Django haystack相关名称搜索

时间:2014-08-01 19:10:58

标签: python django elasticsearch django-haystack

所以我有以下型号:

class Article(models.Model, PublicationMixin):
    publication = models.ForeignKey('Publication', related_name="articles")
    ...

class Publication(models.Model, PublicationMixin):
    is_visible = models.BooleanField(default=False)
    is_approved = models.BooleanField(default=False)
    ....

search_indexes.py我有:

class PublicationIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    id = indexes.CharField(model_attr='id', null=True)

我正在尝试应用进入searchform的过滤器,并仅返回包含文章的出版物。

如何使用haystack及相关名称实现这一目标?我使用弹性搜索作为后端。

1 个答案:

答案 0 :(得分:0)

您是否曾尝试在索引中引用articles字段,如下所示:http://django-haystack.readthedocs.org/en/latest/searchindex_api.html#advanced-data-preparation然后使用SearchQuerySetApi检索所需的值:http://django-haystack.readthedocs.org/en/latest/searchqueryset_api.html

:)