Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MySQL Full-Text search query with MATCH return strange result order

I need to query a table using the following query:

SELECT cards.name, MATCH(`cards.name`) AGAINST("Swiftfoot Boot") AS relevance
FROM cards
WHERE MATCH(`cards.name`) AGAINST("Swiftfoot Boot")
ORDER BY relevance DESC;

Here is my db-fiddle link with schema and records.

If you run the query you can see that the first result with the highest relevance is "Boot Nipper", but I expect to have "Swiftfoot Boots" (note the ‘s’ at the end). Any idea why this strange order result and how to fix it?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Natural Language Full-Text Searches

Every correct word in the collection and in the query is weighted according to its significance in the collection or query. Thus, a word that is present in many documents has a lower weight, because it has lower semantic value in this particular collection. Conversely, if the word is rare, it receives a higher weight. The weights of the words are combined to compute the relevance of the row. This technique works best with large collections.

DEMO

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading