From d78dc601cd9e9a24f2495676492a1cc1f3d7edd8 Mon Sep 17 00:00:00 2001 From: franck cuny Date: Tue, 8 Feb 2011 15:38:58 +0100 Subject: update code to add rank information and make it work again --- lib/WebService/Google/Suggest.pm | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/WebService/Google/Suggest.pm b/lib/WebService/Google/Suggest.pm index d2e36c0..e1d6598 100644 --- a/lib/WebService/Google/Suggest.pm +++ b/lib/WebService/Google/Suggest.pm @@ -34,12 +34,13 @@ sub complete { my ( $user_query, $array ) = ( $1, $2 ); my @results; - while ( $array =~ /\[([^\]]+)\]/g ) { + while ( $array =~ /\[([^\]]+)\]/g ) { my $row = $1; - my ( $query, $count ) = $row =~ /\"([^"]+)\",\"([\d,]+) results?/; + my ( $query, $count, $rank ) = $row =~ /\"([^"]+)\",\"([\d]+)?\",\"([\d]+)?\"/; $count =~ tr/,//d; $count += 0; # numify - push @results, { query => $query, results => $count }; + $rank += 0; + push @results, { query => $query, results => $count, rank => $rank }; } return @results; @@ -56,10 +57,12 @@ WebService::Google::Suggest - Google Suggest as an API use WebService::Google::Suggest; - my $suggest = WebService::Google::Suggest->new(); + my $suggest = WebService::Google::Suggest->new(); my @suggestions = $suggest->complete("goog"); for my $suggestion (@suggestions) { - print "$suggestion->{query}: $suggestion->{results} results\n"; + print "[" . $suggestion->{rank} . "] " + . $suggestion->{query} . ":" + . $suggestion->{results} results . "\n"; } =head1 DESCRIPTION @@ -85,8 +88,8 @@ the query. Suggestions are in a list of hashrefs, for example with query "Google": @suggestions = ( - { query => "google", results => 122000000 }, - { query => "google toolbar", results => 2620000 }, + { query => "google", results => 0, rank => 0 }, + { query => "google toolbar", results => 0, rank => 1 }, ... ); @@ -105,6 +108,7 @@ properties. =head1 AUTHOR Tatsuhiko Miyagawa Emiyagawa@bulknews.netE + Franck Cuny Efranck@lumberjaph.netE =head1 LICENSE -- cgit 1.4.1