Jump to content

search complete words only


Guest

Recommended Posts

Hello,

I've found that if I put in a search for 'table' I get anything back with table as part of the word, like vegetables. Or if you put in 'hog', you get mahogany. I'm using CC for a shop that sells miniatures (like scale models and the like) so the range of products is vast, from furniture (tables) to miniature food (vegetables).

Is there a way of only having complete word matches returned?

Many thanks, and I really hope someone can help.

Cheers!

Link to comment
Share on other sites

  • 4 weeks later...

Hello,

I've found that if I put in a search for 'table' I get anything back with table as part of the word, like vegetables. Or if you put in 'hog', you get mahogany. I'm using CC for a shop that sells miniatures (like scale models and the like) so the range of products is vast, from furniture (tables) to miniature food (vegetables).

Is there a way of only having complete word matches returned?

Many thanks, and I really hope someone can help.

Cheers!

Hi,

I'm currently building a site with cubecart 3.0.13 and wanted to do an exact word/complete word search for my product range eg the whole word "red" but not match "credit"... here are the changes I made to get it working. Changes were made to includes/content/viewCat.inc.php

ADD after:

		for ($i=0; $i<$noKeys;$i++) {




THE following:


			   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:


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




TO:


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

The above change adds two markers, they stand for word boundaries. They match the beginning and end of words, respectively.

FOR EXAMPLE: "This product is red." vs "Buy this product with a credit card.".... in the first example "red" is an isolated word because it is surrounded by non-alphabetic and/or non-numeric characters, in this case it is a "space" on the left and a "full-stop" on the right. Whereas in the second example "red" (part of the word "credit") is surrounded by alphabetic characters and therefore is not a whole/exact word, in this case "c" on the left and "it" on the right.

See the attached file for a diff formatted patch file.

viewCat_inc_php.txt

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...