r1322@llin: dpavlin | 2007-09-03 16:44:01 +0200
[webpac2] / lib / WebPAC / Output / KinoSearch.pm
index 6c50ac3..2c03ec6 100644 (file)
@@ -8,7 +8,7 @@ use base qw/WebPAC::Common/;
 use KinoSearch::InvIndexer;
 use KinoSearch::Analysis::PolyAnalyzer;
 use Encode qw/from_to/;
-use Data::Dumper;
+use Data::Dump qw/dump/;
 use Storable;
 
 =head1 NAME
@@ -17,11 +17,11 @@ WebPAC::Output::KinoSearch - Create KinoSearch full text index
 
 =head1 VERSION
 
-Version 0.02
+Version 0.03
 
 =cut
 
-our $VERSION = '0.02';
+our $VERSION = '0.03';
 
 =head1 SYNOPSIS
 
@@ -80,7 +80,7 @@ sub new {
 
        my $log = $self->_get_logger;
 
-       #$log->debug("self: ", sub { Dumper($self) });
+       #$log->debug("self: ", sub { dump($self) });
 
        foreach my $p (qw/index_path fields database/) {
                $log->logdie("need $p") unless ($self->{$p});
@@ -90,7 +90,11 @@ sub new {
 
        $self->{encoding} ||= 'ISO-8859-2';
 
-       $log->info("using index $self->{index_path} with encoding $self->{encoding}");
+       $self->{index_path} .= '/' . $self->{database};
+
+       $self->{clean} = 1 if (! -e $self->{index_path} . '/segments');
+
+       $log->info("using", $self->{clean} ? ' new' : '', " index $self->{index_path} with encoding $self->{encoding}");
 
        my $analyzer = KinoSearch::Analysis::PolyAnalyzer->new( language => 'en' );
 
@@ -168,7 +172,7 @@ sub add {
 
        my $doc = $self->{invindex}->new_doc( $uri ) || $log->logdie("can't create new_doc( $uri )");
 
-       sub add_value($$$$$) {
+       sub _add_value($$$$$) {
                my ($self,$log,$doc,$n,$v) = @_;
                return unless ($v);
 
@@ -179,9 +183,9 @@ sub add {
                $log->warn("can't insert: $n = $v") if ($@);
        }
 
-       add_value($self,$log,$doc, 'uri', $uri);
+       _add_value($self,$log,$doc, 'uri', $uri);
 
-       $log->debug("ds = ", sub { Dumper($args->{'ds'}) } );
+       $log->debug("ds = ", sub { dump($args->{'ds'}) } );
 
        # filter all tags which have type defined
        my @tags = grep {
@@ -201,11 +205,11 @@ sub add {
                $vals = $self->convert( $vals ) or
                        $log->logdie("can't convert '$vals' to UTF-8");
 
-               add_value($self, $log, $doc, $tag, $vals );
+               _add_value($self, $log, $doc, $tag, $vals );
        }
 
        if (my $text = $args->{'text'}) {
-               add_value($self, $log, $doc, 'bodytext', $text );
+               _add_value($self, $log, $doc, 'bodytext', $text );
        }
 
        #$log->debug("adding ", sub { $doc->dump_draft } );