【问题标题】:PostgreSQL full text search abbreviationsPostgreSQL全文搜索缩写
【发布时间】:2016-06-18 18:10:06
【问题描述】:

我使用“德语”创建了 Postgresql 全文搜索。如何配置,当我搜索“Bezirk”时,包含“Bez”的行。也有比赛? (反之亦然)

【问题讨论】:

  • 如果要与文本搜索匹配,则需要创建自定义synonym dictionary
  • @pozs 似乎您的建议是可行的方法。当您将其表述为答案时,我会接受。

标签: postgresql full-text-search pattern-matching trigram


【解决方案1】:

尝试在搜索中使用通配符。

例如:

tableName.column LIKE 'Bez%'

% 将搜索Bez 之后的任何字母或数字

【讨论】:

  • 重点是“Bez”。存储在数据库中,我查询“Bezirk”,因此查询与您假设和建议的相反。
  • 对问题的描述非常模糊,因此很难准确地确定您要做什么。抱歉,我无法为您提供帮助。祝你的问题好运。
【解决方案2】:

描述非常模糊,无法理解您想要实现的目标,但看起来您在查找缩写时需要简单的pattern matching 搜索(因此需要像在全文搜索中那样进行词干提取)。为此,我会使用pg_trgm

WITH t(word) AS ( VALUES
  ('Bez'),
  ('Bezi'),
  ('Bezir')
)
SELECT word, similarity(word, 'Bezirk') AS similarity
FROM t
WHERE word % 'Bezirk'
ORDER BY similarity DESC;

结果:

 word  | similarity 
-------+------------
 Bezir |      0.625
 Bezi  |        0.5
 Bez   |      0.375
(3 rows)

【讨论】:

    【解决方案3】:

    @pozs 是对的。您需要使用synonym dictionary

    1 - 在目录 $SHAREDIR/tsearch_data 中创建具有以下内容的文件 German.syn:

    Bez Bezirk
    

    2 - 执行查询:

    CREATE TEXT SEARCH DICTIONARY german_syn (
        template = synonym,
        synonyms = german);
    CREATE TEXT SEARCH CONFIGURATION german_syn(COPY='simple');
    ALTER TEXT SEARCH CONFIGURATION german_syn
        ALTER MAPPING FOR asciiword, asciihword, hword_asciipart,
            word, hword, hword_part
        WITH german_syn, german_stem;
    

    现在你可以测试它了。执行查询:

    test=# SELECT to_tsvector('german_syn', 'Bezirk') @@ to_tsquery('german_syn', 'Bezirk & Bez');
     ?column? 
    ----------
     t
    (1 row)
    
    test=# SELECT to_tsvector('german_syn', 'Bez Bez.') @@ to_tsquery('german_syn', 'Bezirk');
     ?column? 
    ----------
     t
    (1 row)
    

    其他链接:

    1. PostgreSQL: A Full Text Search engine(已过期)

    【讨论】:

    • 嗨@Artur,如何使用COPY,是完整的语言副本吗? germansimple 是语言.... PS:链接无效
    • @PeterKrauss,您能否展示您的 COPY 查询示例? PS:谢谢,我把链接标记为过期了。
    • 您好,感谢您的回复!见stackoverflow.com/q/60082663/287948
    猜你喜欢
    • 2011-11-15
    • 1970-01-01
    • 1970-01-01
    • 2013-03-09
    • 2020-03-07
    • 2014-01-05
    • 1970-01-01
    • 1970-01-01
    • 2011-04-14
    相关资源
    最近更新 更多