Yashwanth Babu
Yashwanth Babu

Reputation: 939

django haystack partial search for IntegerField

I am using Django-haystack 2.4.1. I am trying to do a partial search for IntegerField. I have a item_id filed in my searchindex. For example I want to search 23456, 2345, 234, 23, 2 all of these. This is not working with the query

SearchQuerySet().filter(item_id__icontains=234).models(MyModel)

Can anyone help me with this please.

Upvotes: 0

Views: 153

Answers (1)

Andrey Shipilov
Andrey Shipilov

Reputation: 2014

In your search_indexes.py the field that is your document field, should be EdgeNgramField.

class ModelIndex(indexes.SearchIndex, indexes.Indexable):
    indexed_text = indexes.EdgeNgramField(document=True, use_template=True)

And obviously you should update the index every time before making queries.

Upvotes: 0

Related Questions