Hello
I'm using fulltext without problem on my website
when somebody is searching for "blue shoes" it gives all results with either "blue" or "shoes" in name and description
what i would like is that it gives all results with only "blue shoes" in name
How can i do that ?
Tx
Coyote
Hi David
Thanks, it works like a charm, as usual ;)
Have a good week end !
Cheers,
Coyote
Hi Coyote,
The full text index search should work by relevance, so anything with BLUE and SHOES will be ranked higher than a record without one or other of the words. However it is easy to make the full text query use AND logic. In search.php, look for the following block of code beginning at line 77:
if ($useFullText)
{
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, MATCH name AGAINST ('".database_safe($parts[0])."') AS relevance FROM `".$config_databaseTablePrefix."products` WHERE MATCH name AGAINST ('".database_safe($parts[0])."') GROUP BY name";
$sqlResultCount = "SELECT COUNT(DISTINCT(name)) as resultcount FROM `".$config_databaseTablePrefix."products` WHERE MATCH name AGAINST ('".database_safe($parts[0])."')";
$orderBySelection = $orderByFullText;
}
...and REPLACE that with:
if ($useFullText)
{
$match = "+".str_replace(" "," +",$parts[0]);
$sql = "SELECT *, MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, MATCH name AGAINST ('".database_safe($match)."' IN BOOLEAN MODE) AS relevance FROM `".$config_databaseTablePrefix."products` WHERE MATCH name AGAINST ('".database_safe($match)."' IN BOOLEAN MODE) GROUP BY name";
$sqlResultCount = "SELECT COUNT(DISTINCT(name)) as resultcount FROM `".$config_databaseTablePrefix."products` WHERE MATCH name AGAINST ('".database_safe($match)."' IN BOOLEAN MODE)";
$orderBySelection = $orderByFullText;
}
Cheers,
David.