I run an online shop and wanted to improve the search with some fuzzy logic. To do this I created an index of all words in all product names and created a Levenshtein MySQL stored function in my database.
This is the code I found and used:
[
codejanitor.com...]
So when someone types in "wodget" and this returns no results I do a MySQL Query that returns the most plausible alternative, for example widget:
$sql = "SELECT * FROM table ORDER BY LEVENSHTEIN(table.word, '$keyword') ASC LIMIT 1";
I then do a new search with "widget".
However this is quite slow. Depending on the number of letters it can take 2-4 seconds until I get a result. This is ok for a normal search, however I planned to use it in my Ajax "search suggestion", and for this it is too slow.
Anybody have an idea how I could improve the speed? Is the PHP levenshtein function faster? Maybe I could put all words into an array in PHP and then sort them by levenshtein ratio?