[cgi-wiki-dev] Search module for Plucene

Simon Cozens cgi-wiki-dev@earth.li
Mon, 23 Feb 2004 17:51:32 +0000


--J/dobhs11T7y2rNN
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

This is untested, and depends on the earlier patch to abstract out
searching.

-- 
I hooked up my accelerator pedal in my car to my brake lights.  I hit the gas,
people behind me stop, and I'm gone.  -- Steven Wright

--J/dobhs11T7y2rNN
Content-Type: application/x-perl
Content-Disposition: attachment; filename="Plucene.pm"
Content-Transfer-Encoding: quoted-printable

package CGI::Wiki::Search::Plucene;=0A=0Ause strict;=0Ause Search::Inverted=
Index;=0Ause Carp "croak";=0Ause Plucene::Simple;=0A=0Ause vars qw( @ISA $V=
ERSION );=0A=0A$VERSION =3D 0.08;=0Ause base 'CGI::Wiki::Search::Base';=0A=
=0A=3Dhead1 NAME=0A=0ACGI::Wiki::Search::Plucene - Search::InvertedIndex pl=
ugin for CGI::Wiki=0A=0A=3Dhead1 SYNOPSIS=0A=0A  my $indexdb =3D Search::In=
vertedIndex::DB::Mysql->new( ... );=0A  my $search =3D CGI::Wiki::Search::P=
lucene->new( indexdb =3D> $indexdb );=0A  my %wombat_nodes =3D $search->sea=
rch_nodes("wombat");=0A=0AProvides search-related methods for CGI::Wiki=0A=
=0ASee also L<CGI::Wiki::Base>=0A=0A=3Dcut=0A=0A=3Dhead1 METHODS=0A=0A=3Dov=
er 4=0A=0A=3Ditem B<new>=0A=0A  my $search =3D CGI::Wiki::Search::Plucene->=
new( path =3D> "/var/plucene/wiki" );=0A=0ATakes only one parameter, which =
is mandatory. C<path> must be a path to=0Astore the index.=0A=0A=3Dcut=0A=
=0Asub _init {=0A    my ($self, %args) =3D @_;=0A    $self->{plucene} =3D P=
lucene::Simple->open($args{path});=0A}=0A=0Asub search_nodes {=0A    my ($s=
elf, $query, $and_or) =3D @_;=0A    local $Plucene::QueryParser::DefaultOpe=
rator =3D "AND" if $and_or eq "and";=0A    my $i =3D 1;=0A    return map { =
$_ =3D> $i++ } $self->{plucene}->search($query);=0A}=0A=0Asub _fuzzy_match =
{=0A    my ($self, $string, $canonical) =3D @_;=0A    return map { $_ =3D> =
($_ eq $string ? 2 : 1) } =0A           $self->{plucene}->search("fuzzy:$ca=
nonical");=0A}=0A=0Asub index_node {=0A    my ($self, $node, $content) =3D =
@_;=0A    $self->{plucene}->add(=0A        $node =3D> { content =3D> $conte=
nt,=0A                   fuzzy   =3D> $self->canonicalise_title( $node ),=
=0A                   title   =3D> $node,=0A                 }=0A    );=0A}=
=0A=0Asub _delete_node {=0A    my ($self, $node) =3D @_;=0A    $self->{pluc=
ene}->delete( $node );=0A}=0A=0Asub supports_phrase_searches { return 1; }=
=0Asub supports_fuzzy_searches  { return 1; }=0A=0A=3Dback=0A=0A=3Dhead1 SE=
E ALSO=0A=0AL<CGI::Wiki>, L<CGI::Wiki::Base>=0A=0A=3Dcut=0A=0A1;=0A
--J/dobhs11T7y2rNN--