| 1 | # PurpleWiki::Search::Engine.pm | ||
| 2 | # vi:ai:sm:et:sw=4:ts=4 | ||
| 3 | # | ||
| 4 | # $Id: Engine.pm 366 2004-05-19 19:22:17Z eekim $ | ||
| 5 | # | ||
| 6 | # Copyright (c) Blue Oxen Associates 2002-2004. All rights reserved. | ||
| 7 | # | ||
| 8 | # This file is part of PurpleWiki. PurpleWiki is derived from: | ||
| 9 | # | ||
| 10 | # UseModWiki v0.92 (c) Clifford A. Adams 2000-2001 | ||
| 11 | # AtisWiki v0.3 (c) Markus Denker 1998 | ||
| 12 | # CVWiki CVS-patches (c) Peter Merel 1997 | ||
| 13 | # The Original WikiWikiWeb (c) Ward Cunningham | ||
| 14 | # | ||
| 15 | # PurpleWiki is free software; you can redistribute it and/or modify | ||
| 16 | # it under the terms of the GNU General Public License as published by | ||
| 17 | # the Free Software Foundation; either version 2 of the License, or | ||
| 18 | # (at your option) any later version. | ||
| 19 | # | ||
| 20 | # This program is distributed in the hope that it will be useful, | ||
| 21 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 22 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 23 | # GNU General Public License for more details. | ||
| 24 | # | ||
| 25 | # You should have received a copy of the GNU General Public License | ||
| 26 | # along with this program; if not, write to the | ||
| 27 | # Free Software Foundation, Inc. | ||
| 28 | # 59 Temple Place, Suite 330 | ||
| 29 | # Boston, MA 02111-1307 USA | ||
| 30 | |||
| 31 | package PurpleWiki::Search::Engine; | ||
| 32 | |||
| 33 | use strict; | ||
| 34 | use PurpleWiki::Search::Result; | ||
| 35 | |||
| 36 | our $VERSION; | ||
| 37 | $VERSION = sprintf("%d", q$Id: Engine.pm 366 2004-05-19 19:22:17Z eekim $ =~ /\s(\d+)\s/); | ||
| 38 | |||
| 39 | sub new { | ||
| 40 | my $class = shift; | ||
| 41 | my $self = {}; | ||
| 42 | |||
| 43 | bless ($self, $class); | ||
| 44 | |||
| 45 | my %params = @_; | ||
| 46 | |||
| 47 | $self->{config} = PurpleWiki::Config->instance(); | ||
| 48 | |||
| 49 | $self->{modules} = $self->{config}->SearchModule; | ||
| 50 | |||
| 51 | return $self; | ||
| 52 | } | ||
| 53 | |||
| 54 | sub search { | ||
| 55 | my $self = shift; | ||
| 56 | my $query = shift; | ||
| 57 | |||
| 58 | foreach my $module (@{$self->{modules}}) { | ||
| 59 | my $class = "PurpleWiki::Search::$module"; | ||
| 60 | eval "require $class"; | ||
| 61 | |||
| 62 | my $searcher = $class->new(); | ||
| 63 | |||
| 64 | $self->{results}{$module} = [ $searcher->search($query) ]; | ||
| 65 | } | ||
| 66 | |||
| 67 | return $self; | ||
| 68 | } | ||
| 69 | |||
| 70 | sub modules { | ||
| 71 | return \@{shift->{modules}}; | ||
| 72 | } | ||
| 73 | |||
| 74 | sub results { | ||
| 75 | return \%{shift->{results}}; | ||
| 76 | } | ||
| 77 | |||
| 78 | sub config { | ||
| 79 | my $self = shift; | ||
| 80 | return $self->{config}; | ||
| 81 | } | ||
| 82 | |||
| 83 | 1; | ||
| 84 | __END__ |