Postgresql 中文操作指南

F.13. dict_int — example full-text search dictionary for integers #

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.

此模块被认为是“受信任的”,也就是说,它可以由在当前数据库上具有 CREATE 权限的非超级用户安装。

This module is considered “trusted”, that is, it can be installed by non-superusers who have CREATE privilege on the current database.

F.13.1. Configuration #

该词典接受三个选项:

The dictionary accepts three options:

F.13.2. Usage #

安装 dict_int 扩展将创建一个基于它的文本搜索模板 intdict_template 和词典 intdict,具有默认参数。您可以更改参数,例如

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}

但实际使用会将其包含在一个文本搜索配置中,如 Chapter 12 中所述。它可能看起来像这样:

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;