I help a friend build vocabulary grades for the project he is working on. Part of the project is to create a search function. The database is in MySQL, backend in php.
Now starting our simple request was a piece of cake:
SELECT *, ( (CASE WHEN word LIKE '%$query%' THEN 1 ELSE 0 END) + (CASE WHEN defin LIKE '%$query%' THEN 1 ELSE 0 END) ) AS relev FROM dictionary WHERE word LIKE '%$q%' OR defin LIKE '%$q%' ORDER BY relev DESC;
It brought good results; for example, the input of "fire" gave us fire, firemen, firemen, set fire, etc. However, we also need a room for error: we want the error “prnk” to give us prank, prink, as well as pink, or the word “mule”, to also suggest the word “moth”.
It is absolutely amazing that we could not find any information about this. The relevance system is completely superficial, because we do not need actual significance (just a general pointer), but we need something (and therefore we went to the LIKE instruction, and not to the MATCH ... AGAINST instruction, where we did not find anywhere to sort by relevance.)
A database consists of only three things: id, word, defin. Simple as it required complexity (or simplicity).
Thanks to everyone in advance.
Zirak source share