From 71a375e327a1044a5f8e093301496c6f6692dff2 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Wed, 23 Nov 2005 21:52:55 +0000 Subject: [PATCH] r9072@llin: dpavlin | 2005-11-23 21:31:14 +0100 API 0.02: changed and added options to match Hyper Estraier's API git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@122 07558da8-63fa-0310-ba24-9fe276d99e06 --- lib/WebPAC/Search/Estraier.pm | 48 +++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/lib/WebPAC/Search/Estraier.pm b/lib/WebPAC/Search/Estraier.pm index bc9c84e..b11d76e 100644 --- a/lib/WebPAC/Search/Estraier.pm +++ b/lib/WebPAC/Search/Estraier.pm @@ -13,11 +13,11 @@ WebPAC::Search::Estraier - search Hyper Estraier full text index =head1 VERSION -Version 0.01 +Version 0.02 =cut -our $VERSION = '0.01'; +our $VERSION = '0.02'; =head1 SYNOPSIS @@ -100,10 +100,20 @@ sub new { Locate items in index my @results = $est->search( - query => 'name of book or novel', - attr => qw/PersonalName TitleProper/, + phrase => 'name of book or novel', + add_attr => [ + "filepath ISTRINC $q", + "size NUMGT 100", + ], + get_attr => qw/PersonalName TitleProper/, + order => 'NUMD', + max => 100, + options => $HyperEstraier::Condition::SURE, ); +Options are close match to Hyper Estraier API, except C which defines +attributes which will be returned in hash for each record. + Results are returned as hash array with keys named by attributes =cut @@ -115,22 +125,28 @@ sub search { my $log = $self->_get_logger; - $self->confess('need db in object') unless ($self->{'db'}); - $self->confess('need attr') unless ($args->{'attr'}); + $self->confess('need db in object') unless ($self->{db}); + $self->confess('need get_attr') unless ($args->{get_attr}); - $self->confess("need attr as array not " . ref($args->{'attr'}) ) unless (ref($args->{'attr'}) eq 'ARRAY'); + $self->confess("need get_attr as array not " . ref($args->{get_attr}) ) unless (ref($args->{get_attr}) eq 'ARRAY'); - my $q = $args->{'query'}; + my $q = $args->{phrase}; my $cond = HyperEstraier::Condition->new(); -# $cond->add_attr("filepath ISTRINC $q"); + if ( ref($args->{add_attr}) eq 'ARRAY' ) { + $log->debug("adding search attributes: " . join(", ", @{ $args->{add_attr} }) ); + map { + $cond->add_attr( $self->{iconv}->conver( $_ ) ); + $log->debug(" + $_"); + } $args->{add_attr}; + } - $cond->set_phrase( $self->{'iconv'}->convert( $q ) ) if ($q); - $cond->set_max( $args->{'max'} ) if ($args->{'max'}); -# $cond->set_options( $HyperEstraier::Condition::SURE ); -# $cond->set_order( 'NUMD' ); + $cond->set_phrase( $self->{iconv}->convert($q) ) if ($q); + $cond->set_max( $args->{max} ) if ($args->{max}); + $cond->set_options( $args->{options} ) if ($args->{options}); + $cond->set_order( $args->{order} ) if ($args->{order}); - my $result = $self->{'db'}->search($cond, 0) || + my $result = $self->{db}->search($cond, 0) || $log->die("can't search for ", sub { Dumper( $args ) }); my $hits = $result->doc_num; @@ -149,10 +165,10 @@ sub search { my $hash; - foreach my $attr (@{ $args->{'attr'} }) { + foreach my $attr (@{ $args->{get_attr} }) { my $val = $doc->attr( $attr ); #$log->debug("attr $attr = ", $val || 'undef'); - $hash->{$attr} = $self->{'iconv'}->convert( $val ) if (defined($val)); + $hash->{$attr} = $self->{iconv}->convert( $val ) if (defined($val)); } if ($hash) { -- 2.20.1