[Django]-Django Combining __unaccent and __search Lookups

5👍

The way to do this is to define custom search configuration in database like:

CREATE TEXT SEARCH CONFIGURATION unaccent ( COPY = french );
ALTER TEXT SEARCH CONFIGURATION unaccent ALTER MAPPING FOR hword, hword_part, word WITH unaccent, simple;

I am not a postgres expert, but this configuration works for me. For more details check tutorial like this: http://www.nomadblue.com/blog/django/from-like-to-full-text-search-part-ii/

and than use this in Django:

from django.contrib.postgres.search import SearchVector, SearchQuery

Game.objects.annotate(unaccent_title=SearchVector('title', config='unaccent')).filter(unaccent_title=SearchQuery('Pokemon', config='unaccent'))

Leave a comment