/[webpac2]/trunk/lib/WebPAC/Output/KinoSearch.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/WebPAC/Output/KinoSearch.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 437 by dpavlin, Sun Apr 30 19:06:09 2006 UTC revision 609 by dpavlin, Tue Aug 1 17:26:55 2006 UTC
# Line 9  use KinoSearch::InvIndexer; Line 9  use KinoSearch::InvIndexer;
9  use KinoSearch::Analysis::PolyAnalyzer;  use KinoSearch::Analysis::PolyAnalyzer;
10  use Encode qw/from_to/;  use Encode qw/from_to/;
11  use Data::Dumper;  use Data::Dumper;
12    use Storable;
13    
14  =head1 NAME  =head1 NAME
15    
# Line 16  WebPAC::Output::KinoSearch - Create Kino Line 17  WebPAC::Output::KinoSearch - Create Kino
17    
18  =head1 VERSION  =head1 VERSION
19    
20  Version 0.01  Version 0.03
21    
22  =cut  =cut
23    
24  our $VERSION = '0.01';  our $VERSION = '0.03';
25    
26  =head1 SYNOPSIS  =head1 SYNOPSIS
27    
# Line 89  sub new { Line 90  sub new {
90    
91          $self->{encoding} ||= 'ISO-8859-2';          $self->{encoding} ||= 'ISO-8859-2';
92    
93          $log->info("using index $self->{index_path} with encoding $self->{encoding}");          $self->{clean} = 1 if (! -e $self->{index_path} . '/segments');
94    
95            $log->info("using", $self->{clean} ? ' new' : '', " index $self->{index_path} with encoding $self->{encoding}");
96    
97          my $analyzer = KinoSearch::Analysis::PolyAnalyzer->new( language => 'en' );          my $analyzer = KinoSearch::Analysis::PolyAnalyzer->new( language => 'en' );
98    
# Line 99  sub new { Line 102  sub new {
102                  analyzer => $analyzer,                  analyzer => $analyzer,
103          );          );
104    
105            my $fields_path = $self->{index_path} . '/fields.storable';
106            $fields_path =~ s#//#/#g;
107            if (-e $fields_path) {
108                    $self->{fields} = retrieve($fields_path) ||
109                            $log->warn("can't open $fields_path: $!");
110            } else {
111                    $log->error("This will be dummy run since no fields statistics are found!");
112                    $log->error("You will have to re-run indexing to get search results!");
113                    $self->{dummy_run} = 1;
114            }
115            $self->{fields_path} = $fields_path;
116    
117          foreach my $f (@{ $self->{fields} }) {          foreach my $f (@{ $self->{fields} }) {
118                  $self->{invindex}->spec_field(                  $self->{invindex}->spec_field(
119                          name  => $f,                          name  => $f,
# Line 158  sub add { Line 173  sub add {
173          sub add_value($$$$$) {          sub add_value($$$$$) {
174                  my ($self,$log,$doc,$n,$v) = @_;                  my ($self,$log,$doc,$n,$v) = @_;
175                  return unless ($v);                  return unless ($v);
176    
177                    $self->{value_usage}->{$n}++;
178                    return if ($self->{dummy_run});
179    
180                  eval { $doc->set_value($n, $self->convert($v) ) };                  eval { $doc->set_value($n, $self->convert($v) ) };
181                  $log->warn("can't insert: $n = $v") if ($@);                  $log->warn("can't insert: $n = $v") if ($@);
182          }          }
# Line 208  Close index Line 227  Close index
227  sub finish {  sub finish {
228          my $self = shift;          my $self = shift;
229    
230          $self->_get_logger()->info("finish index writing to disk");          my $log = $self->_get_logger();
231    
232            $log->info("finish index writing to disk");
233          $self->{invindex}->finish;          $self->{invindex}->finish;
234    
235            $log->info("writing value usage file");
236    
237            # add fields from last run
238            map { $self->{value_usage}->{$_}++ } @{ $self->{fields} };
239    
240            my @fields = keys %{ $self->{value_usage} };
241            store \@fields, $self->{fields_path} ||
242                    $log->warn("can't write $self->{fields_path}: $!");
243    
244  }  }
245    
246  =head2 convert  =head2 convert

Legend:
Removed from v.437  
changed lines
  Added in v.609

  ViewVC Help
Powered by ViewVC 1.1.26