Py学习  »  Django

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

Santhosh • 3 年前 • 355 次点击  

在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

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

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

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/131920