I have a Django project that uses SOLR for indexing.
I'm trying to do a substring search using Haystack's SearchQuerySet class.
For example, when a user searches for the term "ear", it should return the entry that has a field with the value: "Search". As you can see, "ear" is a SUBSTRING of "Search". (obviously :))
In other words, in a perfect Django world I would like something like:
SearchQuerySet().all().filter(some_field__contains_substring='ear')
In the haystack documentation for SearchQuerySet (https://django-haystack.readthedocs.org/en/latest/searchqueryset_api.html#field-lookups), it says that only the following FIELD LOOKUP types are supported:
- contains
- exact
- gt, gte, lt, lte
- in
- startswith
- range
I tried using __contains, but it behaves exactly like __exact, which looks up the exact word (the whole word) in a sentence, not a substring of a word.
I am confused, because such a functionality is pretty basic, and I'm not sure if I'm missing something, or there is another way to approach this problem (using Regex or something?).
Thanks
some_field = indexes.NgramField(model_attr='some_field')
. The EdgeNgramField can only do "starts with" and "ends with" type of filtering. – Oceania