问题
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