/[Grep]/lib/Grep/Search.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/Grep/Search.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 131 by dpavlin, Tue May 1 10:47:23 2007 UTC revision 145 by dpavlin, Tue May 8 14:28:14 2007 UTC
# Line 3  package Grep::Search; Line 3  package Grep::Search;
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;
# Line 22  Grep::Search - full text search using L< Line 22  Grep::Search - full text search using L<
22    
23    my $search = Grep::Search->new();    my $search = Grep::Search->new();
24    
25      my $search = Grep::Search->new( create => 1 );
26    
27    =head2 invindexer
28    
29    Accessor to call any method defined on L<KinoSearch::InvIndexer>
30    
31      $search->invindexer->delete_by_term( 'id', 42 );
32    
33  =cut  =cut
34    
35  sub log { Jifty->web->log }  sub log { Jifty->web->log }
# Line 34  sub new { Line 42  sub new {
42    
43          $self->index_path( $index_path );          $self->index_path( $index_path );
44    
45          if (! -e "$index_path") {          if ( ! -e "$index_path" || $self->create ) {
46                  $self->log->debug("Creating new index $index_path");                  $self->log->debug("Creating new index $index_path");
47                  $self->invindexer( KinoSearch::InvIndexer->new( invindex => Grep::Search::Schema->clobber( $index_path ) ) );                  $self->invindexer( KinoSearch::InvIndexer->new( invindex => Grep::Search::Schema->clobber( $index_path ) ) );
48          } else {          } else {
# Line 117  sub add { Line 125  sub add {
125    
126  =head2 collection  =head2 collection
127    
128    Return C<Grep::Model::ItemCollection> which is result of C<search query>
129    
130    my $ItemCollection = $search->collection( 'search query' );    my $ItemCollection = $search->collection( 'search query' );
131    
132    =head2 hits
133    
134    Return number of results from last C<collection> call
135    
136      my $num_results = $search->hits;
137    
138  =cut  =cut
139    
140  sub collection {  sub collection {
# Line 139  sub collection { Line 155  sub collection {
155  #               num_wanted      => $hits_per_page,  #               num_wanted      => $hits_per_page,
156          );          );
157    
158          my $num_hits = $hits->total_hits;          $self->hits( $hits->total_hits );
159    
160          $self->log->debug("found $num_hits results");          $self->log->debug("found ", $self->hits, " results");
161    
162          my $collection = Grep::Model::ItemCollection->new();          my $collection = Grep::Model::ItemCollection->new();
163    
# Line 154  sub collection { Line 170  sub collection {
170                  my $title = $hit->{title};                  my $title = $hit->{title};
171                  my $id = $hit->{id};                  my $id = $hit->{id};
172    
173                  $self->log->debug("result $i $score $title");                  $self->log->debug("result $i [$id] $title $score");
174    
175                  my $item = Grep::Model::Item->new();                  my $item = Grep::Model::Item->new();
176                  my ($ok,$msg) = $item->load_by_cols( id => $id );                  my ($ok,$msg) = $item->load_by_cols( id => $id );
# Line 192  sub finish { Line 208  sub finish {
208          return;          return;
209  }  }
210    
 =cut  
   
211  =head2 snippet  =head2 snippet
212    
213    my $short = $self->snippet( 50, $text );    my $short = $self->snippet( 50, $text );
# Line 223  package Grep::Search::Schema; Line 237  package Grep::Search::Schema;
237    
238  =head1 NAME  =head1 NAME
239    
240  Grep::Search::Schema - data definition  Grep::Search::Schema - schema definition for full-text search
241    
242  =cut  =cut
243    

Legend:
Removed from v.131  
changed lines
  Added in v.145

  ViewVC Help
Powered by ViewVC 1.1.26