MySQL - Efficient search with partial word match and relevancy score (FULLTEXT)

后端 未结 2 1417
旧巷少年郎
旧巷少年郎 2020-12-15 18:42

How can I do a MySQL search which will match partial words but also provide accurate relevancy sorting?

SELECT name, MATCH(name) AGAINST (\'math*\' IN BOOLEA         


        
相关标签:
2条回答
  • 2020-12-15 19:07

    I obtained a good solution in this (somewhat) duplicate question a year later:

    MySQL - How to get search results with accurate relevance

    0 讨论(0)
  • 2020-12-15 19:09

    The new InnoDB full-text search feature in MySQL 5.6 helps in this case. I use the following query:

    SELECT MATCH(column) AGAINST('(word1* word2*) ("word1 word1")' IN BOOLEAN MODE) score, id, column 
    FROM table
    having score>0
    ORDER BY score 
    DESC limit 10;
    

    where ( ) groups words into a subexpression. The first group has like word% meaning; the second looks for exact phrase. The score is returned as float.

    0 讨论(0)
提交回复
热议问题