【问题标题】:Postgresql create a search configuration with custom stop word listPostgresql 使用自定义停用词列表创建搜索配置
【发布时间】:2017-12-18 18:01:05
【问题描述】:

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

german.stop复制到german_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));

但是当我这样做时

SELECT body, autor
FROM comments
WHERE to_tsvector('german_nostop', body) @@ to_tsquery('wie');

我明白了:

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)

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

【问题讨论】:

    标签: postgresql full-text-indexing


    【解决方案1】:

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

    你应该写:

    to_tsquery('german_nostop', 'wie')
    

    to_tsquery 也删除了停用词,由于它默认使用 german 配置,所以 'wie' 被删除了。

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

    【讨论】:

    • 谢谢!出于某种原因,我不得不重新创建索引,但现在它按预期工作。
    猜你喜欢
    • 2015-10-16
    • 1970-01-01
    • 2014-12-02
    • 2011-02-01
    • 2016-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-23
    相关资源
    最近更新 更多