赋予某些字段更多的相关性,并在mysql全文搜索中按相关性排序
我的帖子表中有两个字段 - post_title 和 post_content。现在,我使用标准全文搜索来匹配两个字段的一些关键字。我需要给标题字段比内容字段更多的相关性,并且比按相关性对结果进行排序...
要实现此目标,mysql 语法会是什么样子?我用的是mysql 5.1
I have two fields in posts table - post_title and post_content. Now I use standard full text search to match some keywords against both fields. I need to give the title field more relevance than the content field and than order the results by relevance...
What would the mysql syntax look like to achieve this goal? I use mysql 5.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,创建三个 FULLTEXT 索引:
然后,按以下方式构建查询:
这将使标题的相关性比正文高 2 倍。
当您需要允许对内容进行排序(例如按标签(用户不会查看))时,这非常方便,因为它允许您在幕后调整结果。
First, create three FULLTEXT indexes:
Then, build your query in the following manner:
This will give the title 2 times more relevance than the body.
This is quite handy when you need to allow the content to be sorted, for instance, by tags (which are not viewed by the users) because it allows you to tweak the results from behind the scenes.