| 1 | package CGI::Wiki::Plugin::Indexer; |
|---|
| 2 | use strict; |
|---|
| 3 | use CGI::Wiki::Plugin; |
|---|
| 4 | use Data::Dumper; |
|---|
| 5 | |
|---|
| 6 | use vars qw( $VERSION @ISA ); |
|---|
| 7 | $VERSION = '0.02'; |
|---|
| 8 | @ISA = qw( CGI::Wiki::Plugin ); |
|---|
| 9 | |
|---|
| 10 | sub new { |
|---|
| 11 | my $class = shift; |
|---|
| 12 | my $self = {}; |
|---|
| 13 | bless $self, $class; |
|---|
| 14 | return $self; |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | sub reindex { |
|---|
| 18 | my ($self, $node, $content, $metadata) = @_; |
|---|
| 19 | my $search = $self->indexer; |
|---|
| 20 | my %metadata = %{ $metadata }; |
|---|
| 21 | my $indexText = $content . "\n"; |
|---|
| 22 | foreach my $key ( qw( phone address city postcode website fax summary ) ) { |
|---|
| 23 | $indexText .= $metadata{$key} . "\n"; |
|---|
| 24 | } |
|---|
| 25 | foreach my $text (@{ $metadata{category}}) { |
|---|
| 26 | if ($text) { |
|---|
| 27 | $indexText .= $text . "\n"; |
|---|
| 28 | } |
|---|
| 29 | } |
|---|
| 30 | foreach my $text (@{ $metadata{locale}}) { |
|---|
| 31 | if ($text) { |
|---|
| 32 | $indexText .= $text . "\n"; |
|---|
| 33 | } |
|---|
| 34 | } |
|---|
| 35 | $search->index_node($node, $indexText); |
|---|
| 36 | return 1; |
|---|
| 37 | } |
|---|
| 38 | 1; |
|---|