I have installed UnaccentExtension in Django but I'm having problems using it with this search:
vector = SearchVector('title__unaccent', 'abstract__unaccent')
query = SearchQuery(word) | SearchQuery(word2)
files = Doc.objects.annotate(rank=SearchRank(vector, query)).order_by('-rank')
This is the error:
Cannot resolve keyword 'unaccent' into field. Join on 'title' not permitted.
Whit a simplest search it works fine:
Doc.objects.filter(title__unaccent=word)
So, what am I doing wrong?
You can't use 'unaccent' in 'SearchVector' but you have to define a new "unaccented" config in PostgreSQL.
Create your unaccented dictionary in PostgrSQL or using an empty migrations with this SQL:
CREATE TEXT SEARCH CONFIGURATION french_unaccent( COPY = french );
ALTER TEXT SEARCH CONFIGURATION french_unaccent
ALTER MAPPING FOR hword, hword_part, word
WITH unaccent, french_stem;
Use this configuration in your Django query :
SearchVector('title','abstract', config='french_unaccent')
SearchQuery(word, config='french_unaccent')
You can find more info about this type of configuration in the official PostgreSQL documentation on in various articles
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