MySQL order by relevance

后端 未结 4 1444
感动是毒
感动是毒 2021-01-02 08:40

I have a search form which searches a site content table to pull back appropriate results.

I want to search the title and content fields and pull back results in ord

4条回答
  •  执笔经年
    2021-01-02 09:03

    I managed to get pretty spot on with this:

    SELECT *, 
    ( (1.3 * (MATCH(strTitle) AGAINST ('+john+smith' IN BOOLEAN MODE))) + (0.6 * (MATCH(txtContent) AGAINST ('+john+smith' IN BOOLEAN MODE)))) AS relevance 
    FROM content 
    WHERE (MATCH(strTitle,txtContent) AGAINST ('+john+smith' IN BOOLEAN MODE) ) 
    ORDER BY relevance DESC
    

提交回复
热议问题