You are here:  » Concatenate Search Terms


Concatenate Search Terms

Submitted by EIF Media on Sun, 2013-05-12 16:15 in

Hello,

Can you tell me if there is a way to concatenate search terms to provide a more comprehensive set of results? For example if someone searches the term 'smash mouth' a search would be performed for smash+mouth+"smash mouth"?

Thank you once again for your excellent support!

Dan

Submitted by support on Mon, 2013-05-13 08:40

Hi Dan,

It's straight forward to give this a go in queries that trigger use of the FULLTEXT index (all terms > 3 characters long). In search.php look for the following code around line 215:

  $where = "MATCH ".$matchFields." AGAINST ('".database_safe($parts[0])."')";
  $sql = "SELECT SQL_CALC_FOUND_ROWS * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, MATCH ".$matchFields." AGAINST ('".database_safe($parts[0])."') AS relevance FROM `".$config_databaseTablePrefix."products` WHERE ".$where.$priceWhere." GROUP BY name";

...and REPLACE with:

  $against = "'".database_safe($parts[0])." \"".database_safe($parts[0])."\"' IN BOOLEAN MODE";
  $where = "MATCH ".$matchFields." AGAINST (".$against.")";
  $sql = "SELECT SQL_CALC_FOUND_ROWS * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, MATCH ".$matchFields." AGAINST (".$against.") AS relevance FROM `".$config_databaseTablePrefix."products` WHERE ".$where.$priceWhere." GROUP BY name";

That will create a second version of the query in "quotes" (phrase match in MySQL FULLTEXT searching) that is searched in boolean mode (logic OR by default) with the original terms...

Cheers,
David.
--
PriceTapestry.com