Using unaccent with SearchVector and SearchQuery in Django

前端 未结 1 1838
陌清茗
陌清茗 2021-01-05 02:00

I have installed UnaccentExtension in Django but I\'m having problems using it with this search:

vector = SearchVector(\'title__unaccent\', \'abstract__unacc         


        
相关标签:
1条回答
  • 2021-01-05 02:07

    You can't use 'unaccent' in 'SearchVector' but you have to define a new "unaccented" config in PostgreSQL.

    1. If you missed, installs the unaccent extension.
    2. 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;
      
    3. 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

    0 讨论(0)
提交回复
热议问题