1 package WebPAC::Output::KinoSearch;
6 use base qw/WebPAC::Common WebPAC::Output Class::Accessor/;
7 __PACKAGE__->mk_accessors(qw(
16 use KinoSearch::Simple;
18 use Encode qw/from_to/;
19 use Data::Dump qw/dump/;
24 WebPAC::Output::KinoSearch - Create KinoSearch full text index
32 our $VERSION = '0.05';
36 Create full text index using KinoSearch index from data with
45 my $out = new WebPAC::Output::KinoSearch({
46 path => '/path/to/invindex',
48 encoding => 'iso-8859-2',
58 path to KinoSearch index to use
62 name of database from which data comes
66 character encoding of C<data_structure> if it's differenet than C<ISO-8859-2>
67 (and it probably is). This encoding will be converted to C<UTF-8> for
81 my $log = $self->_get_logger;
83 #$log->debug("self: ", sub { dump($self) });
85 foreach my $p (qw/path database/) {
86 $log->logdie("need $p") unless ($self->$p);
89 # $log->logdie("fields is not ARRAY") unless (ref($self->{fields}) eq 'ARRAY');
91 $self->encoding( 'ISO-8859-2' ) unless $self->encoding;
93 if ( ! -e $self->path ) {
94 mkpath $self->path || $log->logdie("can't create ", $self->path,": $!");
95 $log->info("created ", $self->path);
96 } elsif ( $self->clean ) {
97 $log->info("removing existing ", $self->path);
98 rmtree $self->path || $log->logdie("can't remove ", $self->path,": $!");
99 mkpath $self->path || $log->logdie("can't create ", $self->path,": $!");
102 my $path = $self->path . '/' . $self->database;
104 $log->info("using index $path with encoding ", $self->encoding);
106 my $index = KinoSearch::Simple->new(
111 $log->logdie("can't open $path: $!") unless $index;
113 $self->index( $index );
122 $out->add( 42, $ds );
129 my ( $id, $ds ) = @_;
131 my $log = $self->_get_logger;
132 $log->logdie("need id") unless defined $id;
133 $log->logdie("need ds") unless $ds;
135 $log->debug("id: $id ds = ",dump($ds));
137 my $hash = $self->ds_to_hash( $ds, 'search' ) || return;
139 $hash->{database} ||= $self->database;
142 $log->debug("add( $id, ", sub { dump($ds) }," ) => ", sub { dump( $hash ) });
144 $self->index->add_doc( $hash );
160 my $log = $self->_get_logger();
162 $log->info("dummy finish");
168 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
170 =head1 COPYRIGHT & LICENSE
172 Copyright 2005-2007 Dobrica Pavlinusic, All Rights Reserved.
174 This program is free software; you can redistribute it and/or modify it
175 under the same terms as Perl itself.
179 1; # End of WebPAC::Output::Estraier