Reputation:
Example, I want to search for "John Smith" in "My name is John Joe Smith and I live in America". But with a limit of 5 characters between "John" and "Smith".
How could I get this with MySql (php)?
I am building a search engine for my database, I am already using MATCH AGAINST, but I also want to offer a different kind of search.
thank you, Andy
Upvotes: 0
Views: 95
Reputation: 1269593
But with a limit of 5 characters between "John" and "Smith"
MySQL full text functions don't offer such flexibility as far as I know. You can use like
or regular expressions:
where col regexp 'John.{0,5}Smith'
If you do the full text search in a subquery, then this might actually have reasonable performance.
The delightful like
expression is:
where col like '%John%Smith%' and
col not like '%John______Smith%'
There are six _
s.
Upvotes: 0
Reputation: 1456
You may want to explore
SOUNDEX()
, this will help you to achieve what you need, e.g. auto suggest functionality. strings. but it comes with few drawbacks as only the first few characters are taken into account, first letter must be the same or you won't find a match easily.
For more advanced needs, I think you need to look at the
Levenshtein distance aka "edit distance" of two strings and work with a threshold
. This is the more complex yet slower solution, but it comes with better flexibility
You might want refer example tutorial here
Upvotes: 1