Haystack SearchQuerySet returns None 带内容过滤器
Haystack SearchQuerySet returns None with content filter
我有以下 SearchIndex:
class ProductIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True)
display_name = indexes.CharField(model_attr='display_name')
link = indexes.CharField(model_attr='link')
def get_model(self):
return Product
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().objects.\
filter(last_updated__lte=datetime.datetime.now())
它适用于以下查询:
>>>> SearchQuerySet().filter(display_name='Levis jeans')
[<SearchResult ... >, <SearchResult ... >, ...]
但是当我使用任何内容过滤器时,它 returns 空列表:
>>>> SearchQuerySet().filter(content='Levis jeans')
[]
怎么了?
也没有带有 text
字段的 solr 文档。
解决方案:为 text
字段设置 use_template=True
。 Haystack 使用 django-templates 为搜索引擎呈现文档。
我有以下 SearchIndex:
class ProductIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True)
display_name = indexes.CharField(model_attr='display_name')
link = indexes.CharField(model_attr='link')
def get_model(self):
return Product
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().objects.\
filter(last_updated__lte=datetime.datetime.now())
它适用于以下查询:
>>>> SearchQuerySet().filter(display_name='Levis jeans')
[<SearchResult ... >, <SearchResult ... >, ...]
但是当我使用任何内容过滤器时,它 returns 空列表:
>>>> SearchQuerySet().filter(content='Levis jeans')
[]
怎么了?
也没有带有 text
字段的 solr 文档。
解决方案:为 text
字段设置 use_template=True
。 Haystack 使用 django-templates 为搜索引擎呈现文档。