supprot \x42 HEX numbers in recode
[webpac2] / lib / WebPAC / Output / KinoSearch.pm
index e194f4e..8034a83 100644 (file)
@@ -7,6 +7,7 @@ use base qw/WebPAC::Common WebPAC::Output Class::Accessor/;
 __PACKAGE__->mk_accessors(qw(
        path
        database
+       input
        encoding
        clean
 
@@ -15,7 +16,7 @@ __PACKAGE__->mk_accessors(qw(
 
 use KinoSearch::Simple;
 use File::Path;
-use Encode qw/from_to/;
+use Encode qw/decode/;
 use Data::Dump qw/dump/;
 use Storable;
 
@@ -90,6 +91,9 @@ sub init {
 
        $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);
@@ -132,12 +136,19 @@ sub add {
        $log->logdie("need id") unless defined $id;
        $log->logdie("need ds") unless $ds;
 
-       $log->debug("id: $id ds = ",dump($ds));
-
        my $hash = $self->ds_to_hash( $ds, 'search' ) || return;
 
+       $hash->{id}       ||= $id;
        $hash->{database} ||= $self->database;
-       $hash->{id} ||= $id;
+       $hash->{input}    ||= $self->input;
+
+       foreach my $f ( keys %$hash ) {
+               if ( ref($hash->{$f}) eq 'ARRAY' ) {
+                       $hash->{$f} = join(' <*> ', @{ $hash->{$f} });
+               }
+#              $hash->{$f} = decode( $self->encoding, $hash->{$f} );
+               $self->{field_count}->{$f}++;
+       }
 
        $log->debug("add( $id, ", sub { dump($ds) }," ) => ", sub { dump( $hash ) });
 
@@ -163,6 +174,8 @@ sub finish {
 
        $log->info("indexed ", $self->{count}, " records");
 
+       $log->debug("field usage: ", dump( $self->{field_count} ));
+
 }
 
 =head1 AUTHOR