PDA

View Full Version : Code snippet to search again if no results


amcho
26-03-08, 13:30
I installed a modded version of IntroSites Search Spy described at
http://www.shopwindowforum.com/showthread.php?t=461

On analysing the results some of the searches that returned no results
included a special character (eg AEG-C41022GNM) while a search on "AEG C41022GNM"
was more fruitful.

The following bit of code gives us a second chance by stripping the search query of special characters,
and should be added to search.php just after the line
$oPage = new pageSearch($_......



if (count($oPage->oSearch->searchProductReturn) < 1) {
$q= $_GET['q'];
echo "No results for ".$q."\n<br>";
$n = preg_replace('/[-\/\\\(\)\"]/', ' ', $q);
if ($n!=$q) {
echo "Trying ".$n."\n<br>";
$_GET['q']=$n;
$oPage = new pageSearch($_GET['iListLimit'], $_GET['iListOffset'], '', $_GET['sListSort']);
}
}



To see the code in action go to
http://pricecompareuk.com/search.php?q=AEG-C41022GNM&c=0&search=Search

Usual disclaimers:
This worked for me, it may not for you, so use at your own risk, back everything up before messing with code, etc.
If you improve the code please post updates here so all can benefit.
Enjoy...

Bud
26-03-08, 14:57
What a great little piece of code - Thanks

I have removed the echos as this seemed to throw my formatting out (I don't know why, but I lose the central align of the page).

Also, it's an excellent code to learn from.

Much Kudos!

GeorgeGaz
01-04-08, 13:34
Hi amcho,

I must reiterate what Bud said, great piece of code amcho ;)

Thanks for sharing!

IntroSites
01-04-08, 15:05
Thanks amcho, was meaning to get round to that myself, thanks for sharing