function apachesolr_stats_block_frequent_keywords in Apache Solr Statistics 6
Same name and namespace in other branches
- 6.3 apachesolr_stats.module \apachesolr_stats_block_frequent_keywords()
- 7 apachesolr_stats.module \apachesolr_stats_block_frequent_keywords()
Return a listing of keywords for the Popular Searches block.
1 call to apachesolr_stats_block_frequent_keywords()
- apachesolr_stats_block in ./
apachesolr_stats.module - Implementation of hook_block().
1 string reference to 'apachesolr_stats_block_frequent_keywords'
- apachesolr_stats_uninstall in ./
apachesolr_stats.install - Implementation of hook_uninstall().
File
- ./
apachesolr_stats.module, line 1003 - Keeps and reports statistics about Apache Solr usage and performance.
Code
function apachesolr_stats_block_frequent_keywords($limit = 10) {
$cid = "apachesolr_stats_block_frequent_keywords";
$cached = cache_get($cid, 'cache_block');
if ($cached && $cached->data && $cached->expire > time()) {
return $cached->data;
}
$keywords = array();
// Return keywords only last week's logged queries.
$timestamp = time() - 3600 * 24 * 7;
$result = db_query_range("SELECT keywords FROM {apachesolr_stats} WHERE\n numfound > 0 AND timestamp > %d\n ORDER BY timestamp DESC", $timestamp, 0, 5000);
while ($record = db_fetch_object($result)) {
if (trim($record->keywords) != "") {
// Keep track of individual keywords used
$keys_filtered = drupal_strtolower(trim($record->keywords));
if (isset($keywords[$keys_filtered])) {
$keywords[$keys_filtered]++;
}
else {
$keywords[$keys_filtered] = 1;
}
}
}
// Sort by most frequent first.
arsort($keywords);
// Get first $limit items.
$keywords = array_slice($keywords, 0, $limit);
$links = array();
foreach ($keywords as $key => $frequency) {
$links[] = l($key, 'search/apachesolr_search/' . $key);
}
// Cache information for 10 minutes.
$expire = time() + 600;
cache_set($cid, $links, 'cache_block', $expire);
return $links;
}