« Speeding Up MovableType | Main | Jeff Gleason on Achieving Reusability with SOA »

Tag Cloud For My Blog

This morning’s entry on categories got me thinking and I decided to try generating a tag cloud based on the keywords I put on entries. Here is the result. I like it because it gives an immediate feel for which topics I spend the most time on. The cloud doesn’t show tags I used just once. To create the page, I followed Al-Muhajabah’s instructions with a few modifications.

  • I’m careful to separate my tags by commas or whitespace, so I replaced
    $wordlist = preg_split(
      '/\s*[\s+\.|\?|,|(|)|\-+|\'|\"|=|;|×|\$|\/|:|{|}]\s*/i', 
      $string);
    
    with
    $wordlist = preg_split('/\s+|,/i',$string);
    
    The longer regexp was breaking things up more than I wanted and I was ending up with tags that weren’t tags I’d created.
  • I modified some the font sizes to make them 25 points bigger all around. The smallest font wasn’t readable, at least in Firefox.
  • I changed if ($count >= 1) to if ($count >= 2) on the grounds that if I’ve only used a tag once, it’s probably not all that important.
  • Al-Muhajabah uses a SearchFields option in the search URL that doesn’t appear to be supported by MovableType. As an alternate, I used the SearchElement option which is supported, but not for keywords. I modified the _search_hit function in $MTHOME/lib/MT/App/Search.pm to support the keyword field like so:
    sub _search_hit {
      my($app, $entry) = @_;
      my @text_elements;
      if ($app->{searchparam}{SearchElement} ne 'comments') {
          @text_elements = 
              ($entry->title, $entry->text, $entry->text_more,
               $entry->keywords);
      }
      if ($app->{searchparam}{SearchElement} ne 'entries') {
          my $comments = $entry->comments;
          for my $comment (@$comments) {
              push @text_elements, 
                     $comment->text, $comment->author,
                     $comment->url;
          }
      }
      if ($app->{searchparam}{SearchElement} eq 'keywords') {
          @text_elements = ($entry->keywords);
      }
      return 1 
         if $app->is_a_match(
                join("\n", map $_ || '', @text_elements));
    }
    

This seems to work pretty well, giving the right results in the search. I’m going to monitor it for a while and eventually remove categories from my blog.

Posted by windley on March 14, 2006 11:59 AM

See related posts:

2 Comments

Very cool stuff, you should post this to my new code snippet community http://www.bytemycode.com

It would be a great addition. I should also modify my tag cloud code to implement some things you did here. Good stuff!

Glad you found mt-rebuild helpful. I also developed a plugin that does tag clouds and intersections called Tags.App http://code.appnel.com/tags-app
. In addition to tags frequency it also supports "entropy" -- use over time. Examples of its use can be seen on the O'Reilly Radar site http://radar.oreilly.com/
and Union Square Ventures http://www.unionsquareventures.com/ to name a few.