From 03e275196b3f82415a965d0bdd6bfa52a15d7446 Mon Sep 17 00:00:00 2001 From: pop Date: Sat, 26 Jul 2003 16:27:46 +0000 Subject: [PATCH] Added support for resultset terms. --- perl/IDZebra.i | 6 +++ perl/IDZebra_wrap.c | 103 ++++++++++++++++++++++++++++++++++++++++- perl/lib/IDZebra.pm | 1 + perl/lib/IDZebra/Resultset.pm | 30 +++++++++++- perl/lib/IDZebra/Session.pm | 6 ++- perl/t/05_search.t | 32 +++++++++++-- 6 files changed, 170 insertions(+), 8 deletions(-) diff --git a/perl/IDZebra.i b/perl/IDZebra.i index 0cf0ca7..8cd8382 100644 --- a/perl/IDZebra.i +++ b/perl/IDZebra.i @@ -373,6 +373,12 @@ int zebra_deleleResultSet(ZebraHandle zh, int function, int *statuses); +/* Resultset terms */ +%name(resultSetTerms) +int zebra_resultSetTerms (ZebraHandle zh, const char *setname, + int no, int *REFERENCE, + int *REFERENCE, char *out, int *REFERENCE); + /* == Sort ================================================================= */ %name(sort) int zebra_sort_by_specstr (ZebraHandle zh, diff --git a/perl/IDZebra_wrap.c b/perl/IDZebra_wrap.c index cbf5b83..e73f915 100644 --- a/perl/IDZebra_wrap.c +++ b/perl/IDZebra_wrap.c @@ -212,7 +212,7 @@ SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { * perl5.swg * * Perl5 runtime library - * $Header: /home/cvsroot/idis/perl/Attic/IDZebra_wrap.c,v 1.19 2003-07-07 10:59:33 pop Exp $ + * $Header: /home/cvsroot/idis/perl/Attic/IDZebra_wrap.c,v 1.20 2003-07-26 16:27:46 pop Exp $ * ----------------------------------------------------------------------------- */ #define SWIGPERL @@ -4630,6 +4630,106 @@ XS(_wrap_deleteResultSet) { } +XS(_wrap_resultSetTerms) { + char _swigmsg[SWIG_MAX_ERRMSG] = ""; + const char *_swigerr = _swigmsg; + { + ZebraHandle arg1 ; + char *arg2 ; + int arg3 ; + int *arg4 ; + int *arg5 ; + char *arg6 ; + int *arg7 ; + int result; + int dvalue4 ; + int dvalue5 ; + int dvalue7 ; + int argvi = 0; + SV * _saved[3] ; + dXSARGS; + + if ((items < 7) || (items > 7)) { + SWIG_croak("Usage: resultSetTerms(zh,setname,no,REFERENCE,REFERENCE,out,REFERENCE);"); + } + { + ZebraHandle * argp; + if (SWIG_ConvertPtr(ST(0),(void **) &argp, SWIGTYPE_p_ZebraHandle,0) < 0) { + SWIG_croak("Type error in argument 1 of resultSetTerms. Expected _p_ZebraHandle"); + } + arg1 = *argp; + } + if (!SvOK((SV*) ST(1))) arg2 = 0; + else arg2 = (char *) SvPV(ST(1), PL_na); + arg3 = (int) SvIV(ST(2)); + { + SV *tempsv; + if (!SvROK(ST(3))) { + SWIG_croak("expected a reference"); + } + tempsv = SvRV(ST(3)); + if (!SvIOK(tempsv)) { + SWIG_croak("expected a integer reference"); + } + dvalue4 = SvIV(tempsv); + arg4 = &dvalue4; + } + { + SV *tempsv; + if (!SvROK(ST(4))) { + SWIG_croak("expected a reference"); + } + tempsv = SvRV(ST(4)); + if (!SvIOK(tempsv)) { + SWIG_croak("expected a integer reference"); + } + dvalue5 = SvIV(tempsv); + arg5 = &dvalue5; + } + if (!SvOK((SV*) ST(5))) arg6 = 0; + else arg6 = (char *) SvPV(ST(5), PL_na); + { + SV *tempsv; + if (!SvROK(ST(6))) { + SWIG_croak("expected a reference"); + } + tempsv = SvRV(ST(6)); + if (!SvIOK(tempsv)) { + SWIG_croak("expected a integer reference"); + } + dvalue7 = SvIV(tempsv); + arg7 = &dvalue7; + } + _saved[0] = ST(3); + _saved[1] = ST(4); + _saved[2] = ST(6); + result = (int)zebra_resultSetTerms(arg1,(char const *)arg2,arg3,arg4,arg5,arg6,arg7); + + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++), (IV) result); + { + SV *tempsv; + tempsv = SvRV(_saved[0]); + sv_setiv(tempsv, (IV) *arg4); + } + { + SV *tempsv; + tempsv = SvRV(_saved[1]); + sv_setiv(tempsv, (IV) *arg5); + } + { + SV *tempsv; + tempsv = SvRV(_saved[2]); + sv_setiv(tempsv, (IV) *arg7); + } + XSRETURN(argvi); + fail: + (void) _swigerr; + } + croak(_swigerr); +} + + XS(_wrap_sort) { char _swigmsg[SWIG_MAX_ERRMSG] = ""; const char *_swigerr = _swigmsg; @@ -8632,6 +8732,7 @@ static swig_command_info swig_commands[] = { {"IDZebrac::records_retrieve", _wrap_records_retrieve}, {"IDZebrac::record_retrieve", _wrap_record_retrieve}, {"IDZebrac::deleteResultSet", _wrap_deleteResultSet}, +{"IDZebrac::resultSetTerms", _wrap_resultSetTerms}, {"IDZebrac::sort", _wrap_sort}, {"IDZebrac::scan_PQF", _wrap_scan_PQF}, {"IDZebrac::getScanEntry", _wrap_getScanEntry}, diff --git a/perl/lib/IDZebra.pm b/perl/lib/IDZebra.pm index b4a5009..4661205 100644 --- a/perl/lib/IDZebra.pm +++ b/perl/lib/IDZebra.pm @@ -77,6 +77,7 @@ package IDZebra; *records_retrieve = *IDZebrac::records_retrieve; *record_retrieve = *IDZebrac::record_retrieve; *deleteResultSet = *IDZebrac::deleteResultSet; +*resultSetTerms = *IDZebrac::resultSetTerms; *sort = *IDZebrac::sort; *scan_PQF = *IDZebrac::scan_PQF; sub getScanEntry { diff --git a/perl/lib/IDZebra/Resultset.pm b/perl/lib/IDZebra/Resultset.pm index 7408d35..28db014 100644 --- a/perl/lib/IDZebra/Resultset.pm +++ b/perl/lib/IDZebra/Resultset.pm @@ -1,4 +1,4 @@ -# $Id: Resultset.pm,v 1.9 2003-03-06 23:32:10 pop Exp $ +# $Id: Resultset.pm,v 1.10 2003-07-26 16:27:46 pop 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.9 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; + our $VERSION = do { my @r = (q$Revision: 1.10 $ =~ /\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; diff --git a/perl/lib/IDZebra/Session.pm b/perl/lib/IDZebra/Session.pm index ea49deb..30c4877 100644 --- a/perl/lib/IDZebra/Session.pm +++ b/perl/lib/IDZebra/Session.pm @@ -1,4 +1,4 @@ -# $Id: Session.pm,v 1.18 2003-07-07 10:59:33 pop Exp $ +# $Id: Session.pm,v 1.19 2003-07-26 16:27:46 pop Exp $ # # Zebra perl API header # ============================================================================= @@ -16,7 +16,7 @@ BEGIN { use IDZebra::ScanList; use IDZebra::RetrievalRecord; require Exporter; - our $VERSION = do { my @r = (q$Revision: 1.18 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; + our $VERSION = do { my @r = (q$Revision: 1.19 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; our @ISA = qw(IDZebra::Logger Exporter); our @EXPORT = qw (TRANS_RW TRANS_RO); } @@ -595,6 +595,7 @@ sub search { $self->databases(@{$args{databases}}); } + my $rsname = $args{rsname} ? $args{rsname} : $self->_new_setname; my $rs = $self->_search_pqf($query, $rsname); @@ -633,6 +634,7 @@ sub _search_pqf { my $rs = IDZebra::Resultset->new($self, name => $setname, + query => $query, recordCount => $hits, errCode => $self->errCode, errString => $self->errString); diff --git a/perl/t/05_search.t b/perl/t/05_search.t index 404c23f..0ba8ad2 100644 --- a/perl/t/05_search.t +++ b/perl/t/05_search.t @@ -1,6 +1,6 @@ #!perl # ============================================================================= -# $Id: 05_search.t,v 1.2 2003-03-04 19:33:53 pop Exp $ +# $Id: 05_search.t,v 1.3 2003-07-26 16:27:46 pop Exp $ # # Perl API header # ============================================================================= @@ -14,7 +14,7 @@ BEGIN { use strict; use warnings; -use Test::More tests => 7; +use Test::More tests => 12; # ---------------------------------------------------------------------------- # Session opening and closing @@ -41,6 +41,7 @@ my ($hits, $expected); # Search 1 databases my $rs1 = $sess->search(cqlmap => 'demo/cql.map', cql => 'IDZebra', + termset => 1, databases => [qw(demo1)]); $expected = $filecount; @@ -64,9 +65,34 @@ ok(($hits == $expected), "CQL search - found $hits/$expected records"); my $rs3 = $sess->search(cqlmap => 'demo/cql.map', pqf => '@attr 1=4 IDZebra'); $expected = $filecount * 2; -$hits = $rs2->count; +$hits = $rs3->count; +ok(($hits == $expected), "RPN search - found $hits/$expected records"); + +# Termlists; +my $rs4 = $sess->search(pqf => '@attr 1=4 @and IDZebra Session'); +$expected = 2; +$hits = $rs4->count; ok(($hits == $expected), "RPN search - found $hits/$expected records"); +my @terms = $rs4->terms(); +ok(($#terms == 1), "Got 2 terms in RPN expression"); +my $cc = 0; +foreach my $t (@terms) { + if ($t->{term} eq 'IDZebra') { + ok(($t->{count} = $filecount*2), "Term IDZebra ($t->{count})"); + $cc++; + } + elsif ($t->{term} eq 'Session') { + ok(($t->{count} = 2), "Term Session ($t->{count})"); + $cc++; + } else { + ok(0,"Invalid term $t->{term}"); + } + +} +ok (($cc == 2), "Got 2 terms for RS"); + + # More specific search -- 1.7.10.4