Ordering FULLTEXT searches on relevance and other fields

Deadly 提交于 2019-12-13 06:40:25

问题


I'm using FULLTEXT natural language search, and I notice that it automatically sorts my results by relevance. However, when I start to add things to ORDER, it seems to no longer sort by relevance. Is there a way to explicitly set the importance of relevance sorting?


回答1:


If you specify the MATCH (...) AGAINST (...) within the column portion of the SELECT query, you can then explicitly order by the 'score' and then any other required parameters.

For example:

SELECT column_a, column_b, MATCH(...) AGAINST (...) AS score
FROM
...
ORDER BY score DESC, column_a DESC

This might seems a bit dubious (as you will have to repeat the same MATCH clause within the WHERE portion of the query to do the actual matching) but it should work perfectly. (If there's a cunning way to alias such things, I'd love to know, but there didn't seem to be in the last version of MySQL I used.)



来源:https://stackoverflow.com/questions/3471733/ordering-fulltext-searches-on-relevance-and-other-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!