【问题标题】:Search for multiple words in a string with partial matching POSTGRESQL使用部分匹配的 POSTGRESQL 在字符串中搜索多个单词
【发布时间】:2020-11-04 19:36:08
【问题描述】:

我目前在这样的字符串中搜索多个单词:

select name from restaurant where regexp_split_to_array(lower(name), '\s+') @> array['bar', 'food'];

将字符串拆分为这样的数组: The Food Bar = [the, food, bar]

但它只有在完整的单词都在字符串中时才有效。例如,如果我使用“ba”和“foo”,我想得到相同的结果。我怎样才能实现它?

【问题讨论】:

    标签: sql postgresql


    【解决方案1】:

    全文搜索可以解决问题:

    WHERE to_tsvector('simple', name) @@ to_tsquery('simple', 'the:* | food:* | bar:*')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-01
      • 2015-07-25
      • 2017-02-27
      • 2014-01-17
      • 1970-01-01
      • 1970-01-01
      • 2020-11-20
      相关资源
      最近更新 更多