Wow...it so happens that I was modifying the original Search Log 0.4 the same day as you realease this and ran across your post. I like what you've done with it, so I changed over to your code...but I couldn't leave it alone with what I'd already learned

So here are my "improvements"

A.) A lighter weight method of getting the data into the table is to use the tpl_advanced_search_result_default.php file to get the search results. If you use my method, you should not use the files (delete them) in the "includes" directory of the distribution. (Basically, the class file and the auto_loader)


Edit or copy the default file to: includes/templates/[YOUR TEMPLATE NAME]\templates\tpl_advanced_search_result_default.php

Find the line around 48:

require($template->get_template_dir('tpl_modules_product_listing.php', DIR_WS_TEMPLATE, $current_page_base,'templates'). '/' . 'tpl_modules_product_listing.php');

And append this code after it

// GDS add 8-23-07 for search_log
// Modified to return number of rows returned
$keyword = (strip_tags(trim($_GET['keyword'])));
$searchsql = "insert into " .DB_PREFIX. "search_log (search_term, search_time, search_results) values ('". $keyword .
"',now(),'". $listing_split->number_of_rows ."')";
$result = $db->Execute($searchsql);
if (!$result) {
$messageStack->add_session('search', ENTRY_ADV_SEARCH_INSERTION_ERROR);
}

// End of GDS add 8-23-07 for search_log

This saves a database call.

B.) I also modified the admin page to show the top 5 search terms. This requires adding code to admin/index.php. Find the end of the </div> around line 160.

Some code right before this point is:


echo ' <div class="row"><span class="left">' . $counter_startdate_formatted . '</span><span class="rigth"> ' . $counter->fields['session_counter'] . ' - ' . $counter->fields['counter'] . '</span> </div>' . "\n";
$counter->MoveNext();
}
?>

</div>

Append the following code after it:
<!- GDS Added 8-3-07 for search_log -->

<div class="reportBox">
<div class="header"><?php echo SEARCHLOG_TOP_5; ?></div>
<?php
echo "<table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\">
<tr>
<td width=\"110\"><b>" . SEARCHLOG_TERM . "</b></td>
<td><b>" . SEARCHLOG_COUNT . "</b></td>
</tr>";
$color1 = "#F8E7F9";
$color2 = "#BFD8BC";
$row_count = 0;


$sql = "SELECT search_term, count(*) AS Number
FROM " . TABLE_SEARCH_LOG . "
WHERE search_term is not null and search_term not like ''
GROUP BY search_term
ORDER BY Number desc limit 0,5";
$result = mysql_query($sql);

if (!$result) {
$messageStack->add(ENTRY_SEARCHLOG_ID_NOT_FOUND, 'error');
} ###### End of if statement.

while ($row = @mysql_fetch_array($result)) {
$searchterm = (isset($row["search_term"]) && !empty($row["search_term"])) ? trim($row["search_term"]) : "";
$number = (isset($row["Number"]) && $row["Number"] != 0) ? intval(trim($row["Number"])) : 0;

/* Now we do this small line which is basically going to tell
PHP to alternate the colors between the two colors we defined above. */

$row_color = ($row_count % 2) ? trim($color1) : trim($color2);

// Echo your table row and table data that you want to be looped over and over here.

echo "<tr>
<td width=\"110\" bgcolor=\"$row_color\" nowrap>" . $searchterm . "</td>
<td bgcolor=\"".$row_color."\">" . $number . "</td>
</tr>";

// Add 1 to the row count

$row_count++;
}

// Close out your table.

echo "</table>";
echo '<a href=' . zen_href_link(FILENAME_STATS_SEARCH_LOG, '', 'NONSSL'). '>' . BOX_REPORTS_SEARCH_LOG . '</a>';
?>
</div>

<!- End of GDS Add 8-23-07 for search_log -->


Next add the following lines to admin/includes/languages/english/extra_definitions/search_log.php

// Added by GDS on 8/23/07 to handle Top5 info on admin page
define('SEARCHLOG_TERM', '<b>Search Term</b>');
define('SEARCHLOG_TOP_5', 'Search Log Top 5');
define('SEARCHLOG_COUNT', '<b>count</b>');
define('VIEW_SEARCH_LOG', 'View Search Log');
define('ENTRY_SEARCHLOG_ID_NOT_FOUND', 'Error: Search ID could not be found.');
define('ENTRY_SEARCHLOG_EMPTY_ROWS', 'There are currently no search logs entries in your ' . DB_PREFIX. TABLE_SEARCH_LOG . ' table. ');

That's all there is to it.


Hope this helps someone,

Gregg Short
GShort.com Web Marketing and Design