--- trunk/lib/WebPAC/Output/KinoSearch.pm 2007/10/30 21:57:36 917 +++ trunk/lib/WebPAC/Output/KinoSearch.pm 2007/10/31 12:29:57 939 @@ -7,6 +7,7 @@ __PACKAGE__->mk_accessors(qw( path database + input encoding clean @@ -25,11 +26,11 @@ =head1 VERSION -Version 0.04 +Version 0.05 =cut -our $VERSION = '0.04'; +our $VERSION = '0.05'; =head1 SYNOPSIS @@ -90,9 +91,16 @@ $self->encoding( 'ISO-8859-2' ) unless $self->encoding; + ## FIXME we shouldn't re-create whole KinoSearch index every time! + $self->clean( 1 ); + if ( ! -e $self->path ) { mkpath $self->path || $log->logdie("can't create ", $self->path,": $!"); $log->info("created ", $self->path); + } elsif ( $self->clean ) { + $log->info("removing existing ", $self->path); + rmtree $self->path || $log->logdie("can't remove ", $self->path,": $!"); + mkpath $self->path || $log->logdie("can't create ", $self->path,": $!"); } my $path = $self->path . '/' . $self->database; @@ -128,14 +136,26 @@ $log->logdie("need id") unless defined $id; $log->logdie("need ds") unless $ds; - $log->debug("id: $id ds = ",dump($ds)); + $log->debug("id: $id ds = ", sub { dump($ds) }); my $hash = $self->ds_to_hash( $ds, 'search' ) || return; - warn "add( $id, ",dump($ds)," ) => ", dump( $hash ); + $hash->{id} ||= $id; + $hash->{database} ||= $self->database; + $hash->{input} ||= $self->input; + + foreach my $f ( keys %$hash ) { + if ( ref($hash->{$f}) eq 'ARRAY' ) { + $hash->{$f} = join(' <*> ', @{ $hash->{$f} }); + } + } + + $log->debug("add( $id, ", sub { dump($ds) }," ) => ", sub { dump( $hash ) }); $self->index->add_doc( $hash ); + $self->{count}++; + return 1; } @@ -152,7 +172,7 @@ my $log = $self->_get_logger(); - $log->info("dummy finish"); + $log->info("indexed ", $self->{count}, " records"); }