Home >Database >Mysql Tutorial >How to Boost Relevance in MySQL Fulltext Search for Specific Fields?
How to Enhance MySQL Fulltext Search Relevance for Specific Fields
Suppose you have a database with two columns: keywords and content. You've created a fulltext index covering both columns. But, you want to prioritize rows with specific words in the keywords column over those with the same words in the content column.
Solution:
Create three fulltext indexes:
Then, modify your query as follows:
SELECT id, keyword, content, MATCH (keyword) AGAINST ('watermelon') AS rel1, MATCH (content) AGAINST ('watermelon') AS rel2 FROM table WHERE MATCH (keyword,content) AGAINST ('watermelon') ORDER BY (rel1*1.5)+(rel2) DESC
Explanation:
The above is the detailed content of How to Boost Relevance in MySQL Fulltext Search for Specific Fields?. For more information, please follow other related articles on the PHP Chinese website!