Postgresql 中带有分数/排名的全文查询
我是 Postgres 新手,我不知道如何将此 MySQL 查询转换为 Postgres:
SELECT pictures.id, MATCH (title, cached_tag_list) AGAINST ('phrase') AS score FROM pictures WHERE MATCH (title, cached_tag_list) AGAINST ('phrase') ORDER BY score DESC;
Im new to Postgres and I dont know how to translate this MySQL query to postgres:
SELECT pictures.id, MATCH (title, cached_tag_list) AGAINST ('phrase') AS score FROM pictures WHERE MATCH (title, cached_tag_list) AGAINST ('phrase') ORDER BY score DESC;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Postgres 全文搜索与 MySQL 全文搜索略有不同。它有更多的选项,但要按照您喜欢的方式工作可能会有点困难。
本文档告诉您如何对搜索结果进行排名,但我强烈建议您阅读手册中的整个全文部分,以了解可以用它做什么:http://www.postgresql.org/docs/current/interactive/textsearch-controls.html#TEXTSEARCH-RANKING
基本上,您的查询的等价物是这样的:
如您所见,这使用
textsearch
,这是您必须自己定义的内容。对于简短版本,请阅读:http://www.postgresql.org/ docs/current/interactive/textsearch-tables.html查询本质上非常简单:
但我强烈建议也添加索引:
The Postgres fulltext search is a little different from the MySQL fulltext search. It has a lot more options but can be a bit more difficult to get working the way you like it.
This document tells you how to rank your search results, but I strongly recommend you read the entire fulltext section from the manual to get an idea about what you can do with it: http://www.postgresql.org/docs/current/interactive/textsearch-controls.html#TEXTSEARCH-RANKING
Basically, the equivalent of your query would be this:
As you can see, this uses
textsearch
which is something you will have to define yourself. For the short version, read: http://www.postgresql.org/docs/current/interactive/textsearch-tables.htmlThe query is essentially very simple:
But I would strongly recommend adding indexes aswell: