I am implementing a search engine in my django project using django haystack. The problem is that some of the fields in my models have some French accents, and I would like to find records that contain a query with and without accents.
I think the best idea is to create SearchIndex with fields with accents and with the same field without accents.
Any idea or hint on this?
Here is the code
Imagine the following models:
Cars(models.Model): name = models.CharField()
and the following Haystack index:
Cars(indexes.SearchIndex): name = indexes.CharField(model_attr='name') cleaned_name = indexes.CharField(model_attr='name') def prepare_cleaned_name(self, object): return strip_accents(object.name)
now, in my index template, I put both fields:
{{ object.cleaned_name }} {{ object.name }}
So this is some kind of pseudo code, I donβt know if it works, but if you have any ideas on this, let me know!
source share