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:
Thanks for your answers-
As you are using EdgeNgramField that is the expected behavior as it tokenizes on whitespace and matches texts starting with the characters in the query.
In order to get results for the query "laMun" or "mundo" you should use NgramField instead of EdgeNgramField.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With