7 |
__PACKAGE__->mk_accessors(qw( |
__PACKAGE__->mk_accessors(qw( |
8 |
path |
path |
9 |
database |
database |
10 |
|
input |
11 |
encoding |
encoding |
12 |
clean |
clean |
13 |
|
|
16 |
|
|
17 |
use KinoSearch::Simple; |
use KinoSearch::Simple; |
18 |
use File::Path; |
use File::Path; |
19 |
use Encode qw/from_to/; |
use Encode qw/decode/; |
20 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
21 |
use Storable; |
use Storable; |
22 |
|
|
26 |
|
|
27 |
=head1 VERSION |
=head1 VERSION |
28 |
|
|
29 |
Version 0.04 |
Version 0.05 |
30 |
|
|
31 |
=cut |
=cut |
32 |
|
|
33 |
our $VERSION = '0.04'; |
our $VERSION = '0.05'; |
34 |
|
|
35 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
36 |
|
|
91 |
|
|
92 |
$self->encoding( 'ISO-8859-2' ) unless $self->encoding; |
$self->encoding( 'ISO-8859-2' ) unless $self->encoding; |
93 |
|
|
94 |
|
## FIXME we shouldn't re-create whole KinoSearch index every time! |
95 |
|
$self->clean( 1 ); |
96 |
|
|
97 |
if ( ! -e $self->path ) { |
if ( ! -e $self->path ) { |
98 |
mkpath $self->path || $log->logdie("can't create ", $self->path,": $!"); |
mkpath $self->path || $log->logdie("can't create ", $self->path,": $!"); |
99 |
$log->info("created ", $self->path); |
$log->info("created ", $self->path); |
100 |
|
} elsif ( $self->clean ) { |
101 |
|
$log->info("removing existing ", $self->path); |
102 |
|
rmtree $self->path || $log->logdie("can't remove ", $self->path,": $!"); |
103 |
|
mkpath $self->path || $log->logdie("can't create ", $self->path,": $!"); |
104 |
} |
} |
105 |
|
|
106 |
my $path = $self->path . '/' . $self->database; |
my $path = $self->path . '/' . $self->database; |
136 |
$log->logdie("need id") unless defined $id; |
$log->logdie("need id") unless defined $id; |
137 |
$log->logdie("need ds") unless $ds; |
$log->logdie("need ds") unless $ds; |
138 |
|
|
139 |
$log->debug("id: $id ds = ",dump($ds)); |
$log->debug("id: $id ds = ", sub { dump($ds) }); |
140 |
|
|
141 |
my $hash = $self->ds_to_hash( $ds, 'search' ) || return; |
my $hash = $self->ds_to_hash( $ds, 'search' ) || return; |
142 |
|
|
143 |
warn "add( $id, ",dump($ds)," ) => ", dump( $hash ); |
$hash->{id} ||= $id; |
144 |
|
$hash->{database} ||= $self->database; |
145 |
|
$hash->{input} ||= $self->input; |
146 |
|
|
147 |
|
foreach my $f ( keys %$hash ) { |
148 |
|
if ( ref($hash->{$f}) eq 'ARRAY' ) { |
149 |
|
$hash->{$f} = join(' <*> ', @{ $hash->{$f} }); |
150 |
|
} |
151 |
|
# $hash->{$f} = decode( $self->encoding, $hash->{$f} ); |
152 |
|
} |
153 |
|
|
154 |
|
$log->debug("add( $id, ", sub { dump($ds) }," ) => ", sub { dump( $hash ) }); |
155 |
|
|
156 |
$self->index->add_doc( $hash ); |
$self->index->add_doc( $hash ); |
157 |
|
|
158 |
|
$self->{count}++; |
159 |
|
|
160 |
return 1; |
return 1; |
161 |
} |
} |
162 |
|
|
173 |
|
|
174 |
my $log = $self->_get_logger(); |
my $log = $self->_get_logger(); |
175 |
|
|
176 |
$log->info("dummy finish"); |
$log->info("indexed ", $self->{count}, " records"); |
177 |
|
|
178 |
} |
} |
179 |
|
|