3 |
use strict; |
use strict; |
4 |
use warnings; |
use warnings; |
5 |
use base qw( Class::Accessor ); |
use base qw( Class::Accessor ); |
6 |
Grep::Search->mk_accessors( qw( invindexer create index_path hits ) ); |
Grep::Search->mk_accessors( qw( create index_path hits ) ); |
7 |
|
|
8 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
9 |
use KinoSearch::InvIndexer; |
use KinoSearch::InvIndexer; |
10 |
use KinoSearch::Searcher; |
use KinoSearch::Searcher; |
11 |
use Jifty::Util; |
use Jifty::Util; |
12 |
|
|
13 |
my $debug = 0; |
my $debug = 1; |
14 |
|
|
15 |
=head1 NAME |
=head1 NAME |
16 |
|
|
24 |
|
|
25 |
my $search = Grep::Search->new( create => 1 ); |
my $search = Grep::Search->new( create => 1 ); |
26 |
|
|
|
=head2 invindexer |
|
|
|
|
|
Accessor to call any method defined on L<KinoSearch::InvIndexer> |
|
|
|
|
|
$search->invindexer->delete_by_term( 'id', 42 ); |
|
|
|
|
27 |
=cut |
=cut |
28 |
|
|
29 |
sub log { Jifty->web->log } |
sub log { Jifty->web->log } |
36 |
|
|
37 |
$self->index_path( $index_path ); |
$self->index_path( $index_path ); |
38 |
|
|
39 |
if ( ! -e "$index_path" || $self->create ) { |
return $self; |
40 |
$self->log->debug("Creating new index $index_path"); |
} |
41 |
$self->invindexer( KinoSearch::InvIndexer->new( invindex => Grep::Search::Schema->clobber( $index_path ) ) ); |
|
42 |
|
=head2 invindexer |
43 |
|
|
44 |
|
Accessor to call any method defined on L<KinoSearch::InvIndexer> |
45 |
|
|
46 |
|
$search->invindexer->delete_by_term( 'id', 42 ); |
47 |
|
|
48 |
|
=cut |
49 |
|
|
50 |
|
my $indexes; |
51 |
|
|
52 |
|
sub invindexer { |
53 |
|
my $self = shift; |
54 |
|
my $invindexer; |
55 |
|
my $index_path = $self->index_path or die "no index_path?"; |
56 |
|
|
57 |
|
if ( $invindexer = $indexes->{$index_path} ) { |
58 |
|
$self->log->debug("Using cached index $index_path"); |
59 |
} else { |
} else { |
60 |
$self->log->debug("Opening index: $index_path"); |
if ( ! -e "$index_path" || $self->create ) { |
61 |
$self->invindexer( KinoSearch::InvIndexer->new( invindex => Grep::Search::Schema->open( $index_path ) ) ); |
$self->log->debug("Creating new index $index_path"); |
62 |
|
my $invindexer = KinoSearch::InvIndexer->new( invindex => Grep::Search::Schema->clobber( $index_path ) ); |
63 |
|
} else { |
64 |
|
$self->log->debug("Opening index: $index_path"); |
65 |
|
$invindexer = KinoSearch::InvIndexer->new( invindex => Grep::Search::Schema->open( $index_path ) ); |
66 |
|
} |
67 |
|
$indexes->{$index_path} = $invindexer; |
68 |
} |
} |
69 |
|
|
70 |
return $self; |
$self->invindexer( $invindexer ); |
71 |
|
|
72 |
} |
} |
73 |
|
|
74 |
=head2 add |
=head2 add |