【发布时间】:2016-04-11 17:25:34
【问题描述】:
我有一个仓库模型,它正在获取如下索引
class WarehouseIndex(SearchIndex, Indexable):
"""
SearchIndex Class that stored indexes for Model Warehouse
"""
text = CharField(document=True, use_template=True)
search_auto = NgramField()
....
def get_model(self):
return WareHouse
在我的 shell 中,我正在运行以下 sqs 查询。
>>> sqs = SearchQuerySet().models(WareHouse)
>>> sqs.filter(customers=3).filter(search_auto='pondicherry')
这返回的结果由不具有确切术语 pondicherry 的结果组成,它还为我提供了一些匹配诸如 ich、che、ndi 等术语的结果。
我什至尝试过使用__exact 和Exact,但都返回相同的结果?
编辑:Index mapping,Index Setting
我怎样才能避免这种情况并仅提供术语 pondicherry 的结果?
【问题讨论】:
-
你能展示你的映射吗?
-
@Val : 添加了映射和设置
-
这是因为您的
search_autongram 字段具有相同的索引和搜索分析器,因此您的搜索词pondicherry在搜索时也会被 ngramed。解决此问题的唯一方法是为您的search_auto字段设置不同的search_analyzer,standard将是一个不错的选择。似乎与this issue有关 -
@Val 如何设置 seach_analyzer?
标签: django elasticsearch django-haystack