django haystack how do I find substrings in words?

岁酱吖の 提交于 2019-12-10 10:18:17

问题


In my field the content is "example". I want to find not only the exact word "example", I also want to find "examp". How can I do that? Are there any options. Can't find anything.


回答1:


If you just want to search for objects starting with some string, then just look at Haystack SearchQuerySet API documentation. It resembles the Django QuerySet API, so it is possible to write:

SearchQuerySet().filter(content__startswith='examp')
SearchQuerySet().filter(content__contains='examp')

or whatever you want.

But there is also something deeper in this question. I don't think you really need to. Because of the way search engines works - when someone searches for e.q. 'monitoring' it gets stemmed (it is process of getting something similar to root of the word - so we will have f.e. 'monitor' from 'monitoring') and that will be searched for in fact. Also everything in search indexes gets stemmed, so searching for monitor will return results containing f.e. 'monitors', 'monitoring', 'monitorize' etc.



来源:https://stackoverflow.com/questions/11987177/django-haystack-how-do-i-find-substrings-in-words

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!