[英]Django-Haystack(elasticsearch) Autocomplete giving results for substring in search term
I have a search index with elasticsearch as backend: 我有一个将Elasticsearch作为后端的搜索索引:
class MySearchIndex(indexes.SearchIndex, indexes.Indexable):
...
name = indexes.CharField(model_attr='name')
name_auto = indexes.NgramField(model_attr='name')
...
Suppose I have following values in elasticsearch: 假设我在elasticsearch中具有以下值:
Cable
Magnet
Network
Internet
Switch
When I execute search for netw
, it returned Magnet
& Internet
also along with Network
. 当我执行搜索netw
,它还返回了Magnet
& Internet
和Network
。 Using some other test cases I think haystack is searching for substring also, like net in netw
as you see in above example. 使用一些其他的测试案例,我认为草垛中寻找子也一样, 净 netw
正如你看到的上面的例子。
Here is the code: 这是代码:
sqs = sqs.filter(category='cat_name').using(using)
queried = sqs.autocomplete(name_auto=q)
Also tried with: 还尝试了:
queried = sqs.autocomplete(name_auto__contains=q)
How can I resolve this and make it working to return only those results that contains exact search term ? 如何解决此问题并使它仅返回那些包含精确搜索词的结果?
Using django-haystack==2.4.1 Django==1.9.1 elasticsearch==1.9.0 使用django-haystack == 2.4.1 Django == 1.9.1 elasticsearch == 1.9.0
Customize your elasticsearch backend settings with django-hesab 使用django-hesab自定义您的Elasticsearch后端设置
The default settings of django-hesab will return the exact search result. django-hesab的默认设置将返回准确的搜索结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.