Postgres ts_headline 不一致的行为

Mic*_*ael 6 postgresql full-text-search

我刚刚在 postgres ts_headline 函数(用于突出显示全文搜索结果)中偶然发现了一个奇怪的行为。首先,我认为简单的字典不能突出显示,如下例所示(应该有<b>标签):

# SELECT ts_headline('simple', 'This is artificial text', to_tsquery('artificial'));
       ts_headline       
-------------------------
 This is artificial text
(1 row)
Run Code Online (Sandbox Code Playgroud)

但是换个词就好了……

# SELECT ts_headline('simple', 'some Word in', to_tsquery('Word'));
 ts_headline     
---------------------
 some <b>Word</b> in
(1 row)
Run Code Online (Sandbox Code Playgroud)

有人对这种行为有解释吗?

Mic*_*ael 5

我注意到了我的错误。里面的 to_tsquery 函数还需要知道使用哪个字典(也就是使用简单的)。默认情况下,它使用产生以下结果的英语词干:

SELECT to_tsquery('artificial');
 to_tsquery 
------------
 'artifici'
Run Code Online (Sandbox Code Playgroud)

这当然不能在简单字典转换的文本中找到。所以正确的查询应该是:

# SELECT ts_headline('simple', 'This is artificial text', to_tsquery('simple', 'artificial'));
          ts_headline           
--------------------------------
 This is <b>artificial</b> text
(1 row)
Run Code Online (Sandbox Code Playgroud)