O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  



HACK
#79
Measuring Google Mindshare
Measure the Google mindshare of a particular person within a query domain.
The Code

Contributed by:

[03/13/03 | Discuss (5) | Link to this hack]

Based on an idea by author Steven Johnson (http://www.stevenberlinjohnson.com), this hack determines the Google mindshare of a person within a particular set of Google queried keywords. What's Willy Wonka's Google mindshare of "Willy"? What percentage of "weatherman" does Al Roker hold? Who has the greater "The Beatles" Google mindshare, Ringo Starr or Paul McCartney? More importantly, what Google mindshare of your industry does your company own?

Google mindshare is calculated as follows: determine the size of the result set for a keyword or phrase. Determine the result set size for that query along with a particular person. Divide the second by the first and multiply by 100, yielding percent Google mindshare. For example: A query for Willy yields about 1,590,000 results. "Willy Wonka" +Willy finds 66,700. We can conclude—however unscientifically—that Willy Wonka holds roughly a 4% (66,700 / 1,590,000 × 100) Google mindshare of Willy.

Sure it's a little silly, but there's probably a grain of truth in it somewhere.

The Code

The Code

#!/usr/local/bin/perl
# google_mindshare.cgi
# This implementation by Rael Dornfest
# http://www.raelity.org/lang/perl/google/googleshare/
# Based on an idea by Steven Johnson
# http://www.stevenberlinjohnson.com/movabletype/archives/000009.html

# Your Google API developer's key
my $google_key='insert key here';

# Location of the GoogleSearch WSDL file
my $google_wdsl = "./GoogleSearch.wsdl";

use SOAP::Lite;
use CGI qw/:standard *table/;

print
  header(  ),
  start_html("Googleshare Calculator"),
  h1("Googleshare Calculator"),
  start_form(-method=>'GET'),
  'Query: ', br(  ), textfield(-name=>'query'),
  p(  ),
  'Person: ',br(  ), textfield(-name=>'person'),
  p(  ),
  submit(-name=>'submit', -value=>'Calculate'),
  end_form(  ), p(  );

if (param('query') and param('person')) {
  my $google_search  = SOAP::Lite->service("file:$google_wdsl");

  # Query Google for they keyword, keywords, or phrase
  my $results = $google_search ->
    doGoogleSearch(
      $google_key, '"'.param('query').'"', 0, 1, "false", "",  "false",
      "", "latin1", "latin1"
    );

  # Save the results for the Query
  my $query_count = $results->{estimatedTotalResultsCount};

  my $results = $google_search ->
    doGoogleSearch(
      $google_key, '+"'.param('query').'" +"'.param('person').'"', 0, 1,
      "false", "",  "false", "", "latin1", "latin1"
    );
  # Save the results for the Query AND Person
  my $query_person_count = $results->{estimatedTotalResultsCount};

  print
    p(
      b(sprintf "%s has a %.2f%% googleshare of %s",
        param('person'),
        ($query_person_count / $query_count * 100),
        '"'.param('query').'"'
      )
    )
}

print end_html(  );


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.