user1603200
user1603200

Reputation: 65

django haystack how do I find substrings in words?

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.

Upvotes: 3

Views: 1567

Answers (1)

jasisz
jasisz

Reputation: 1298

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.

Upvotes: 4

Related Questions