1 package WebPAC::Output::KinoSearch;
6 use base qw/WebPAC::Common WebPAC::Output Class::Accessor/;
7 __PACKAGE__->mk_accessors(qw(
17 use KinoSearch::Simple;
19 use Encode qw/from_to/;
20 use Data::Dump qw/dump/;
25 WebPAC::Output::KinoSearch - Create KinoSearch full text index
33 our $VERSION = '0.05';
37 Create full text index using KinoSearch index from data with
46 my $out = new WebPAC::Output::KinoSearch({
47 path => '/path/to/invindex',
49 encoding => 'iso-8859-2',
59 path to KinoSearch index to use
63 name of database from which data comes
67 character encoding of C<data_structure> if it's differenet than C<ISO-8859-2>
68 (and it probably is). This encoding will be converted to C<UTF-8> for
82 my $log = $self->_get_logger;
84 #$log->debug("self: ", sub { dump($self) });
86 foreach my $p (qw/path database/) {
87 $log->logdie("need $p") unless ($self->$p);
90 # $log->logdie("fields is not ARRAY") unless (ref($self->{fields}) eq 'ARRAY');
92 $self->encoding( 'ISO-8859-2' ) unless $self->encoding;
94 ## FIXME we shouldn't re-create whole KinoSearch index every time!
97 if ( ! -e $self->path ) {
98 mkpath $self->path || $log->logdie("can't create ", $self->path,": $!");
99 $log->info("created ", $self->path);
100 } elsif ( $self->clean ) {
101 $log->info("removing existing ", $self->path);
102 rmtree $self->path || $log->logdie("can't remove ", $self->path,": $!");
103 mkpath $self->path || $log->logdie("can't create ", $self->path,": $!");
106 my $path = $self->path . '/' . $self->database;
108 $log->info("using index $path with encoding ", $self->encoding);
110 my $index = KinoSearch::Simple->new(
115 $log->logdie("can't open $path: $!") unless $index;
117 $self->index( $index );
126 $out->add( 42, $ds );
133 my ( $id, $ds ) = @_;
135 my $log = $self->_get_logger;
136 $log->logdie("need id") unless defined $id;
137 $log->logdie("need ds") unless $ds;
139 $log->debug("id: $id ds = ", sub { dump($ds) });
141 my $hash = $self->ds_to_hash( $ds, 'search' ) || return;
144 $hash->{database} ||= $self->database;
145 $hash->{input} ||= $self->input;
147 foreach my $f ( keys %$hash ) {
148 if ( ref($hash->{$f}) eq 'ARRAY' ) {
149 $hash->{$f} = join(' <*> ', @{ $hash->{$f} });
153 $log->debug("add( $id, ", sub { dump($ds) }," ) => ", sub { dump( $hash ) });
155 $self->index->add_doc( $hash );
173 my $log = $self->_get_logger();
175 $log->info("indexed ", $self->{count}, " records");
181 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
183 =head1 COPYRIGHT & LICENSE
185 Copyright 2005-2007 Dobrica Pavlinusic, All Rights Reserved.
187 This program is free software; you can redistribute it and/or modify it
188 under the same terms as Perl itself.
192 1; # End of WebPAC::Output::Estraier