I'm working on an application based on django 1.8 and search engine django-haystack 2.4.1.
A strange situation because when I search for the words "New York"
- everything is OK.
When there is a strange name in the name of the event for example. "Zo-zo on"
(with dash) search does not show correct results, only pages isolated instances of letters, for example: "zo ..."
I made rebuild_index
.
class EventIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.EdgeNgramField(document=True, use_template=True)
id = indexes.CharField(model_attr='id')
get_absolute_url = indexes.CharField(model_attr='get_absolute_url')
description = indexes.CharField(model_attr='description', null=True)
is_past = indexes.CharField(model_attr='is_past', default='false')
date_start = indexes.DateTimeField(model_attr='date_start')
def get_model(self):
return Booking
def index_queryset(self, using=None):
date_past = now() - timedelta(days=1)
return self.get_model().published.filter(date_start__gt=date_past).filter(id=7353)
def read_queryset(self, using=None):
return self.get_model().all_objects.all()
ok based on your search index schema. You are using EdgeNGramField which tokenize everything that you give to it into token of size 2 and more.
For ex : if you new york it will tokenize and make sure your document matches to terms like ne, new, yo, yor and york. EdgeNGram fields are generally used for autosuggest as it during query and indexing time it tokenize the word into such forms.
You can change your schema to CharField. That way it will zo-zo will transform to zo zo which will match to Zo-zo on in your index.
class EventIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
to do a match like as you intend. It will only support exact word matches that way.
Create a seperate field if you intend to keep EdgeNGram Field.