From 03d53289357e1714d2b1a9492a029eb352325480 Mon Sep 17 00:00:00 2001 From: pop Date: Mon, 18 Nov 2002 13:25:53 +0000 Subject: [PATCH] Search now returns a Resultset object, for retrieval purposes. Added sort functionality. --- perl/lib/IDZebra/Session.pm | 80 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 16 deletions(-) diff --git a/perl/lib/IDZebra/Session.pm b/perl/lib/IDZebra/Session.pm index d53bb7f..f876555 100644 --- a/perl/lib/IDZebra/Session.pm +++ b/perl/lib/IDZebra/Session.pm @@ -9,6 +9,7 @@ package IDZebra::Session; use IDZebra; use IDZebra::Logger qw(:flags :calls); use IDZebra::Repository; +use IDZebra::Resultset; use Scalar::Util; our @ISA = qw(IDZebra::Logger); @@ -51,13 +52,15 @@ sub close { IDZebra::close($self->{zh}); $self->{zh} = undef; } - + if ($self->{odr_input}) { + IDZebra::odr_reset($self->{odr_input}); IDZebra::odr_destroy($self->{odr_input}); $self->{odr_input} = undef; } if ($self->{odr_output}) { + IDZebra::odr_reset($self->{odr_output}); IDZebra::odr_destroy($self->{odr_output}); $self->{odr_output} = undef; } @@ -108,6 +111,16 @@ sub end_trans { } } +sub begin_read { + my ($self) =@_; + return(IDZebra::begin_read($self->{zh})); +} + +sub end_read { + my ($self) =@_; + IDZebra::end_read($self->{zh}); +} + sub shadow_enable { my ($self, $value) = @_; if ($#_ > 0) { IDZebra::set_shadow_enable($self->{zh},$value); } @@ -160,7 +173,7 @@ sub Repository { } # ----------------------------------------------------------------------------- -# Search and retrieval +# Search # ----------------------------------------------------------------------------- sub select_databases { my ($self, @databases) = @_; @@ -169,25 +182,60 @@ sub select_databases { \@databases)); } -sub begin_read { - my ($self) =@_; - return(IDZebra::begin_read($self->{zh})); +sub search_pqf { + my ($self, $query, $setname) = @_; + my $hits = IDZebra::search_PQF($self->{zh}, + $self->{odr_input}, + $self->{odr_output}, + $query, + $setname); + + my $rs = IDZebra::Resultset->new($self, + name => $setname, + recordCount => $hits, + errCode => $self->errCode, + errString => $self->errString); + return($rs); } -sub end_read { - my ($self) =@_; - IDZebra::end_read($self->{zh}); -} +# ----------------------------------------------------------------------------- +# Sort +# +# Sorting of multiple result sets is not supported by zebra... +# ----------------------------------------------------------------------------- -sub search_pqf { - my ($self, $query, $setname) = @_; - return (IDZebra::search_PQF($self->{zh}, - $self->{odr_input}, - $self->{odr_output}, - $query, - $setname)); +sub sortResultsets { + my ($self, $sortspec, $setname, @sets) = @_; + + my @setnames; + my $count = 0; + foreach my $rs (@sets) { + push (@setnames, $rs->{name}); + $count += $rs->{recordCount}; # is this really sure ??? It doesn't + # matter now... + } + + my $status = IDZebra::sort($self->{zh}, + $self->{odr_output}, + $sortspec, + $setname, + \@setnames); + + my $errCode = $self->errCode; + my $errString = $self->errString; + + if ($status || $errCode) {$count = 0;} + + my $rs = IDZebra::Resultset->new($self, + name => $setname, + recordCount => $count, + errCode => $errCode, + errString => $errString); + + return ($rs); } + __END__ =head1 NAME -- 1.7.10.4