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 ) ); |
Grep::Search->mk_accessors( qw( invindexer create index_path hits ) ); |
7 |
|
|
8 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
9 |
use KinoSearch::InvIndexer; |
use KinoSearch::InvIndexer; |
22 |
|
|
23 |
my $search = Grep::Search->new(); |
my $search = Grep::Search->new(); |
24 |
|
|
25 |
|
my $serach = Grep::Search->new( create => 1 ); |
26 |
|
|
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") { |
if ( ! -e "$index_path" || $self->create ) { |
40 |
$self->log->debug("Creating new index $index_path"); |
$self->log->debug("Creating new index $index_path"); |
41 |
$self->invindexer( KinoSearch::InvIndexer->new( invindex => Grep::Search::Schema->clobber( $index_path ) ) ); |
$self->invindexer( KinoSearch::InvIndexer->new( invindex => Grep::Search::Schema->clobber( $index_path ) ) ); |
42 |
} else { |
} else { |
119 |
|
|
120 |
=head2 collection |
=head2 collection |
121 |
|
|
122 |
|
Return C<Grep::Model::ItemCollection> which is result of C<search query> |
123 |
|
|
124 |
my $ItemCollection = $search->collection( 'search query' ); |
my $ItemCollection = $search->collection( 'search query' ); |
125 |
|
|
126 |
|
=head2 hits |
127 |
|
|
128 |
|
Return number of results from last C<collection> call |
129 |
|
|
130 |
|
my $num_results = $search->hits; |
131 |
|
|
132 |
=cut |
=cut |
133 |
|
|
134 |
sub collection { |
sub collection { |
149 |
# num_wanted => $hits_per_page, |
# num_wanted => $hits_per_page, |
150 |
); |
); |
151 |
|
|
152 |
my $num_hits = $hits->total_hits; |
$self->hits( $hits->total_hits ); |
153 |
|
|
154 |
$self->log->debug("found $num_hits results"); |
$self->log->debug("found ", $self->hits, " results"); |
155 |
|
|
156 |
my $collection = Grep::Model::ItemCollection->new(); |
my $collection = Grep::Model::ItemCollection->new(); |
157 |
|
|
164 |
my $title = $hit->{title}; |
my $title = $hit->{title}; |
165 |
my $id = $hit->{id}; |
my $id = $hit->{id}; |
166 |
|
|
167 |
$self->log->debug("result $i $score $title"); |
$self->log->debug("result $i [$id] $title $score"); |
168 |
|
|
169 |
my $item = Grep::Model::Item->new(); |
my $item = Grep::Model::Item->new(); |
170 |
my ($ok,$msg) = $item->load_by_cols( id => $id ); |
my ($ok,$msg) = $item->load_by_cols( id => $id ); |
202 |
return; |
return; |
203 |
} |
} |
204 |
|
|
|
=cut |
|
|
|
|
205 |
=head2 snippet |
=head2 snippet |
206 |
|
|
207 |
my $short = $self->snippet( 50, $text ); |
my $short = $self->snippet( 50, $text ); |
231 |
|
|
232 |
=head1 NAME |
=head1 NAME |
233 |
|
|
234 |
Grep::Search::Schema - data definition |
Grep::Search::Schema - schema definition for full-text search |
235 |
|
|
236 |
=cut |
=cut |
237 |
|
|
238 |
use base 'KinoSearch::Schema'; |
use base 'KinoSearch::Schema'; |
239 |
use KinoSearch::Analysis::PolyAnalyzer; |
use KinoSearch::Analysis::PolyAnalyzer; |
240 |
|
|
241 |
our %FIELDS = ( |
our %fields = ( |
242 |
id => 'Grep::Search::KeywordField', |
id => 'Grep::Search::KeywordField', |
243 |
|
|
244 |
in_feed_id => 'Grep::Search::KeywordField', |
in_feed_id => 'Grep::Search::KeywordField', |