问题描述
我想从字符串创建食物/饮料列表。
让我说我有一个表ingredients
,其中列name
的值是:
name
----
Lemon
Lemon Juice
Triple Sec
Vodka
我有句子Please by lemon juice,vodka and bread from the store
然后我运行查询
select it.name from ingredients it where
to_tsvector('Please by lemon juice,vodka and bread from the store') @@ phraseto_tsquery(it.name);
然后它将返回Lemon
,Lemon juice
和vodka
。它只需要返回lemon juice
和vodka
。
有没有办法做到这一点?
对于Postgresql中的所有全文搜索功能,我真的是一个新手,对于我当前的示例,使用它似乎无关紧要,但是它将变得更加复杂,我将在这一领域继续前进。
我以为我可以得到比赛的位置,那么如果我找到具有相同位置比赛的短语,我会得到最长的短语,但还是不知道该怎么做!
因此,如果您有任何解决方案,那就太好了。
我考虑过使用or |
排序的name desc
语句构建字符串,因此Lemon Juice
将首先出现。所以我这样做了:
with it as (select name from ingredients order by lower(name) desc),parser as (select string_agg(replace(name,' ',' <-> '),' | ') as name from it)
select name::tsquery from parser;
但这只会给我一个匹配,而不会给我匹配的匹配,因此还不够。
谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)