r1383@llin: dpavlin | 2007-10-30 23:07:09 +0100
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 30 Oct 2007 22:07:11 +0000 (22:07 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 30 Oct 2007 22:07:11 +0000 (22:07 +0000)
 added clean to start with empty index

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@919 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Output/KinoSearch.pm
t/5-output-kinosearch.t

index 98a200d..8129e94 100644 (file)
@@ -25,11 +25,11 @@ WebPAC::Output::KinoSearch - Create KinoSearch full text index
 
 =head1 VERSION
 
-Version 0.04
+Version 0.05
 
 =cut
 
-our $VERSION = '0.04';
+our $VERSION = '0.05';
 
 =head1 SYNOPSIS
 
@@ -93,6 +93,10 @@ sub init {
        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;
@@ -132,7 +136,10 @@ sub add {
 
        my $hash = $self->ds_to_hash( $ds, 'search' ) || return;
 
-       warn "add( $id, ",dump($ds)," ) => ", dump( $hash );
+       $hash->{database} ||= $self->database;
+       $hash->{id} ||= $id;
+
+       $log->debug("add( $id, ", sub { dump($ds) }," ) => ", sub { dump( $hash ) });
 
        $self->index->add_doc( $hash );
 
index 03fb846..a613ebc 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-use Test::More tests => 14;
+use Test::More tests => 20;
 use Test::Exception;
 use Cwd qw/abs_path/;
 use KinoSearch;
@@ -23,6 +23,8 @@ my $path = "$abs_path/kino/";
 ok(my $out = new WebPAC::Output::KinoSearch({
        path => $path,
        database => 'test',
+       clean => 1,
+       debug => $debug,
 }), "new");
 
 ok( $out->init, 'init' );
@@ -66,6 +68,7 @@ my $total_hits = $index->search(
                                                                                                                   
 diag "Total hits: $total_hits\n";
 while ( my $hit = $index->fetch_hit_hashref ) {
+       ok( $hit, 'hit' );
        diag dump($hit);
 }