sql - 使用部分匹配的 POSTGRESQL 在字符串中搜索多个单词
问题描述
我目前在这样的字符串中搜索多个单词:
select name from restaurant where regexp_split_to_array(lower(name), '\s+') @> array['bar', 'food'];
它将字符串拆分为这样的数组: The Food Bar = [the, food, bar]
但它只有在完整的单词都在字符串中时才有效。例如,如果我使用“ba”和“foo”,我想得到相同的结果。我怎样才能实现它?
解决方案
全文搜索可以解决问题:
WHERE to_tsvector('simple', name) @@ to_tsquery('simple', 'the:* | food:* | bar:*')
推荐阅读
- python - 多处理稍后添加参数
- asp.net-mvc - 在 Visual Studio 2017 中编译时键入脚本编译器显示错误
- r-markdown - 使用带有 cbind 或其他方法的 kable 函数来选择变量
- ios - 依赖注入快速查看控制器的建议
- google-earth-engine - 如何估计焦点和
- docker - k8s securityContext.runAsUser vs Dockerfile USER 指令
- wordpress - 如何从评论/评论中获取 woocommerce 用户帐单地址
- javascript - Javascript循环并添加对象
- angular - 将角度 7 更新为 8 后缺少导入路径
- reactjs - react-form-validator-core ref="form" 的目的是什么