Postgresql 使用自定义停用词列表创建搜索配置

Ale*_*lex 5 postgresql full-text-indexing

对于特定的全文搜索,我需要修改标准停用词文件并排除一些单词。到目前为止我做了什么:

复制german.stopgerman_modified.stop,然后从 中删除文字german_modified.stop。然后:

CREATE TEXT SEARCH DICTIONARY public.german_nostop (
   TEMPLATE = pg_catalog.simple,
   STOPWORDS = german_modified
);

CREATE TEXT SEARCH CONFIGURATION public.german_nostop (
   COPY = pg_catalog.german
);

ALTER TEXT SEARCH CONFIGURATION public.german_nostop
   ALTER MAPPING
      FOR asciiword, asciihword, hword_asciipart, hword, hword_part, word
      WITH german_nostop;

CREATE INDEX body_idx ON comments
   USING gin (to_tsvector('german_nostop', body));
Run Code Online (Sandbox Code Playgroud)

但当我这样做时

SELECT body, autor
FROM comments
WHERE to_tsvector('german_nostop', body) @@ to_tsquery('wie');
Run Code Online (Sandbox Code Playgroud)

我得到:

NOTICE:  text-search query contains only stop words or doesn't contain lexemes, ignored
NOTICE:  text-search query contains only stop words or doesn't contain lexemes, ignored
NOTICE:  text-search query contains only stop words or doesn't contain lexemes, ignored
 body | autor
------+-------
(0 rows)
Run Code Online (Sandbox Code Playgroud)

'wie'是我从修改后的停用词列表中删除的单词。由于某种原因 PostgreSQL 没有使用新的非索引字表。我真的不想修改原始文件,因为我确实想将原始文件用于其他搜索。

Lau*_*lbe 3

您忘记将文本搜索配置添加到to_tsquery通话中。

你应该写:

to_tsquery('german_nostop', 'wie')
Run Code Online (Sandbox Code Playgroud)

to_tsquery还删除了停用词,并且由于它german默认使用配置,因此'wie'被删除。

如果您希望新的文本搜索配置成为默认设置,则可以设置default_text_search_config为。german_nostop