Jump to content

search complete words only - return products with all keywods only


Guest mikejshaw

Recommended Posts

Guest mikejshaw

Hi,

I tried the following code and it works; but it's not specific enough. If I search for 'history' and 'france' it returns titles with either keyword. What do i need to change if i want to find only those products containing all of the search keywords? I tried changing some ORs to ANDs but it didn't work (I'm a cut and paste monkey - not a coder!)

Any help appreciated.

CODE

if(strlen(trim($searchArray[$i])) == 0) {

continue;

}

The above addition means that empty search terms are ignored eg spaces at the begining or the end of a search query (" red and green" OR "red and green ")

CHANGE the following query:

CODE

$like .= "(name LIKE '%".$searchArray[$i]."%' OR description LIKE '%".$searchArray[$i]."%' OR productCode LIKE '%".$searchArray[$i]."%') OR ";

TO:

CODE

$like .= "(name REGEXP '[[:<:]]".$searchArray[$i]."[[:>:]]' OR description REGEXP '[[:<:]]".$searchArray[$i]."[[:>:]]' OR productCode REGEXP '[[:<:]]".$searchArray[$i]."[[:>:]]') OR ";

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...