F.14. dict_int
Модуль dict_int представляет собой пример дополнительного шаблона словаря для полнотекстового поиска. Этот словарь был создан для управляемой индексации целых чисел (со знаком и без); он позволяет индексировать такие числа и при этом избежать чрезмерного разрастания списка уникальных слов, что значительно увеличивает скорость поиска.
F.14.1. Конфигурирование
Этот словарь принимает два параметра:
Параметр
maxlenзадаёт максимальное число цифр, из которого может состоять целое число. Значение по умолчанию — 6.Параметр
rejectlongопределяет, должны ли чрезмерно длинные числа усекаться или игнорироваться. Еслиrejectlongимеет значениеfalse(по умолчанию), этот словарь возвращает первыеmaxlenцифр целого числа. Еслиrejectlongравенtrue, чрезмерное длинное целое воспринимается как стоп-слово, и в результате не индексируется. Заметьте, это означает, что такое целое нельзя будет найти.
F.14.2. Использование
При установке расширения dict_int в базе создаётся шаблон текстового поиска intdict_template и словарь intdict на его базе, с параметрами по умолчанию. Вы можете изменить параметры словаря, например так:
mydb# ALTER TEXT SEARCH DICTIONARY intdict (MAXLEN = 4, REJECTLONG = true); ALTER TEXT SEARCH DICTIONARY
или создать новые словари на базе этого шаблона.
Протестировать этот словарь можно так:
mydb# select ts_lexize('intdict', '12345678');
ts_lexize
-----------
{123456}Но для практического применения его нужно включить в конфигурацию текстового поиска, как описано в Главе 12. Это может выглядеть примерно так:
ALTER TEXT SEARCH CONFIGURATION english
ALTER MAPPING FOR int, uint WITH intdict;F.14. dict_int
dict_int is an example of an add-on dictionary template for full-text search. The motivation for this example dictionary is to control the indexing of integers (signed and unsigned), allowing such numbers to be indexed while preventing excessive growth in the number of unique words, which greatly affects the performance of searching.
F.14.1. Configuration
The dictionary accepts two options:
The
maxlenparameter specifies the maximum number of digits allowed in an integer word. The default value is 6.The
rejectlongparameter specifies whether an overlength integer should be truncated or ignored. Ifrejectlongisfalse(the default), the dictionary returns the firstmaxlendigits of the integer. Ifrejectlongistrue, the dictionary treats an overlength integer as a stop word, so that it will not be indexed. Note that this also means that such an integer cannot be searched for.
F.14.2. Usage
Installing the dict_int extension creates a text search template intdict_template and a dictionary intdict based on it, with the default parameters. You can alter the parameters, for example
mydb# ALTER TEXT SEARCH DICTIONARY intdict (MAXLEN = 4, REJECTLONG = true); ALTER TEXT SEARCH DICTIONARY
or create new dictionaries based on the template.
To test the dictionary, you can try
mydb# select ts_lexize('intdict', '12345678');
ts_lexize
-----------
{123456}
but real-world usage will involve including it in a text search configuration as described in Chapter 12. That might look like this:
ALTER TEXT SEARCH CONFIGURATION english
ALTER MAPPING FOR int, uint WITH intdict;