I am having a very strange behavior with EdgeNgramField in Haystack with Elasticsearch.
Basically. If I have a BooleanField in my index, all Ngram and EdgeNgram fields work just like regular CharField.. anyone knows about this?
Here is my index (no boolean field, ngram search works just fine):
class UserIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True)
name = indexes.EdgeNgramField(model_attr='first_name')
def get_model(self):
return User
def index_queryset(self, using=None):
# Filter the user - return only the one with a UserProfile
return self.get_model().objects.all().annotate(pcount=models.Count('userprofile')).filter(pcount__gt=0)
Here is the result of a search (looks good):
>>> for item in sqs.autocomplete(name='sebastien'):
... print item.name
...
Sebastien
Sebastien
sebastien
Sebastian
Sebastian
Sebastian
Juan Sebastián
sebtest
sebtest2
sebtest
Seetesh
Serena
Selene
Severine
Severine
Sergio
Then I add a BooleanField:
class UserIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True)
name = indexes.EdgeNgramField(model_attr='first_name')
is_active = indexes.BooleanField(model_attr='is_active')
def get_model(self):
return User
def index_queryset(self, using=None):
# Filter the user - return only the one with a UserProfile
return self.get_model().objects.all().annotate(pcount=models.Count('userprofile')).filter(pcount__gt=0)
And for some unknown reason, the EdgeNgramField is now acting like a CharField (the re-indexing is performed without any error)
>>> for item in sqs.autocomplete(name='sebastien'):
... print item.name
...
Sebastien
Sebastien
sebastien