The field Products.Name
contains PETISCO NESTLE PURINA DOG CHOW CARINHOS MIX DE FRUTAS
I need search de word DOG
and the word NESTEL
(wrong word) but the first three letters are correct.
I don't know the order of the words.
I tried same thing like this REGEXP '[^DOG][^NESTEL]{3}'
but doesn't work!
thanks
Update 1:
When the user types DOG and NESTEL I want my app to show all products that contain the words DOG and NESTLE, even part of the word is wrong!
Update 2:
where Products.Name REGEXP '[[:<:]]?=*NES.*[[:>:]]' and Products.Name REGEXP '[[:<:]]?=*DOG.*[[:>:]]'
This shows me the dog E NES but if the user types NESTEL and not NESTLE?
You need the levenshtein function for mysql. It goes through all the results evaluating them according to it's similarity to the searched word (ie NESTEL) and return them with that extra ratio field. Then you only have to select the one with a higher ratio, or a list with the ones more similar... etc.
SELECT ...
FROM ...
WHERE Name REGEXP '[[:<:]]dog[[:>:]]'
AND Name REGEXP '[[:<:]]nes';
It does not check for 6 letters in "nes...", that would be
AND Name REGEXP '[[:<:]]nes[az]{3}[[:>:]]';
There may be a collation issue; please provide SHOW CREATE TABLE
.
Mini-lesson:
[^DOG]
says "match 1 bytes, but not D
, nor O
, nor G
. [^NESTEL]{3}
says match exactly 3 bytes, but they cannot be any of those 6 letters. ?
NES.*[[:>:]]
matches NES
, followed by the rest of the string -- This is because *
is "greedy" and that [[:>:]]
will match the end of string. nes***
as a regexp would say ne
followed by any number of s
, including zero. nes...
would match nes
plus 3 bytes of any kind. So, all it says it that the nes
must not be too near the end of the string. WHERE some_col LIKE '%dog%nes%' or some_col LIKE '%nes%dog%'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.