/[webpac2]/trunk/lib/WebPAC/Search/Estraier.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 /trunk/lib/WebPAC/Search/Estraier.pm

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

revision 152 by dpavlin, Sat Nov 26 01:38:28 2005 UTC revision 211 by dpavlin, Mon Dec 5 17:47:10 2005 UTC
# Line 13  WebPAC::Search::Estraier - search Hyper Line 13  WebPAC::Search::Estraier - search Hyper
13    
14  =head1 VERSION  =head1 VERSION
15    
16  Version 0.02  Version 0.04
17    
18  =cut  =cut
19    
20  our $VERSION = '0.02';  our $VERSION = '0.04';
21    
22  =head1 SYNOPSIS  =head1 SYNOPSIS
23    
# Line 31  L<WebPAC::Output::Estraier>. Line 31  L<WebPAC::Output::Estraier>.
31  Connect to Hyper Estraier index using HTTP  Connect to Hyper Estraier index using HTTP
32    
33   my $est = new WebPAC::Search::Estraier(   my $est = new WebPAC::Search::Estraier(
34          url => 'http://localhost:1978/node/webpac2',          masterurl => 'http://localhost:1978/',
35            database => 'webpac2',
36          user => 'admin',          user => 'admin',
37          passwd => 'admin',          passwd => 'admin',
38          encoding => 'iso-8859-2',          encoding => 'iso-8859-2',
# Line 42  Options are: Line 43  Options are:
43    
44  =over 4  =over 4
45    
46  =item url  =item maseterurl
47    
48  URI to C<estmaster> node  URI to C<estmaster> node
49    
50    =item database
51    
52    name of C<estmaster> node
53    
54  =item user  =item user
55    
56  C<estmaster> user with read rights  C<estmaster> user with read rights
# Line 76  sub new { Line 81  sub new {
81    
82          my $log = $self->_get_logger;          my $log = $self->_get_logger;
83    
84          foreach my $p (qw/url user passwd/) {          foreach my $p (qw/masterurl user passwd/) {
85                  $log->logdie("need $p") unless ($self->{$p});                  $log->logdie("need $p") unless ($self->{$p});
86          }          }
87    
88            my $url = $self->{masterurl} . '/node/' . $self->{database};
89            $url =~ s#//#/#g;
90            $self->{url} = $url;
91    
92          $log->info("opening Hyper Estraier index $self->{'url'} as $self->{'user'}");          $log->info("opening Hyper Estraier index $self->{'url'} as $self->{'user'}");
93    
94          $self->{'db'} = HyperEstraier::Node->new($self->{'url'});          $self->{'db'} = HyperEstraier::Node->new($self->{'url'});
# Line 109  Locate items in index Line 118  Locate items in index
118          order => 'NUMD',          order => 'NUMD',
119          max => 100,          max => 100,
120          options => $HyperEstraier::Condition::SURE,          options => $HyperEstraier::Condition::SURE,
121            page => 42,
122    );    );
123    
124  Options are close match to Hyper Estraier API, except C<get_attr> which defines  Options are close match to Hyper Estraier API, except C<get_attr> which defines
# Line 116  attributes which will be returned in has Line 126  attributes which will be returned in has
126    
127  Results are returned as hash array with keys named by attributes  Results are returned as hash array with keys named by attributes
128    
129    Pages are numbered C< 1 ... hits/max >.
130    
131  =cut  =cut
132    
133  sub search {  sub search {
# Line 146  sub search { Line 158  sub search {
158          };          };
159    
160          $cond->set_phrase( $self->{iconv}->convert($q) ) if ($q);          $cond->set_phrase( $self->{iconv}->convert($q) ) if ($q);
         $cond->set_max( $args->{max} ) if ($args->{max});  
161          $cond->set_options( $args->{options} ) if ($args->{options});          $cond->set_options( $args->{options} ) if ($args->{options});
162          $cond->set_order( $args->{order} ) if ($args->{order});          $cond->set_order( $args->{order} ) if ($args->{order});
163    
164            my $max = $args->{max} || 7;
165            my $page = $args->{page} || 1;
166            if ($page < 1) {
167                    $log->warn("page number $page < 1");
168                    $page = 1;
169            }
170    
171            $cond->set_max( $page * $max );
172    
173          my $result = $self->{db}->search($cond, 0) ||          my $result = $self->{db}->search($cond, 0) ||
174                  $log->die("can't search for ", sub { Dumper( $args ) });                  $log->die("can't search for ", sub { Dumper( $args ) });
175    
# Line 158  sub search { Line 178  sub search {
178    
179          my @results;          my @results;
180    
181          for my $i ( 0 .. ( $hits - 1 ) ) {          for my $i ( (($page - 1) * $max) .. ( $hits - 1 ) ) {
182    
183                  #$log->debug("get_doc($i)");                  #$log->debug("get_doc($i)");
184                  my $doc = $result->get_doc( $i );                  my $doc = $result->get_doc( $i );

Legend:
Removed from v.152  
changed lines
  Added in v.211

  ViewVC Help
Powered by ViewVC 1.1.26