1

Is it possible to use levenshtein to compare portion of a column with search term? For example if a user searches "waiferer" - it will find "Schwinn Men's 700c Wayfarer Bike". I also would like to sort from highest match to lowest. I'm using leveshtein code from here. Here's my php code

$result = mysql_query('SELECT name FROM products WHERE LEVENSHTEIN("'.$word.'", name) <= 10')
Dmitry
  • 4,143
  • 10
  • 46
  • 57
  • FWIW, I find a soundex (http://en.wikipedia.org/wiki/Soundex)-type algorithm a better candidate for this sort of thing (For instance, waiferer, and wayfarer are IDENTICAL soundex scores). – Tyler Eaves Apr 03 '12 at 14:35
  • Unfortunately, I'm leaning towards the answer to this being "No". It would be possible, with a lot of messing about, to create a wrapper function which splits the string into words ([difficult in itself](http://stackoverflow.com/questions/471914) for an unknown number of words) then passes them all into the `LEVENSHTEIN()` function and returns the lowest value of all found words, which you could then `ORDER BY`. This, however, would probably not work as desired if someone just searched e.g. `farer`. It would also probably be pretty slow. My SQL-fu is not good enough to write it, either. – DaveRandom Apr 03 '12 at 14:40
  • @TylerEaves Good suggestion, although you still have the substring problem - `waiferer` and `Schwinn Men's 700c Wayfarer Bike` definitely *don't* have identical scores! – DaveRandom Apr 03 '12 at 14:43
  • I think better solution for this - using search engine like Sphinx, Solr etc. After indexing Search engine your database - you should make different types of search - exact, not exact, difference by n symbols etc. – yAnTar Apr 06 '12 at 15:00

0 Answers0