在Postgresql中创建过滤同义词库

use*_*658 5 dictionary full-text-search thesaurus postgresql-9.3

我正在使用Postgresql进行全文搜索,我在使用词典(12.6)进行全文搜索的Postgresql文档所描述的方式创建过滤词库时遇到了问题.

据我所知,该文档仅讨论了一个过滤字典,该字典是一个接受令牌作为输入并返回一个设置了TSL_FILTER标志的lexeme的程序,用一个新标记替换原始标记以传递给后续字典.我的问题是:是否有可能创建一个词库,它接受一个短语(1-3个令牌)并返回一个带有TSL_FILTER标志集的词汇,并将其传递给后续词典或同义词库?如果是这样,我做错了什么?

我试图创建一个名为dict_fths的新扩展,它与Postgresql提供的默认词库基本相同,只是一个短语被映射到的每个词位都设置了TSL_FILTER标志.我用以下方式创建了两个名为fths和second_ths的文本搜索词典:

# CREATE EXTENSION dict_fths;
# CREATE TEXT SEARCH DICTIONARY fths (
    template=fths_template, 
    dictionary=english_stem, 
    dictfile=fths_sample
);
# CREATE TEXT SEARCH DICTIONARY second_ths (
    template=thesaurus,
    dictionary=english_stem,
    dictfile=second_ths
);
# CREATE TEXT SEARCH CONFIGURATION test ( COPY=pg_catalog.english );
# ALTER TEXT SEARCH CONFIGURATION test 
  ALTER MAPPING FOR asciihword, asciiword, hword, hword_asciipart, hword_part, word
  WITH fths, second_ths, english_stem;
Run Code Online (Sandbox Code Playgroud)

当映射在单个标记和单个lexeme之间时,dict_fths行为正确.

fths_sample.ths条目:

ski : sport
Run Code Online (Sandbox Code Playgroud)

second_ths.ths条目:

sport competition : *sporting-event
Run Code Online (Sandbox Code Playgroud)

输出(正确,正确):

# select to_tsvector('test', 'ski');
    to_tsvector
  ---------------
   'sport':1
(1 row)

# select to_tsvector('test', 'ski competition');
    to_tsvector
  ---------------
   'sporting-event':1
(1 row)
Run Code Online (Sandbox Code Playgroud)

但是当我编辑这些文件以包含短语时,我不再获得我想要的输出:

fths_sample.ths条目:

ski : sport
ski jumping : sport
Run Code Online (Sandbox Code Playgroud)

输出(正确,正确,不正确,不正确):

# select to_tsvector('test','ski');
    to_tsvector
  ---------------
   'sport':1
(1 row)

# select to_tsvector('test','ski jumping');
    to_tsvector
  ---------------
   'sport':1
(1 row)

# select to_tsvector('test' 'ski competition');
    to_tsvector
  ---------------
   'sport':1 'competit':2
(1 row)

# select to_tsvector('test', 'ski jumping competition');
    to_tsvector
  ---------------
   'sport':1 'competit':2
(1 row)
Run Code Online (Sandbox Code Playgroud)

即使我编辑了fths_sample.ths文件,输出仍然不正确:

fths_sample.ths包含:

ski jumping : sport
Run Code Online (Sandbox Code Playgroud)

这是输出(正确,不正确):

# select to_tsvector('test', 'ski jumping');
    to_tsvector
  ---------------
   'sport':1
(1 row)

# select to_tsvector('test', 'ski jumping competition');
    to_tsvector
  ---------------
   'sport':1 'competit':2
(1 row)
Run Code Online (Sandbox Code Playgroud)

因此,当1)它具有多于1个令牌时,似乎同义词未能通过词位2)它是较长短语的一部分.