You are here:  » Refining search


Refining search

Submitted by krispy1812 on Fri, 2006-07-28 20:13 in

Hi,

Is there any way to refine the search features of the script.

I have noticed that when searching for twin named products, such as digital cameras, the search results thrown out everything with both the words 'digital' and 'camera' in the results. In this particular instance on my site, I have digital products completely unrelated to cameras.

How can this be refined to throw out on 'digital cameras' if that is what someone was searching for.

Thanx

Submitted by support on Fri, 2006-07-28 20:46

Hi,

Firstly to explain what you are seeing...

The normal search method uses MySQL's "Full Text" indexing feature; which by default tries to work in a way similar to a search engine like Google in that not all the words have to be in product record in order for it to match - however a product that does have all the words will be ranked higher in relevance and appear at the top of the list. One nice side effect is that it helps users find products even if they are not sure of the spelling, or have got a model number wrong for example.

It will certainly be possible to change the SQL to return only products with all the words in the query in the product name (but not necessarily contigously) - so i'll do some experiements on my test server to work out the best code to use...

Cheers,
David.

Submitted by badger on Sat, 2006-07-29 12:11

ive noticed that if i search for psp i get results like the following

ASUS WIRELESS LAN 54Mbps PC CARD WL 107G

Submitted by support on Sat, 2006-07-29 12:29

Yes - that's because the full text index does not include words of less than 4 characters; so when you type in a 3 letter query the "normal" search method is used which is a basic string search.

However - to make the search function more user friendly (in the majority of cases) the search is done against a field that is stripped of all white space, so the query "psp" is matching "54Mbps PC" within that string.

The reason it's done like that is so that users can search for model numbers without having to worry about exactly how the model number is specified, for example "Sony DSCS40" would still match "Sony DSC S40" - although not that this only applies to

Submitted by krispy1812 on Sat, 2006-07-29 12:46

Thanx for your replies David.

Submitted by support on Sat, 2006-07-29 14:53

You'll need MySQL > 4.0.1 (version checker script) to do all inclusive searches against the full text index. The code is as follows; although note that the "Relevance" sort become irrelevant as all results are considered equally relevant. The code is as follows, replacing line 65 of search.php:

$match = "";
$words = explode(" ",$parts[0]);
foreach($words as $word) $match .= "+".database_safe($word)." ";
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, MATCH name AGAINST ('".$match."' IN BOOLEAN MODE) AS relevance FROM `".$config_databaseTablePrefix."products` WHERE MATCH name AGAINST ('".$match."' IN BOOLEAN MODE) GROUP BY name";

Another alternative you might want to consider is using the old search method (currently used just for queries of less than 4 characters). To do this, change line 63 of search.php to just:

if (0)

Cheers,
David.