--- trunk/lib/WebPAC/Output/KinoSearch.pm 2006/04/30 19:06:09 437 +++ trunk/lib/WebPAC/Output/KinoSearch.pm 2006/06/26 16:39:51 536 @@ -9,6 +9,7 @@ use KinoSearch::Analysis::PolyAnalyzer; use Encode qw/from_to/; use Data::Dumper; +use Storable; =head1 NAME @@ -16,11 +17,11 @@ =head1 VERSION -Version 0.01 +Version 0.02 =cut -our $VERSION = '0.01'; +our $VERSION = '0.02'; =head1 SYNOPSIS @@ -99,6 +100,18 @@ analyzer => $analyzer, ); + my $fields_path = $self->{index_path} . '/fields.storable'; + $fields_path =~ s#//#/#g; + if (-e $fields_path) { + $self->{fields} = retrieve($fields_path) || + $log->warn("can't open $fields_path: $!"); + } else { + $log->error("This will be dummy run since no fields statistics are found!"); + $log->error("You will have to re-run indexing to get search results!"); + $self->{dummy_run} = 1; + } + $self->{fields_path} = $fields_path; + foreach my $f (@{ $self->{fields} }) { $self->{invindex}->spec_field( name => $f, @@ -158,6 +171,10 @@ sub add_value($$$$$) { my ($self,$log,$doc,$n,$v) = @_; return unless ($v); + + $self->{value_usage}->{$n}++; + return if ($self->{dummy_run}); + eval { $doc->set_value($n, $self->convert($v) ) }; $log->warn("can't insert: $n = $v") if ($@); } @@ -208,8 +225,20 @@ sub finish { my $self = shift; - $self->_get_logger()->info("finish index writing to disk"); + my $log = $self->_get_logger(); + + $log->info("finish index writing to disk"); $self->{invindex}->finish; + + $log->info("writing value usage file"); + + # add fields from last run + map { $self->{value_usage}->{$_}++ } @{ $self->{fields} }; + + my @fields = keys %{ $self->{value_usage} }; + store \@fields, $self->{fields_path} || + $log->warn("can't write $self->{fields_path}: $!"); + } =head2 convert