Diacritics and search

I’ve managed to add Polish fulltext search, thanks to PostgreSQL ability to use hunspell dictionaries for languages that don’t have snowball stemmer algorithm and this Github script:
https://github.com/lemonskyjwt/plpstgrssearch
It does unaccent as well and should be easy to use with other languages as well.
I’d submit it as a PR, but it’s not really production quality, rather a hack. But perhaps some :discourse: dev will be able to make it work, what do you think @sam?
It’s a pups template that’s later included to main app.yml
Edit:

Unfortunately I’ve managed for it to work only on new install, adding it to existing instance does not seem to work, even after issuing rake search:reindex

params:
  LANGFULL: polish
  IDENTIFIER: pl_PL
  
run:
  - exec:
      cmd:
        - apt-get update
        - apt-get install postgresql-server-dev-10
        - wget https://raw.githubusercontent.com/lemonskyjwt/plpstgrssearch/master/pg_hunspell_install
        - chmod +x pg_hunspell_install
        - /bin/sh pg_hunspell_install pl PL $LANGFULL
hooks:
  after_postgres:
     - exec: su postgres -c 'psql template1 -c "create extension if not exists unaccent;"'
     - exec: su postgres -c 'psql $db_name -c "create extension if not exists unaccent;"'
     - exec:
         stdin: |
           CREATE TEXT SEARCH DICTIONARY $LANGFULL_hunspell (TEMPLATE  = ispell, DictFile  = $IDENTIFIER, AffFile   = $IDENTIFIER, StopWords = $LANGFULL);\nCOMMENT ON TEXT SEARCH DICTIONARY $LANGFULL_hunspell\nIS '[USER ADDED] Hunspell dictionary for $LANGFULL';\nCREATE TEXT SEARCH CONFIGURATION public.$LANGFULL (COPY = pg_catalog.english);\nALTER TEXT SEARCH CONFIGURATION $LANGFULL\nALTER MAPPING FOR asciiword, asciihword, hword_asciipart,  word, hword, hword_part\nWITH $LANGFULL_hunspell, unaccent, simple;\nCOMMENT ON TEXT SEARCH CONFIGURATION $LANGFULL\nIS '[USER ADDED] configuration for $LANGFULL';
         cmd: su - postgres -c 'psql discourse'
2 Likes