You are here:  » Logging 1st Search Result


Logging 1st Search Result

Submitted by ChrisNBC on Tue, 2013-05-07 14:47 in

Hi David,

Hope you had a good BH weekend.

I've implemented the search logging detailed in node 2229 (only logging where a match is found). It works beautifully.... but I wondered if you could suggest if there is a way I can alter (what's logged and returned) so that in addition to the search term the 1st returned result from the search is also stored in the table?

I thought this might have already been asked in the past but unless I missed it, I could not see anything in the forum.

Thanks in advance.

Regards
Chris

Submitted by support on Tue, 2013-05-07 15:07

Hi Chris,

Sure - that can be added easily - first add the new field "first_result" to the log table with the following dbmod.php script:

<?php
  
require("includes/common.php");
  
$sql "ALTER TABLE `".$config_databaseTablePrefix."querylog` ADD `first_result` VARCHAR(255)";
  
database_queryModify($sql,$result);
  print 
"Done.";
?>

Then, the logging code needs to be moved to after the point at which the $searchresults array has been created, so instead of immediately following if ($q), look for the following code around line 362:

    require("html/searchresults.php");

...and REPLACE with:

    if ($_GET["log"])
    {
      $sql = "INSERT INTO `".$config_databaseTablePrefix."querylog` SET query='".database_safe($q)."'";
      database_queryModify($sql,$result);
      $sql = "UPDATE `".$config_databaseTablePrefix."querylog` SET count=count+1,first_result='".database_safe($searchresults["products"][0]["name"])."' WHERE query='".database_safe($q)."'";
      database_queryModify($sql,$result);
    }
    require("html/searchresults.php");

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Wed, 2013-05-08 16:50

Hi David,

Thanks as always for the super quick response. I updated the code as you suggested and it works pretty well.... The only problem seems to be when I partially type a search and then select from the 'Auto Complete' dropdown (same as detailed in http://www.pricetapestry.com/node/5003). When I do this I'm directly sent to the product and nothing appears to be logged in the database. I wondered if you could suggest a way I can resolve this? Also, I noticed the count increments by 2 for each search?
Incidentally, I couldn't get the SQL php you sent to work since it generated a load of SQL errors.. so I created the extra field using PHPAdmin instead.
Thanks in advance.

Regards
Chris

Submitted by support on Wed, 2013-05-08 17:06

Hi Chris,

That sounds like the original logging code is still in place hense the double increment. If you could email me your latest search.php i'll make sure there's only the one instance, and also add logging when being redirected as a result of selecting an auto-complete option for you...

Cheers,
David.
--
PriceTapestry.com