| 1 | # PurpleWiki::Search::Google.pm | ||
| 2 | # vi:ai:sm:et:sw=4:ts=4 | ||
| 3 | # | ||
| 4 | # $Id: Google.pm 364 2004-05-19 18:15:26Z eekim $ | ||
| 5 | # | ||
| 6 | # This file is part of PurpleWiki. PurpleWiki is derived from: | ||
| 7 | # | ||
| 8 | # UseModWiki v0.92 (c) Clifford A. Adams 2000-2001 | ||
| 9 | # AtisWiki v0.3 (c) Markus Denker 1998 | ||
| 10 | # CVWiki CVS-patches (c) Peter Merel 1997 | ||
| 11 | # The Original WikiWikiWeb (c) Ward Cunningham | ||
| 12 | # | ||
| 13 | # PurpleWiki is free software; you can redistribute it and/or modify | ||
| 14 | # it under the terms of the GNU General Public License as published by | ||
| 15 | # the Free Software Foundation; either version 2 of the License, or | ||
| 16 | # (at your option) any later version. | ||
| 17 | # | ||
| 18 | # This program is distributed in the hope that it will be useful, | ||
| 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 21 | # GNU General Public License for more details. | ||
| 22 | # | ||
| 23 | # You should have received a copy of the GNU General Public License | ||
| 24 | # along with this program; if not, write to the | ||
| 25 | # Free Software Foundation, Inc. | ||
| 26 | # 59 Temple Place, Suite 330 | ||
| 27 | # Boston, MA 02111-1307 USA | ||
| 28 | |||
| 29 | package PurpleWiki::Search::Google; | ||
| 30 | |||
| 31 | use strict; | ||
| 32 | use base 'PurpleWiki::Search::Interface'; | ||
| 33 | use PurpleWiki::Search::Result; | ||
| 34 | |||
| 35 | our $VERSION; | ||
| 36 | $VERSION = sprintf("%d", q$Id: Google.pm 364 2004-05-19 18:15:26Z eekim $ =~ /\s(\d+)\s/); | ||
| 37 | |||
| 38 | # Where the searching is done. | ||
| 39 | sub search { | ||
| 40 | my $self = shift; | ||
| 41 | my $query = shift; | ||
| 42 | my @results; | ||
| 43 | |||
| 44 | require SOAP::Lite; | ||
| 45 | |||
| 46 | my $service = 'file:' . $self->config()->GoogleWSDL(); | ||
| 47 | my $key = $self->config()->GoogleKey(); | ||
| 48 | |||
| 49 | return @results unless $key; | ||
| 50 | |||
| 51 | my $result = SOAP::Lite | ||
| 52 | -> service($service) | ||
| 53 | -> doGoogleSearch($key, $query, 0, 10, 0, '', 0, '', | ||
| 54 | 'latin1', 'latin1'); | ||
| 55 | |||
| 56 | if (@{$result->{resultElements}} > 0) { | ||
| 57 | foreach my $element (@{$result->{resultElements}}) { | ||
| 58 | my $result = new PurpleWiki::Search::Result; | ||
| 59 | $result->url($element->{URL}); | ||
| 60 | $result->title($element->{title}); | ||
| 61 | $result->summary($element->{snippet}); | ||
| 62 | push(@results, $result); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | return @results; | ||
| 67 | } | ||
| 68 | |||
| 69 | 1; | ||
| 70 | |||
| 71 | __END__ |