[Django]-Django-Haystack not returning exact query

2๐Ÿ‘

โœ…

I just found the solution to this problem. Please listen up if you want to avoid loosing any of you reputations by placing a bounty on the same problem.

Basically I had to replace my original destination field in my search_indexes.py document to the following line:

From this: destination = indexes.EdgeNgramField(model_attr="destination")

To this: destination = indexes.CharField(model_attr="destination")

๐Ÿ‘คlocq

0๐Ÿ‘

Your issue is in your use of dict.get

self.q_from_data = data.get('q', [''])[0]

For example

data.get('q')  # This will return the string "Mexico"
data.get('q')[0]  # This will return the first letter "M"

The line should be

self.q_from_data = data.get('q', '')

Leave a comment