0

I'm trying out functionality of Levenshtein: MySQL + PHP

However my query doesn't return results:

SELECT * FROM products WHERE levenshtein('%".$search."%', `name`) < 5 OR levenshtein('%".$search."%', `series`) < 5 OR levenshtein('%".$search."%', `category`)  < 5

I was trying to make a simple search function using this.

Community
  • 1
  • 1
  • What exactly should that % help? You could not look for every product with a substring sounding like the question, I think. Just search for `$search`. – flaschenpost Jun 10 '13 at 11:25
  • 1
    Levenshtein distance works directly on two strings. It doesn't recognize wildcards. – Gordon Linoff Jun 10 '13 at 11:25
  • Thank you! @flaschenpost That's exactly what I'm trying to accomplish, but now I have no idea how. – Peter Magic Jun 10 '13 at 11:32
  • @PeterMagic you must give a few examples, because searching for substrings sounding like a given input will give quite crazy results (think about sea, archi, chin, ching, ear in "searching"). You may look for kind of splitting your names, categories etc into syllables and look for matching syllables. – flaschenpost Jun 10 '13 at 11:55
  • @flaschenpost I would rather like it to work in a way, that would return the row where "NAME OF PRODUCTS" is, if only the word "PRODUCTS" (or "PRODUDTS") is searched for. – Peter Magic Jun 10 '13 at 12:02
  • You will need to extract all the words from the field you are checking and then perform levenshtein comparisons on all those words. The levenshtein function as a MySQL proc is pretty slow though. – Kickstart Jun 10 '13 at 12:28

0 Answers0