/** * Retrieve the top 20 search terms by popularity from the search_stats table * Enter description here ... */ function getTopSearches() { require_once ROOT_DIR . '/Drivers/marmot_inc/SearchStatNew.php'; $numSearchesToReturn = isset($_REQUEST['numResults']) ? $_REQUEST['numResults'] : 20; $searchStats = new SearchStatNew(); $searchStats->query("SELECT phrase, numSearches as numTotalSearches FROM `search_stats_new` where phrase != '' order by numTotalSearches DESC LIMIT " . $numSearchesToReturn); $searches = array(); while ($searchStats->fetch()) { $searches[] = $searchStats->phrase; } return $searches; }
function saveSearch($phrase, $type = false, $numResults) { //Don't bother to count things that didn't return results. if (!isset($numResults) || $numResults == 0) { return; } //Only save basic searches if (strpos($phrase, '(') !== FALSE || strpos($phrase, ')') !== FALSE) { return; } //Don't save searches that are numeric (if someone has a number they won't need suggestions). if (is_numeric($phrase)) { return; } //Don't save searches that look like spam if (preg_match('/http:|mailto:|https:/i', $phrase)) { return; } //Don't save really long searches if (strlen($phrase) >= 256) { return; } $phrase = str_replace("\t", '', $phrase); $searchStat = new SearchStatNew(); $searchStat->phrase = trim(strtolower($phrase)); $searchStat->find(); $isNew = true; if ($searchStat->N > 0) { $searchStat->fetch(); $searchStat->numSearches++; $isNew = false; } else { $searchStat->numSearches = 1; } $searchStat->lastSearch = time(); if ($isNew) { $searchStat->insert(); } else { $searchStat->update(); } }