How can I write an MySQL search that can compensat

2020-07-17 16:01发布

问题:

Is there any way to write an MySQL search that can compensate for user-errors in spelling and the like?

As random examples, someone might type foo@gmial.com instead of foo@gmail.com.

Even help with search terms to help pull up relevant data from Google will be helpful. I'm not looking for a search engine, per say, what I'm looking for is some kind of spelling aid for an administrative control panel.

回答1:

The topic you're delving into is called "Fuzzy Lookup". It's a big rabbit hole to jump down, depending on how precise you'd like to get. There are various methods, such as:

  • soundex
  • Damerau-Levenshtein distance
  • Jaro-Winkler distance
  • metaphone
  • double-metaphone

Some references to check out:

  • PHP/MySQL small-scale fuzzy search
  • http://en.wikipedia.org/wiki/Approximate_string_matching
  • How do I do a fuzzy match of company names in MYSQL with PHP for auto-complete?
  • Implementation of Levenshtein distance for mysql/fuzzy search?


回答2:

There are many ways to do the same. One of I personally like is SOUNDS LIKE.

Checkout the SOUNDEX Example.



标签: php mysql pdo