【问题标题】:Prevent stemming of words starting with # in PostgreSQL full text search在 PostgreSQL 全文搜索中防止以 # 开头的词的词干
【发布时间】:2017-06-12 09:31:31
【问题描述】:

基本上,我希望能够为这样的查询获得完全匹配(包括标签):

=#SELECT to_tsvector('english', '#adoption');
 to_tsvector
-------------
 'adopt':1

相反,我想查看以# 开头的单词:

=#SELECT to_tsvector('english', '#adoption');
 to_tsvector
-------------
 '#adoption':1

这可以通过 psql 全文搜索实现吗?

【问题讨论】:

    标签: postgresql full-text-search stemming


    【解决方案1】:

    在搜索或索引之前,您可以将每个 # 字符替换为您在文本中不使用但会改变解析器解释的其他字符:

    test=> SELECT alias, lexemes FROM ts_debug('english', '#adoption');
    ┌───────────┬─────────┐
    │   alias   │ lexemes │
    ├───────────┼─────────┤
    │ blank     │         │
    │ asciiword │ {adopt} │
    └───────────┴─────────┘
    (2 rows)
    
    test=> SELECT alias, lexemes FROM ts_debug('english', '/adoption');
    ┌───────┬─────────────┐
    │ alias │   lexemes   │
    ├───────┼─────────────┤
    │ file  │ {/adoption} │
    └───────┴─────────────┘
    (1 row)
    

    【讨论】:

    • 天才——谢谢!虽然我希望 PSQL 能够扩展他们的解析器来识别主题标签。它们到处都在使用……
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-24
    • 2018-12-07
    • 1970-01-01
    • 2014-05-10
    • 2017-01-20
    • 2015-10-12
    • 1970-01-01
    相关资源
    最近更新 更多