I have a search index with elasticsearch as backend:
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:
Cable
Magnet
Network
Internet
Switch
When I execute search for netw
, it returned Magnet
& Internet
also along with Network
. Using some other test cases I think haystack is searching for substring also, like net in netw
as you see in above example.
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
Customize your elasticsearch backend settings with django-hesab
The default settings of django-hesab will return the exact search result.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.