--- apachesolr_statsorig2.module	2010-07-01 16:33:15.000000000 +0100
+++ apachesolr_stats.module	2010-07-01 17:31:23.000000000 +0100
@@ -919,4 +919,59 @@ function apachesolr_stats_report_frequen
     ) . " (" . $data["count"] . ")";
   }
   return implode(", ", $items);
+}
+
+/**
+ * apachesolr_stats_keywords function. ripped version from above, ideally removed in favour
+ * of better keyword calling
+ * 
+ * @access public
+ * @return void
+ */
+function apachesolr_stats_keywords() {
+  $keywords = array();
+  $result = db_query("SELECT keywords FROM {apachesolr_stats}");
+  
+  while ($record = db_fetch_object($result)) {
+    if (trim($record->keywords) != "") {
+      // Keep track of individual keywords used
+      $keys_filtered = drupal_strtolower(trim($record->keywords));
+      $keywords[$keys_filtered]++;
+    }
+  }
+  return $keywords;
+}
+
+/**
+ * apachesolr_stats_block function.
+ * 
+ * @access public
+ * @param string $op. (default: 'list')
+ * @param int $delta. (default: 0)
+ * @return void
+ */
+function apachesolr_stats_block($op='list', $delta=0) {
+  if ($op == "list") {
+    // Generate listing of blocks from this module, for the admin/block page
+    $block = array();
+    $block[0]["info"] = t('Apachesolr Stats Most Popular Searches');
+    return $block;
+  }
+  else if ($op == 'view') {
+    $block['subject'] = '';
+    
+    // cache this at some point as it could get heavy, maybe block cache will deal with it.
+    $apachesolr_stats_popular = apachesolr_stats_keywords();
+    arsort($apachesolr_stats_popular);
+    $i = 0;
+    foreach($apachesolr_stats_popular as $key => $value) {
+      $apachesolr_stats_popular_data[] = l($key, 'search/apachesolr_search/'.check_plain($key));
+      $i++;
+      if ($i == 10) break;
+    }    
+    
+    $block['content'] = theme('item_list',$apachesolr_stats_popular_data);
+    
+    return $block;
+  }
 }
\ No newline at end of file
