--- trunk/lib/WebPAC/Search/Estraier.pm 2005/11/21 14:42:16 80 +++ trunk/lib/WebPAC/Search/Estraier.pm 2005/11/21 14:42:22 81 @@ -35,7 +35,7 @@ user => 'admin', passwd => 'admin', encoding => 'iso-8859-2', - log => $Log::Log4Perl->log_object, + log => $Log::Log4perl->log_object, ); Options are: @@ -60,6 +60,11 @@ (and it probably is). This encoding will be converted to C for Hyper Estraier. +=item log + +L object or equivalent (C<< $c->log >> can be used in +L and there is support for it). + =back =cut @@ -83,8 +88,8 @@ my $encoding = $self->{'encoding'} || 'ISO-8859-2'; $log->info("using encoding $encoding"); - $self->{'iconv'} = new Text::Iconv($encoding, 'UTF-8') or - $log->die("can't create conversion from $encoding to UTF-8"); + $self->{'iconv'} = new Text::Iconv('UTF-8', $encoding) or + $log->die("can't create conversion from UTF-8 to $encoding"); $self ? return $self : return undef; } @@ -94,11 +99,13 @@ Locate items in index - $est->search( + my @results = $est->search( query => 'name of book or novel', - attr => [ qw/PersonalName Title/ ], + attr => qw/PersonalName TitleProper/, ); +Results are returned as hash array with keys named by attributes + =cut sub search { @@ -110,12 +117,8 @@ $log->logconfess('need db in object') unless ($self->{'db'}); $log->logconfess('need attr') unless ($args->{'attr'}); - $log->logconfess("need attr as array not " . ref($args->{'attr'}) ) unless (ref($args->{'attr'}) eq 'ARRAY'); -# my $database = $self->{'database'} || $log->logconfess('no database in $self'); -# foreach my $p (qw/id ds type/) { -# $log->logconfess("need $p") unless ($args->{$p}); -# } + $log->logconfess("need attr as array not " . ref($args->{'attr'}) ) unless (ref($args->{'attr'}) eq 'ARRAY'); my $cond = HyperEstraier::Condition->new(); # $cond->add_attr("filepath ISTRINC $q"); @@ -131,11 +134,9 @@ my $hits = $result->doc_num; $log->debug("found $hits hits"); - my @attrs = $args->{'attr'} || $self->confess("need attr"); - my @results; - for my $i ( 0 .. $hits ) { + for my $i ( 0 .. ( $hits - 1 ) ) { $log->debug("get_doc($i)"); my $doc = $result->get_doc( $i ); @@ -146,10 +147,10 @@ my $hash; - foreach my $attr (@attrs) { + foreach my $attr (@{ $args->{'attr'} }) { my $val = $doc->attr( $attr ); $log->debug("attr $attr = ", $val || 'undef'); - $hash->{$attr} = $val if (defined($val)); + $hash->{$attr} = $self->{'iconv'}->convert( $val ) if (defined($val)); } if ($hash) {