PostgreSQL имеет собственный полнотекстовый поиск, но в нем нет стемминга для русского языка.
Словари для русского можно достать здесь:
http://ftp5.gwdg.de/pub/openoffice/contrib/dictionaries/ru_RU-pack.zip
Внутри будет архив ru_RU.zip, из которого необходимо извлечь файлы ru_RU.dic и ru_RU.aff.
Словари в кодировке koi8, поэтому их следует преобразовать в UTF-8:
Теперь в консоли постгреса создадим конфигурацию для полнотекстового поиска:
Далее, если нужно чтобы эта конфигурация работала по умолчанию в postgres.conf следует написать
Проверим словари:
Словари для русского можно достать здесь:
http://ftp5.gwdg.de/pub/openoffice/contrib/dictionaries/ru_RU-pack.zip
Внутри будет архив ru_RU.zip, из которого необходимо извлечь файлы ru_RU.dic и ru_RU.aff.
Словари в кодировке koi8, поэтому их следует преобразовать в UTF-8:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iconv -f koi8-r -t utf-8 < ru_RU.aff > /usr/share/postgresql/9.0/tsearch_data/russian.affix | |
iconv -f koi8-r -t utf-8 < ru_RU.dic > /usr/share/postgresql/9.0/tsearch_data/russian.dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
su - postgres | |
psql | |
CREATE TEXT SEARCH DICTIONARY russian_ispell ( | |
TEMPLATE = ispell, | |
DictFile = russian, | |
AffFile = russian, | |
StopWords = russian | |
); | |
CREATE TEXT SEARCH CONFIGURATION ru (COPY=russian); | |
ALTER TEXT SEARCH CONFIGURATION ru ALTER MAPPING FOR hword, hword_part, word WITH russian_ispell, russian_stem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default_text_search_config = 'ru' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# select to_tsvector('ru', 'мама мыла раму'); | |
to_tsvector | |
------------------------------------- | |
'мама':1 'мыло':2 'мыть':2 'рама':3 | |
(1 запись) |
Здравствуйте!
ОтветитьУдалитьСкажите пожалуйста, что если у нас контент может быть и на английском и на русском? Можно ли подключать словари сразу двух языков?
ALTER TEXT SEARCH CONFIGURATION ru ALTER MAPPING FOR hword, hword_part, word WITH russian_ispell, russian_stem, english_ispell, english_stem;
УдалитьЭтот комментарий был удален автором.
ОтветитьУдалитьALTER TEXT SEARCH CONFIGURATION ru ALTER MAPPING FOR hword, hword_part, word WITH russian_ispell, russian_stem
ОтветитьУдалитьALTER TEXT SEARCH CONFIGURATION ru ALTER MAPPING FOR asciiword, asciihword, hword_asciipart WITH english_ispell, english_stem;