Display top searches in a "tag cloud" style
z.stolar - December 29, 2008 - 19:59
| Project: | Top Searches |
| Version: | 6.x-1.0-rc3 |
| Component: | User interface |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
Add a block to show top searches the way tagadelic shows tags. The more a phrase is searched for, the bigger it shows.

#1
sweet!
#2
Where can i find the break that its putting after every word?
#3
which break are you referring to?
#4
I could not find this feature in RC3. Not sure if you already have it working in a dev version, but I made a preprocess function for my theme to do this, based on code from the Tagadelic module.
Here is my preprocess function, in case you want to take a look at the implementation.
<?php
function MYTHEME_top_searches_block($top_searches) {
// The calculations for weighting items. Shamelessly borrowed from tagadelic.module (lines 238-265),
// all credit should go to the maintainer (ber) and MatheMagician (Steve Wittens) of that module.
$steps = 5; // The number of levels we are weighting with.
$searches = array();
$min = 1e9; // Here we use natural logarithms as a basis for calculating weight. I do not know why.
$max = -1e9;
foreach ($top_searches as $search) {
$search->number_of_searches = $search->counter; // We need to store the actual search counter here,
$search->counter = log($search->counter); // because here we overwrite the original with log().
$min = min($min, $search->counter); // These lines figure out if we have a new min or max.
$max = max($max, $search->counter);
$searches[] = $search; // And finally store the information in our array.
}
// Note: we need to ensure the range is slightly too large to make sure even
// the largest element is rounded down.
$range = max(.01, $max - $min) * 1.0001; // Math magic, do not ask me...
$searchcloud = array(); // A new array - this will be used to create the output.
foreach ($searches as $key => $value) { // Weight calculation and addition to our new array.
$searchcloud[] = array('weight' => 1 + floor($steps * ($value->counter - $min) / $range), 'item' => $value);
}
// Get the variable setting of whether or not to display the actual search count.
$show_counters = variable_get('top_searches_show_counters', 0);
// Set up the actual output array and then go through our prepared array with the weights.
$items = array();
foreach ($searchcloud as $key => $q) {
$level = $q['weight']; // This is the key for adding a weight class to the links.
$items[] = l($q['item']->q,
'search/node/' . $q['item']->q,
array('attributes' => array('class' => "search-cloud-item level-$level")))
. ($show_counters ? ' (' . $q['item']->number_of_searches . ')' : '');
}
return theme('item_list', $items, NULL, 'ul', array('class' => 'search-cloud'));
} // function MYTHEME_top_searches_block
?>
#5
tjodolv, could you please give me an example of using the code above?
Which file should this function be placed in and can you please give me an example of how and where this will be called from?
I thought it was a case of replacing the "theme_top_searches_block" code with what you have above but that is not changing how the block is displayed, I'm pretty new to Drupal so any help is very much appreciated.
Thanks!!!
#6
This function is a template preprocess function, and those functions should be placed in the
template.phpfile of the current theme you are using. If you are using Garland, go to the/themes/garland/template.phpfile and add this at the end. If you are using a custom theme, the file should be at/sites/all/themes/YOURTHEMENAME/template.php.edit:
You should never replace any code in a module (and especially not in Drupal core). This is one of the reasons we have the PHPTemplate theme engine, to do these kinds of "rewrites" to change the look and feel of the site. If you need a module's functionality changed, you either need a different or additional module, or a patch with the additional functionality should be submitted to the module in question.