summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2011-02-08 15:38:58 +0100
committerfranck cuny <franck@lumberjaph.net>2011-02-08 15:38:58 +0100
commitd78dc601cd9e9a24f2495676492a1cc1f3d7edd8 (patch)
tree685560f752e088329e37ac8c409ad6e9636c8327 /lib
parentChecking in changes prior to tagging of version 0.04. Changelog diff is: (diff)
downloadwebservice-google-suggest-d78dc601cd9e9a24f2495676492a1cc1f3d7edd8.tar.gz
update code to add rank information and make it work again
Diffstat (limited to 'lib')
-rw-r--r--lib/WebService/Google/Suggest.pm18
1 files changed, 11 insertions, 7 deletions
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 E<lt>miyagawa@bulknews.netE<gt>
+
 Franck Cuny E<lt>franck@lumberjaph.netE<gt>
 
 =head1 LICENSE