代码之家  ›  专栏  ›  技术社区  ›  Santhosh

Django algolia搜索:如何创建多个模型的搜索

  •  0
  • Santhosh  · 技术社区  · 5 年前

    在Django,我有4种不同的型号

    class Baby(model.Model):
        name = ... #(babys name)
        description = ...
        .... other fields not common
    
    class BabyStore(model.Model):
        name = ...  #(name of the shop)
        description = ...
        .... other fields not common
    
    class BabySitter(model.Model):
        name = ... #(babysitter name)
        description = ....
        .... other fields not common
    
    class BabyDoctor(model.Model):
        name = ... #(babydoctors name)
        description = ...
        .... other fields not common
    

    根据 https://github.com/algolia/algoliasearch-django 我们必须登记每种型号

    import algoliasearch_django as algoliasearch
    
    from .models import YourModel
    
    algoliasearch.register(YourModel)
    

    这将为每个模型创建单独的索引。

    在我的例子中,我希望有一个搜索UI,将所有这些都放在一起,并使用模型作为方面。

    如:

    enter image description here

    那么,如何使用多个索引并创建单个搜索呢

    我知道在每个索引中,我们都可以有方面。但在这里,我想把每个索引本身作为一个方面来使用

    0 回复  |  直到 5 年前