我们正在尝试使用文本查询清除特定列上的重复项。
这是一个示例查询:
SELECT
distinct on (title) title",
ts_rank_cd(to_tsvector(title), query, 1) AS rank
FROM
products,
to_tsquery('english',''english','Ribeye | Starter | Cheese | Assortment'') query
WHERE
query @@ to_tsvector(title) AND
book_id = '37' as result
ORDER BY
rank DESC limit 10 offset 0
出于某种原因,我们在使用文本搜索时仍然偶尔会收到重复的标题。
结果是:
"Ribeye Starter Cheese Assortment"
"Filet Mignon Starter Cheese Assortment"
"Ambassadors Assortment"
"Ambassadors Assortment"
"Strip Steak Starter Cheese Assortment"
"After Dinner Cheese Assortment"
"Ambassadors Assortment"
"Chairmans Assortment"
在没有 TSVectors 的情况下使用 distinct 可以正常工作,但引入文本搜索会忽略 PostGres Distinct 关键字。
有任何想法吗 ?