I need to search substring values in a model field. I have an Index and a SearchQuerySet.
This is the Elasticsearch configuration.
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'haystack',
},
}
My Index.
class ElementIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
#model fields
title_element = indexes.EdgeNgramField(model_attr='title')
clean_content = indexes.EdgeNgramField(model_attr='clean_content')
def get_model(self):
return Element
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return Element.objects.filter(updatetime__lte=datetime.datetime.now())
My custom search.
SearchQuerySet().filter(title_element=clean_value)
In my database I have a value "HolaMundoTest", and if I try to search by 'Hola' or 'HolaM' I find a result, but if I try 'Mundo' or 'mundo' or 'laMun' there are no matches.
What Is wrong? I don't understand.
source http://django-haystack.readthedocs.org/en/v2.1.0/autocomplete.html
I am using:
- -django 1.5.1
- -django-haystack==2.1.0
- -elasticsearch-0.90.5
- -pyelasticsearch==0.6
Thanks for your answers-