X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=perl%2Flib%2FIDZebra%2FResultset.pm;h=253bba1b96e83cc24296d250dcc6ad74f721ffb4;hb=4a3a97df9d47b8d099e403308f8015f130366994;hp=80fabdbf8a95e24012932d0659f4c0c6c317aedc;hpb=c45742c694d4fa704d4282ada62c7f46c69fea88;p=idzebra-moved-to-github.git diff --git a/perl/lib/IDZebra/Resultset.pm b/perl/lib/IDZebra/Resultset.pm index 80fabdb..253bba1 100644 --- a/perl/lib/IDZebra/Resultset.pm +++ b/perl/lib/IDZebra/Resultset.pm @@ -1,4 +1,4 @@ -# $Id: Resultset.pm,v 1.8 2003-03-05 13:55:22 pop Exp $ +# $Id: Resultset.pm,v 1.11 2004-07-28 08:15:46 adam Exp $ # # Zebra perl API header # ============================================================================= @@ -12,7 +12,7 @@ BEGIN { use IDZebra::Logger qw(:flags :calls); use Scalar::Util qw(weaken); use Carp; - our $VERSION = do { my @r = (q$Revision: 1.8 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; + our $VERSION = do { my @r = (q$Revision: 1.11 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; our @ISA = qw(IDZebra::Logger); } @@ -32,6 +32,7 @@ sub new { $self->{odr_stream} = IDZebra::odr_createmem($IDZebra::ODR_DECODE); $self->{name} = $args{name}; + $self->{query} = $args{query}; $self->{recordCount} = $args{recordCount}; $self->{errCode} = $args{errCode}; $self->{errString} = $args{errString}; @@ -58,6 +59,31 @@ sub errString { return ($self->{errCode}); } +sub terms { + use Data::Dumper; + my ($self) = @_; + my $count = 0; my $type = 0; my $len = 0; + my $tc = IDZebra::resultSetTerms($self->{session}{zh},$self->{name}, + 0, \$count, \$type, "\0", \$len); + + logf (LOG_LOG,"Got $tc terms"); + + + my @res = (); + for (my $i=0; $i<$tc; $i++) { + my $len = 1024; + my $t = {term => "\0" x $len, count => 0, type => 0}; + my $stat = IDZebra::resultSetTerms($self->{session}{zh},$self->{name}, + $i, \$t->{count}, \$t->{type}, + $t->{term}, \$len); + $t->{term} = substr($t->{term}, 0, $len); + logf (LOG_LOG, + "term $i: type $t->{type}, '$t->{term}' ($t->{count})"); + push (@res, $t); + } + return (@res); +} + # ============================================================================= sub DESTROY { my $self = shift; @@ -91,12 +117,22 @@ sub records { my $from = $args{from} ? $args{from} : 1; my $to = $args{to} ? $args{to} : $self->{recordCount}; + if (($to-$from) >= 1000) { + if ($args{to}) { + croak ("Cannot fetch more than 1000 records at a time"); + } else { + $to = $from + 999; + } + } + my $elementSet = $args{elementSet} ? $args{elementSet} : 'R'; my $schema = $args{schema} ? $args{schema} : ''; my $recordSyntax = $args{recordSyntax} ? $args{recordSyntax} : ''; my $class = $args{class} ? $args{class} : ''; + # ADAM: Reset before we use it (not after) + IDZebra::odr_reset($self->{odr_stream}); my $ro = IDZebra::RetrievalObj->new(); IDZebra::records_retrieve($self->{session}{zh}, @@ -109,7 +145,6 @@ sub records { $to, $ro); - my @res = (); for (my $i=$from; $i<=$to; $i++) { @@ -118,12 +153,10 @@ sub records { if ($class) { } else { - push (@res, $rec); + push (@res, $rec); } } - IDZebra::odr_reset($self->{odr_stream}); - return (@res); }