File Coverage

blib/lib/Kwiki/Search/Plucene.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Kwiki::Search::Plucene;
2 1     1   1393 use Kwiki::Search -Base;
  0            
  0            
3             use Plucene::Simple;
4             our $VERSION = '0.03';
5              
6             field plucy => {},
7             -init => q{Plucene::Simple->open($self->index_path)};
8              
9             sub register {
10             super;
11             my $reg = shift;
12             $reg->add(hook => 'page:store', post => 'update_index');
13             $self->build_index;
14             }
15              
16             sub build_index {
17             my $cmd = $self->hub->command;
18             $cmd->msg("Building Plucene Index...\n");
19             for($self->hub->pages->all) {
20             $cmd->msg(" - Indexing " . $_->id . "\n");
21             $self->update_page($_);
22             }
23             $self->plucy->optimize;
24             $cmd->msg("Done\n");
25             }
26              
27             sub perform_search {
28             [map {$self->pages->new_page($_)} $self->plucy->search($self->cgi->search_term)]
29             }
30              
31             sub index_path {
32             $self->plugin_directory . '/plucene_index';
33             }
34              
35             sub update_index {
36             $self->hub->load_class('search')->update_page($self);
37             }
38              
39             sub update_page {
40             my $page = shift;
41             $self->plucy->delete_document($page->id,$page->content)
42             if(-d $self->index_path);
43             $self->plucy->index_document($page->id,$page->content);
44             }
45              
46             =head1 NAME
47              
48             Kwiki::Search::Plucene - Plucene powered Kwiki search engine
49              
50             =head1 DESCRIPTION
51              
52             This plugin is intend to be an alternative of Kwiki::Search, which use
53             a simple 'grep' upon search, and will be slow after the number of
54             pages grow larger and larger.
55              
56             It use L to index page content upon saving. Plucene is
57             a Perl port of the Lucene search engine.
58              
59             Note that, by each time you do a C<"kwiki -update">, plucene index
60             will be rebuilt. This would help current running sites to build
61             plucene index for the very first time.
62              
63             =head1 SEE ALSO
64              
65             L, L, L
66              
67             =head1 COPYRIGHT
68              
69             Copyright 2005 by Kang-min Liu .
70              
71             This program is free software; you can redistribute it and/or
72             modify it under the same terms as Perl itself.
73              
74             See
75              
76             =cut