Reputation: 53
I am trying to make exact search but getting problem when search with "Sonal", I am getting result from the record has "Sonal" & "personal". When I remove % before var name then getting the result which record start from "Sonal" and doesn't find that text has "Sonal" anywhere.
Here is the query:
AND (
lower(document_text) LIKE '%".$search_name2."%'
OR lower(customdoc_name) LIKE '%".$search_name2."%'
OR lower(doc_tags) LIKE '%".$search_name2."%'
)
Rec. 1 - Personal Certificate
Rec. 2 - Sonal Certificate.
I want only 2nd record return when search with "Sonal".
I am not using FULLTEXT Field.
Upvotes: 1
Views: 98
Reputation: 1147
Use REGEXP
try following..
AND (
lower(document_text) REGEXP '[[:<:]]".$search_name2."[[:>:]]'
OR lower(customdoc_name) REGEXP '[[:<:]]".$search_name2."[[:>:]]'
OR lower(doc_tags) REGEXP '[[:<:]]".$search_name2."[[:>:]]'
)
Performance wise not good.. but you will get exact results..
Upvotes: 1
Reputation: 4860
this may help,
add space back of string or front and back or front only. by this you will get result with "sonal" in case of beginning of string or middle of string or end of string.
AND (
lower(document_text) LIKE '%".$search_name2." %'
OR lower(customdoc_name) LIKE '% ".$search_name2." %'
OR lower(doc_tags) LIKE ' %".$search_name2."%'
)
Upvotes: 2
Reputation: 43235
"%" operator behaves this way only.
It is a wildcard character meaning ANY STRING. So
Upvotes: 0