F.23. Hunspell Dictionaries Modules
These modules provide Hunspell dictionaries for various languages. Upon installation of the module into database using CREATE EXTENSION
command, text search dictionary and configuration objects in the public schema appear.
Table F.14. Modules
Language | Extension name | Dictionary name | Configuration name |
---|---|---|---|
American English | hunspell_en_us | english_hunspell | english_hunspell |
Dutch | hunspell_nl_nl | dutch_hunspell | dutch_hunspell |
French | hunspell_fr | french_hunspell | french_hunspell |
Russian | hunspell_ru_ru | russian_hunspell | russian_hunspell |
F.23.1. Examples
Text search objects will be created after installation of a dictionary module. We can test created configuration:
SELECT * FROM ts_debug('english_hunspell', 'abilities'); alias | description | token | dictionaries | dictionary | lexemes -----------+-----------------+-----------+---------------------------------+------------------+----------- asciiword | Word, all ASCII | abilities | {english_hunspell,english_stem} | english_hunspell | {ability} (1 row)
Or you can create your own text search configuration. For example, with the created dictionaries and with the Snowball
dictionary you can create mixed russian-english configuration:
CREATE TEXT SEARCH CONFIGURATION russian_en ( COPY = simple ); ALTER TEXT SEARCH CONFIGURATION russian_en ALTER MAPPING FOR asciiword, asciihword, hword_asciipart WITH english_hunspell, english_stem; ALTER TEXT SEARCH CONFIGURATION russian_en ALTER MAPPING FOR word, hword, hword_part WITH russian_hunspell, russian_stem;
You can create mixed dictionaries only for languages with different alphabets. If languages have similar alphabets then Postgres Pro can not decide which dictionary should be used.
A text search configuration which is created with a dictionary module is ready to use. For example, in this text you can search some words:
SELECT to_tsvector('english_hunspell', 'The blue whale is the largest animal'); to_tsvector ----------------------------------------- 'animal':7 'blue':2 'large':6 'whale':3 (1 row)
Search query might looks like this:
SELECT to_tsvector('english_hunspell', 'The blue whale is the largest animal') @@ to_tsquery('english_hunspell', 'large & whale'); ?column? ---------- t (1 row)
With this configurations you can search a text using GIN or GIST indexes. For example, there is a table with GIN index:
CREATE TABLE table1 (t varchar); INSERT INTO table1 VALUES ('The blue whale is the largest animal'); CREATE INDEX t_idx ON table1 USING GIN (to_tsvector('english_hunspell', "t"));
For this table you can execute the following query:
SELECT * FROM table1 where to_tsvector('english_hunspell', t) @@ to_tsquery('english_hunspell', 'blue & animal'); t -------------------------------------- The blue whale is the largest animal (1 row)