Django Haystack : search for a term with and without accents

前端 未结 3 1684
日久生厌
日久生厌 2021-01-01 04:32

I\'m implementing a search system onto my django project, using django haystack. The problem is that some fields in my models have some french accents, and I would like to f

3条回答
  •  执念已碎
    2021-01-01 05:00

    I find a way to index both value from the same field in my Model.

    First, write a method in your model which returns the ascii value of the fields:

    class Car(models.Model):
        name = model.CharField()
    
        def ascii_name(self):
            return strip_accents(self.name)
    

    So that in your template used to generate the index, you could do this:

    {{ object.name }}
    {{ object.ascii_name }}
    

    Then, you just have to rebuild your indexes !

提交回复
热议问题