From bb45d1f271522de94ba190f4024a27e2398f55fb Mon Sep 17 00:00:00 2001 From: pop Date: Mon, 2 Dec 2002 10:23:30 +0000 Subject: [PATCH] Scan is working now --- perl/IDZebra.i | 62 ++++---- perl/IDZebra_wrap.c | 427 +++++++++++++++++++++++++++++++++++++++++++++++--- perl/lib/IDZebra.pm | 85 ++++++++++ perl/test.pl | 25 ++- perl/zebra_api_ext.c | 45 ++++++ perl/zebra_perl.h | 7 + 6 files changed, 597 insertions(+), 54 deletions(-) diff --git a/perl/IDZebra.i b/perl/IDZebra.i index 1cab21f..88e6a7b 100644 --- a/perl/IDZebra.i +++ b/perl/IDZebra.i @@ -1,4 +1,5 @@ %module "IDZebra" +%include typemaps.i // Load the typemaps librayr %{ #include "zebraapi.h" @@ -46,30 +47,28 @@ /* Creates a new Perl array and places a NULL-terminated char ** into it */ %typemap(out) char ** { - AV *myav; - SV **svs; - int i = 0,len = 0; - /* Figure out how many elements we have */ - while ($1[len]) - len++; - svs = (SV **) malloc(len*sizeof(SV *)); - for (i = 0; i < len ; i++) { - svs[i] = sv_newmortal(); - sv_setpv((SV*)svs[i],$1[i]); - }; - myav = av_make(len,svs); - free(svs); + AV *myav; + SV **svs; + int i = 0,len = 0; + /* Figure out how many elements we have */ + while ($1[len]) + len++; + svs = (SV **) malloc(len*sizeof(SV *)); + for (i = 0; i < len ; i++) { + svs[i] = sv_newmortal(); + sv_setpv((SV*)svs[i],$1[i]); + }; + myav = av_make(len,svs); + free(svs); $result = newRV((SV*)myav); sv_2mortal($result); argvi++; } - /* == Structures for shadow classes ======================================= */ %include "zebra_perl.h" - /* == Module initialization and cleanup (zebra_perl.c) ===================== */ void init (void); @@ -271,15 +270,28 @@ int sort (ZebraHandle zh, const char *output_setname, const char **input_setnames ); + +/* == Scan ================================================================= */ /* +%apply int *INOUT {int *position}; +%apply int *INOUT {int *num_entries}; +%apply int *INOUT {int *is_partial}; -void zebra_sort (ZebraHandle zh, ODR stream, - int num_input_setnames, - const char **input_setnames, - const char *output_setname, - Z_SortKeySpecList *sort_sequence, - int *sort_status); +%name(scan_PQF) +void zebra_scan_PQF (ZebraHandle zh, + ODR stream, + const char *pqf_query, + int *position, + int *num_entries, + int *is_partial); */ +%name(scan_PQF) +void zebra_scan_PQF (ZebraHandle zh, + ScanObj *so, + ODR stream, + const char *pqf_query); + +ScanEntry *getScanEntry(ScanObj *so, int pos); /* Admin functionality */ /* @@ -287,14 +299,6 @@ void zebra_sort (ZebraHandle zh, ODR stream, %name(admin_shutdown) void zebra_admin_shutdown (ZebraHandle zh); */ -/* Browse -void zebra_scan (ZebraHandle zh, ODR stream, - Z_AttributesPlusTerm *zapt, - oid_value attributeset, - int *position, int *num_entries, - ZebraScanEntry **list, - int *is_partial); -*/ /* Delete Result Set(s) */ /* diff --git a/perl/IDZebra_wrap.c b/perl/IDZebra_wrap.c index 6f8fe93..26298c1 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.3 2002-11-18 13:16:43 pop Exp $ + * $Header: /home/cvsroot/idis/perl/Attic/IDZebra_wrap.c,v 1.4 2002-12-02 10:23:30 pop Exp $ * ----------------------------------------------------------------------------- */ #define SWIGPERL @@ -519,28 +519,29 @@ static void _swig_create_magic(CPerlObj *pPerl, SV *sv, const char *name, int (C #define SWIGTYPE_p_RetrievalRecordBuf swig_types[18] #define SWIGTYPE_p_perl_context swig_types[19] #define SWIGTYPE_p_data1_node swig_types[20] -#define SWIGTYPE_p_RetrievalObj swig_types[21] -#define SWIGTYPE_p_data1_tagset swig_types[22] -#define SWIGTYPE_p_data1_tag swig_types[23] -#define SWIGTYPE_p_Z_ExplainRecord swig_types[24] +#define SWIGTYPE_p_ScanObj swig_types[21] +#define SWIGTYPE_p_RetrievalObj swig_types[22] +#define SWIGTYPE_p_data1_tagset swig_types[23] +#define SWIGTYPE_p_data1_tag swig_types[24] #define SWIGTYPE_p_ZebraRetrievalRecord swig_types[25] #define SWIGTYPE_p_RetrievalRecord swig_types[26] #define SWIGTYPE_p_NMEM swig_types[27] -#define SWIGTYPE_p_data1_marctab swig_types[28] -#define SWIGTYPE_p_Z_BriefBib swig_types[29] -#define SWIGTYPE_p_ScanEntry swig_types[30] -#define SWIGTYPE_p_f_p_void_p_char_size_t__int swig_types[31] -#define SWIGTYPE_p_FILE swig_types[32] -#define SWIGTYPE_p_data1_element swig_types[33] -#define SWIGTYPE_p_recordGroup swig_types[34] -#define SWIGTYPE_p_int swig_types[35] -#define SWIGTYPE_p_data1_handle swig_types[36] -#define SWIGTYPE_p_p_int swig_types[37] -#define SWIGTYPE_p_data1_absyn_cache swig_types[38] -#define SWIGTYPE_p_data1_attset_cache swig_types[39] -#define SWIGTYPE_p_Z_GenericRecord swig_types[40] -#define SWIGTYPE_p_data1_vartype swig_types[41] -static swig_type_info *swig_types[43]; +#define SWIGTYPE_p_Z_ExplainRecord swig_types[28] +#define SWIGTYPE_p_data1_marctab swig_types[29] +#define SWIGTYPE_p_Z_BriefBib swig_types[30] +#define SWIGTYPE_p_ScanEntry swig_types[31] +#define SWIGTYPE_p_f_p_void_p_char_size_t__int swig_types[32] +#define SWIGTYPE_p_FILE swig_types[33] +#define SWIGTYPE_p_data1_element swig_types[34] +#define SWIGTYPE_p_recordGroup swig_types[35] +#define SWIGTYPE_p_int swig_types[36] +#define SWIGTYPE_p_data1_handle swig_types[37] +#define SWIGTYPE_p_p_int swig_types[38] +#define SWIGTYPE_p_data1_absyn_cache swig_types[39] +#define SWIGTYPE_p_data1_attset_cache swig_types[40] +#define SWIGTYPE_p_Z_GenericRecord swig_types[41] +#define SWIGTYPE_p_data1_vartype swig_types[42] +static swig_type_info *swig_types[44]; /* -------- TYPES TABLE (END) -------- */ @@ -2152,6 +2153,292 @@ XS(_wrap_delete_ScanEntry) { } +XS(_wrap_ScanObj_num_entries_set) { + char _swigmsg[SWIG_MAX_ERRMSG] = ""; + const char *_swigerr = _swigmsg; + { + ScanObj *arg1 ; + int arg2 ; + int argvi = 0; + dXSARGS; + + if ((items < 2) || (items > 2)) { + SWIG_croak("Usage: ScanObj_num_entries_set(self,num_entries);"); + } + { + if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_ScanObj,0) < 0) { + SWIG_croak("Type error in argument 1 of ScanObj_num_entries_set. Expected _p_ScanObj"); + } + } + arg2 = (int) SvIV(ST(1)); + if (arg1) (arg1)->num_entries = arg2; + + + XSRETURN(argvi); + fail: + (void) _swigerr; + } + croak(_swigerr); +} + + +XS(_wrap_ScanObj_num_entries_get) { + char _swigmsg[SWIG_MAX_ERRMSG] = ""; + const char *_swigerr = _swigmsg; + { + ScanObj *arg1 ; + int result; + int argvi = 0; + dXSARGS; + + if ((items < 1) || (items > 1)) { + SWIG_croak("Usage: ScanObj_num_entries_get(self);"); + } + { + if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_ScanObj,0) < 0) { + SWIG_croak("Type error in argument 1 of ScanObj_num_entries_get. Expected _p_ScanObj"); + } + } + result = (int) ((arg1)->num_entries); + + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++), (IV) result); + XSRETURN(argvi); + fail: + (void) _swigerr; + } + croak(_swigerr); +} + + +XS(_wrap_ScanObj_position_set) { + char _swigmsg[SWIG_MAX_ERRMSG] = ""; + const char *_swigerr = _swigmsg; + { + ScanObj *arg1 ; + int arg2 ; + int argvi = 0; + dXSARGS; + + if ((items < 2) || (items > 2)) { + SWIG_croak("Usage: ScanObj_position_set(self,position);"); + } + { + if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_ScanObj,0) < 0) { + SWIG_croak("Type error in argument 1 of ScanObj_position_set. Expected _p_ScanObj"); + } + } + arg2 = (int) SvIV(ST(1)); + if (arg1) (arg1)->position = arg2; + + + XSRETURN(argvi); + fail: + (void) _swigerr; + } + croak(_swigerr); +} + + +XS(_wrap_ScanObj_position_get) { + char _swigmsg[SWIG_MAX_ERRMSG] = ""; + const char *_swigerr = _swigmsg; + { + ScanObj *arg1 ; + int result; + int argvi = 0; + dXSARGS; + + if ((items < 1) || (items > 1)) { + SWIG_croak("Usage: ScanObj_position_get(self);"); + } + { + if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_ScanObj,0) < 0) { + SWIG_croak("Type error in argument 1 of ScanObj_position_get. Expected _p_ScanObj"); + } + } + result = (int) ((arg1)->position); + + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++), (IV) result); + XSRETURN(argvi); + fail: + (void) _swigerr; + } + croak(_swigerr); +} + + +XS(_wrap_ScanObj_is_partial_set) { + char _swigmsg[SWIG_MAX_ERRMSG] = ""; + const char *_swigerr = _swigmsg; + { + ScanObj *arg1 ; + int arg2 ; + int argvi = 0; + dXSARGS; + + if ((items < 2) || (items > 2)) { + SWIG_croak("Usage: ScanObj_is_partial_set(self,is_partial);"); + } + { + if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_ScanObj,0) < 0) { + SWIG_croak("Type error in argument 1 of ScanObj_is_partial_set. Expected _p_ScanObj"); + } + } + arg2 = (int) SvIV(ST(1)); + if (arg1) (arg1)->is_partial = arg2; + + + XSRETURN(argvi); + fail: + (void) _swigerr; + } + croak(_swigerr); +} + + +XS(_wrap_ScanObj_is_partial_get) { + char _swigmsg[SWIG_MAX_ERRMSG] = ""; + const char *_swigerr = _swigmsg; + { + ScanObj *arg1 ; + int result; + int argvi = 0; + dXSARGS; + + if ((items < 1) || (items > 1)) { + SWIG_croak("Usage: ScanObj_is_partial_get(self);"); + } + { + if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_ScanObj,0) < 0) { + SWIG_croak("Type error in argument 1 of ScanObj_is_partial_get. Expected _p_ScanObj"); + } + } + result = (int) ((arg1)->is_partial); + + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++), (IV) result); + XSRETURN(argvi); + fail: + (void) _swigerr; + } + croak(_swigerr); +} + + +XS(_wrap_ScanObj_entries_set) { + char _swigmsg[SWIG_MAX_ERRMSG] = ""; + const char *_swigerr = _swigmsg; + { + ScanObj *arg1 ; + ScanEntry *arg2 ; + int argvi = 0; + dXSARGS; + + if ((items < 2) || (items > 2)) { + SWIG_croak("Usage: ScanObj_entries_set(self,entries);"); + } + { + if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_ScanObj,0) < 0) { + SWIG_croak("Type error in argument 1 of ScanObj_entries_set. Expected _p_ScanObj"); + } + } + { + if (SWIG_ConvertPtr(ST(1), (void **) &arg2, SWIGTYPE_p_ScanEntry,0) < 0) { + SWIG_croak("Type error in argument 2 of ScanObj_entries_set. Expected _p_ScanEntry"); + } + } + if (arg1) (arg1)->entries = arg2; + + + XSRETURN(argvi); + fail: + (void) _swigerr; + } + croak(_swigerr); +} + + +XS(_wrap_ScanObj_entries_get) { + char _swigmsg[SWIG_MAX_ERRMSG] = ""; + const char *_swigerr = _swigmsg; + { + ScanObj *arg1 ; + ScanEntry *result; + int argvi = 0; + dXSARGS; + + if ((items < 1) || (items > 1)) { + SWIG_croak("Usage: ScanObj_entries_get(self);"); + } + { + if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_ScanObj,0) < 0) { + SWIG_croak("Type error in argument 1 of ScanObj_entries_get. Expected _p_ScanObj"); + } + } + result = (ScanEntry *) ((arg1)->entries); + + ST(argvi) = sv_newmortal(); + SWIG_MakePtr(ST(argvi++), (void *) result, SWIGTYPE_p_ScanEntry,0); + XSRETURN(argvi); + fail: + (void) _swigerr; + } + croak(_swigerr); +} + + +XS(_wrap_new_ScanObj) { + char _swigmsg[SWIG_MAX_ERRMSG] = ""; + const char *_swigerr = _swigmsg; + { + ScanObj *result; + int argvi = 0; + dXSARGS; + + if ((items < 0) || (items > 0)) { + SWIG_croak("Usage: new_ScanObj();"); + } + result = (ScanObj *)(ScanObj *) calloc(1, sizeof(ScanObj)); + + ST(argvi) = sv_newmortal(); + SWIG_MakePtr(ST(argvi++), (void *) result, SWIGTYPE_p_ScanObj,0); + XSRETURN(argvi); + fail: + (void) _swigerr; + } + croak(_swigerr); +} + + +XS(_wrap_delete_ScanObj) { + char _swigmsg[SWIG_MAX_ERRMSG] = ""; + const char *_swigerr = _swigmsg; + { + ScanObj *arg1 ; + int argvi = 0; + dXSARGS; + + if ((items < 1) || (items > 1)) { + SWIG_croak("Usage: delete_ScanObj(self);"); + } + { + if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_ScanObj,0) < 0) { + SWIG_croak("Type error in argument 1 of delete_ScanObj. Expected _p_ScanObj"); + } + } + free((char *) arg1); + + + XSRETURN(argvi); + fail: + (void) _swigerr; + } + croak(_swigerr); +} + + XS(_wrap_init__SWIG_0) { char _swigmsg[SWIG_MAX_ERRMSG] = ""; const char *_swigerr = _swigmsg; @@ -3517,6 +3804,83 @@ XS(_wrap_sort) { } +XS(_wrap_scan_PQF) { + char _swigmsg[SWIG_MAX_ERRMSG] = ""; + const char *_swigerr = _swigmsg; + { + ZebraHandle arg1 ; + ScanObj *arg2 ; + ODR arg3 ; + char *arg4 ; + int argvi = 0; + dXSARGS; + + if ((items < 4) || (items > 4)) { + SWIG_croak("Usage: scan_PQF(zh,so,stream,pqf_query);"); + } + { + ZebraHandle * argp; + if (SWIG_ConvertPtr(ST(0),(void **) &argp, SWIGTYPE_p_ZebraHandle,0) < 0) { + SWIG_croak("Type error in argument 1 of scan_PQF. Expected _p_ZebraHandle"); + } + arg1 = *argp; + } + { + if (SWIG_ConvertPtr(ST(1), (void **) &arg2, SWIGTYPE_p_ScanObj,0) < 0) { + SWIG_croak("Type error in argument 2 of scan_PQF. Expected _p_ScanObj"); + } + } + { + ODR * argp; + if (SWIG_ConvertPtr(ST(2),(void **) &argp, SWIGTYPE_p_ODR,0) < 0) { + SWIG_croak("Type error in argument 3 of scan_PQF. Expected _p_ODR"); + } + arg3 = *argp; + } + if (!SvOK((SV*) ST(3))) arg4 = 0; + else arg4 = (char *) SvPV(ST(3), PL_na); + zebra_scan_PQF(arg1,arg2,arg3,(char const *)arg4); + + + XSRETURN(argvi); + fail: + (void) _swigerr; + } + croak(_swigerr); +} + + +XS(_wrap_getScanEntry) { + char _swigmsg[SWIG_MAX_ERRMSG] = ""; + const char *_swigerr = _swigmsg; + { + ScanObj *arg1 ; + int arg2 ; + ScanEntry *result; + int argvi = 0; + dXSARGS; + + if ((items < 2) || (items > 2)) { + SWIG_croak("Usage: getScanEntry(so,pos);"); + } + { + if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_ScanObj,0) < 0) { + SWIG_croak("Type error in argument 1 of getScanEntry. Expected _p_ScanObj"); + } + } + arg2 = (int) SvIV(ST(1)); + result = (ScanEntry *)getScanEntry(arg1,arg2); + + ST(argvi) = sv_newmortal(); + SWIG_MakePtr(ST(argvi++), (void *) result, SWIGTYPE_p_ScanEntry,0); + XSRETURN(argvi); + fail: + (void) _swigerr; + } + croak(_swigerr); +} + + XS(_wrap_nmem_create) { char _swigmsg[SWIG_MAX_ERRMSG] = ""; const char *_swigerr = _swigmsg; @@ -6077,7 +6441,7 @@ XS(_wrap_data1_get_read_buf) { svs[i] = sv_newmortal(); sv_setpv((SV*)svs[i],result[i]); }; - myav = av_make(len,svs); + myav = av_make(len,svs); free(svs); ST(argvi) = newRV((SV*)myav); sv_2mortal(ST(argvi)); @@ -6130,7 +6494,7 @@ XS(_wrap_data1_get_map_buf) { svs[i] = sv_newmortal(); sv_setpv((SV*)svs[i],result[i]); }; - myav = av_make(len,svs); + myav = av_make(len,svs); free(svs); ST(argvi) = newRV((SV*)myav); sv_2mortal(ST(argvi)); @@ -7065,13 +7429,14 @@ static swig_type_info _swigt__p_data1_varset[] = {{"_p_data1_varset", 0, "data1_ static swig_type_info _swigt__p_RetrievalRecordBuf[] = {{"_p_RetrievalRecordBuf", 0, "RetrievalRecordBuf *", 0},{"_p_RetrievalRecordBuf"},{0}}; static swig_type_info _swigt__p_perl_context[] = {{"_p_perl_context", 0, "struct perl_context *", 0},{"_p_perl_context"},{0}}; static swig_type_info _swigt__p_data1_node[] = {{"_p_data1_node", 0, "data1_node *", 0},{"_p_data1_node"},{0}}; +static swig_type_info _swigt__p_ScanObj[] = {{"IDZebra::ScanObj", 0, "ScanObj *", 0},{"IDZebra::ScanObj"},{0}}; static swig_type_info _swigt__p_RetrievalObj[] = {{"IDZebra::RetrievalObj", 0, "RetrievalObj *", 0},{"IDZebra::RetrievalObj"},{0}}; static swig_type_info _swigt__p_data1_tagset[] = {{"_p_data1_tagset", 0, "data1_tagset *", 0},{"_p_data1_tagset"},{0}}; static swig_type_info _swigt__p_data1_tag[] = {{"_p_data1_tag", 0, "data1_tag *", 0},{"_p_data1_tag"},{0}}; -static swig_type_info _swigt__p_Z_ExplainRecord[] = {{"_p_Z_ExplainRecord", 0, "Z_ExplainRecord *", 0},{"_p_Z_ExplainRecord"},{0}}; static swig_type_info _swigt__p_ZebraRetrievalRecord[] = {{"_p_ZebraRetrievalRecord", 0, "ZebraRetrievalRecord *", 0},{"_p_ZebraRetrievalRecord"},{0}}; static swig_type_info _swigt__p_RetrievalRecord[] = {{"IDZebra::RetrievalRecord", 0, "RetrievalRecord *", 0},{"IDZebra::RetrievalRecord"},{0}}; static swig_type_info _swigt__p_NMEM[] = {{"_p_NMEM", 0, "NMEM *", 0},{"_p_NMEM"},{0}}; +static swig_type_info _swigt__p_Z_ExplainRecord[] = {{"_p_Z_ExplainRecord", 0, "Z_ExplainRecord *", 0},{"_p_Z_ExplainRecord"},{0}}; static swig_type_info _swigt__p_data1_marctab[] = {{"_p_data1_marctab", 0, "data1_marctab *", 0},{"_p_data1_marctab"},{0}}; static swig_type_info _swigt__p_Z_BriefBib[] = {{"_p_Z_BriefBib", 0, "Z_BriefBib *", 0},{"_p_Z_BriefBib"},{0}}; static swig_type_info _swigt__p_ScanEntry[] = {{"IDZebra::ScanEntry", 0, "ScanEntry *", 0},{"IDZebra::ScanEntry"},{0}}; @@ -7109,13 +7474,14 @@ _swigt__p_data1_varset, _swigt__p_RetrievalRecordBuf, _swigt__p_perl_context, _swigt__p_data1_node, +_swigt__p_ScanObj, _swigt__p_RetrievalObj, _swigt__p_data1_tagset, _swigt__p_data1_tag, -_swigt__p_Z_ExplainRecord, _swigt__p_ZebraRetrievalRecord, _swigt__p_RetrievalRecord, _swigt__p_NMEM, +_swigt__p_Z_ExplainRecord, _swigt__p_data1_marctab, _swigt__p_Z_BriefBib, _swigt__p_ScanEntry, @@ -7237,6 +7603,16 @@ static swig_command_info swig_commands[] = { {"IDZebrac::ScanEntry_term_get", _wrap_ScanEntry_term_get}, {"IDZebrac::new_ScanEntry", _wrap_new_ScanEntry}, {"IDZebrac::delete_ScanEntry", _wrap_delete_ScanEntry}, +{"IDZebrac::ScanObj_num_entries_set", _wrap_ScanObj_num_entries_set}, +{"IDZebrac::ScanObj_num_entries_get", _wrap_ScanObj_num_entries_get}, +{"IDZebrac::ScanObj_position_set", _wrap_ScanObj_position_set}, +{"IDZebrac::ScanObj_position_get", _wrap_ScanObj_position_get}, +{"IDZebrac::ScanObj_is_partial_set", _wrap_ScanObj_is_partial_set}, +{"IDZebrac::ScanObj_is_partial_get", _wrap_ScanObj_is_partial_get}, +{"IDZebrac::ScanObj_entries_set", _wrap_ScanObj_entries_set}, +{"IDZebrac::ScanObj_entries_get", _wrap_ScanObj_entries_get}, +{"IDZebrac::new_ScanObj", _wrap_new_ScanObj}, +{"IDZebrac::delete_ScanObj", _wrap_delete_ScanObj}, {"IDZebrac::DESTROY", _wrap_DESTROY}, {"IDZebrac::logLevel", _wrap_logLevel}, {"IDZebrac::logFile", _wrap_logFile}, @@ -7275,6 +7651,8 @@ static swig_command_info swig_commands[] = { {"IDZebrac::records_retrieve", _wrap_records_retrieve}, {"IDZebrac::record_retrieve", _wrap_record_retrieve}, {"IDZebrac::sort", _wrap_sort}, +{"IDZebrac::scan_PQF", _wrap_scan_PQF}, +{"IDZebrac::getScanEntry", _wrap_getScanEntry}, {"IDZebrac::nmem_create", _wrap_nmem_create}, {"IDZebrac::nmem_destroy", _wrap_nmem_destroy}, {"IDZebrac::data1_create", _wrap_data1_create}, @@ -7423,6 +7801,7 @@ XS(SWIG_init) { SWIG_TypeClientData(SWIGTYPE_p_RetrievalObj, (void*) "IDZebra::RetrievalObj"); SWIG_TypeClientData(SWIGTYPE_p_RetrievalRecord, (void*) "IDZebra::RetrievalRecord"); SWIG_TypeClientData(SWIGTYPE_p_ScanEntry, (void*) "IDZebra::ScanEntry"); + SWIG_TypeClientData(SWIGTYPE_p_ScanObj, (void*) "IDZebra::ScanObj"); ST(0) = &PL_sv_yes; XSRETURN(1); } diff --git a/perl/lib/IDZebra.pm b/perl/lib/IDZebra.pm index 8cd1372..c10d7fa 100644 --- a/perl/lib/IDZebra.pm +++ b/perl/lib/IDZebra.pm @@ -71,6 +71,15 @@ package IDZebra; *records_retrieve = *IDZebrac::records_retrieve; *record_retrieve = *IDZebrac::record_retrieve; *sort = *IDZebrac::sort; +*scan_PQF = *IDZebrac::scan_PQF; +sub getScanEntry { + my @args = @_; + my $result = IDZebrac::getScanEntry(@args); + return undef if (!defined($result)); + my %resulthash; + tie %resulthash, ref($result), $result; + return bless \%resulthash, ref($result); +} *nmem_create = *IDZebrac::nmem_create; *nmem_destroy = *IDZebrac::nmem_destroy; *data1_create = *IDZebrac::data1_create; @@ -467,6 +476,82 @@ sub STORE { } +############# Class : IDZebra::ScanObj ############## + +package IDZebra::ScanObj; +@ISA = qw( IDZebra ); +%OWNER = (); +%BLESSEDMEMBERS = ( + entries => 'IDZebra::ScanEntry', +); + +%ITERATORS = (); +*swig_num_entries_get = *IDZebrac::ScanObj_num_entries_get; +*swig_num_entries_set = *IDZebrac::ScanObj_num_entries_set; +*swig_position_get = *IDZebrac::ScanObj_position_get; +*swig_position_set = *IDZebrac::ScanObj_position_set; +*swig_is_partial_get = *IDZebrac::ScanObj_is_partial_get; +*swig_is_partial_set = *IDZebrac::ScanObj_is_partial_set; +*swig_entries_get = *IDZebrac::ScanObj_entries_get; +*swig_entries_set = *IDZebrac::ScanObj_entries_set; +sub new { + my $pkg = shift; + my @args = @_; + my $self = IDZebrac::new_ScanObj(@args); + return undef if (!defined($self)); + $OWNER{$self} = 1; + my %retval; + tie %retval, "IDZebra::ScanObj", $self; + return bless \%retval, $pkg; +} + +sub DESTROY { + return unless $_[0]->isa('HASH'); + my $self = tied(%{$_[0]}); + return unless defined $self; + delete $ITERATORS{$self}; + if (exists $OWNER{$self}) { + IDZebrac::delete_ScanObj($self); + delete $OWNER{$self}; + } +} + +sub DISOWN { + my $self = shift; + my $ptr = tied(%$self); + delete $OWNER{$ptr}; + }; + +sub ACQUIRE { + my $self = shift; + my $ptr = tied(%$self); + $OWNER{$ptr} = 1; + }; + +sub FETCH { + my ($self,$field) = @_; + my $member_func = "swig_${field}_get"; + my $val = $self->$member_func(); + if (exists $BLESSEDMEMBERS{$field}) { + return undef if (!defined($val)); + my %retval; + tie %retval,$BLESSEDMEMBERS{$field},$val; + return bless \%retval, $BLESSEDMEMBERS{$field}; + } + return $val; +} + +sub STORE { + my ($self,$field,$newval) = @_; + my $member_func = "swig_${field}_set"; + if (exists $BLESSEDMEMBERS{$field}) { + $self->$member_func(tied(%{$newval})); + } else { + $self->$member_func($newval); + } +} + + # ------- VARIABLE STUBS -------- package IDZebra; diff --git a/perl/test.pl b/perl/test.pl index 46144e5..f9b61f5 100755 --- a/perl/test.pl +++ b/perl/test.pl @@ -59,6 +59,9 @@ $sess->end_trans; #$sess->end_trans; $sess->select_databases('Default'); + +goto scan; + $sess->begin_read; #print STDERR "Hits:", $sess->search_pqf('@or @attr 1=4 Filter @attr 1=4 Data1','test_1'), "\n"; #print STDERR "Hits:", $sess->search_pqf('@or @attr 1=4 Filter @attr 1=4 Data1','test_1'), "\n"; @@ -82,10 +85,30 @@ my @recs1 = $rs1->records(from=>1,to=>2); $sess->end_read; -#$sess->commit; + #IDZebra::describe_recordGroup($rep->{rg}); #$rep->update; # print "HOW did we got back???\n"; + +scan: + +my $so = IDZebra::ScanObj->new; +$so->{position} = 1; +$so->{num_entries} = 20; +$so->{is_partial} = 0; +#print STDERR "Pos:$so->{position}\nNum:$so->{num_entries}\nPartial:$so->{is_partial}\n"; + +IDZebra::scan_PQF($sess->{zh}, $so, + $sess->{odr_output}, + "\@attr 1=4 a"); + +#print STDERR "Pos:$so->{position}\nNum:$so->{num_entries}\nPartial:$so->{is_partial}\n"; + +for ($i=1; $i<=$so->{num_entries}; $i++) { + my $se = IDZebra::getScanEntry($so, $i); + print STDERR "$se->{term} ($se->{occurrences})\n"; +} + $sess->close; $service->stop; diff --git a/perl/zebra_api_ext.c b/perl/zebra_api_ext.c index 32440bc..10f0692 100644 --- a/perl/zebra_api_ext.c +++ b/perl/zebra_api_ext.c @@ -213,6 +213,51 @@ int zebra_search_PQF (ZebraHandle zh, return(hits); } +void zebra_scan_PQF (ZebraHandle zh, + ScanObj *so, + ODR stream, + const char *pqf_query) +{ + Z_AttributesPlusTerm *zapt; + Odr_oid *attrsetid; + const char* oidname; + oid_value attributeset; + ZebraScanEntry *entries; + int i, class; + + logf(LOG_DEBUG, + "scan req: pos:%d, num:%d, partial:%d", + so->position, so->num_entries, so->is_partial); + + zapt = p_query_scan (stream, PROTO_Z3950, &attrsetid, pqf_query); + + oidname = yaz_z3950oid_to_str (attrsetid, &class); + logf (LOG_DEBUG, "Attributreset: %s", oidname); + attributeset = oid_getvalbyname(oidname); + + if (!zapt) { + logf (LOG_WARN, "bad query %s\n", pqf_query); + odr_reset (stream); + return; + } + + so->entries = (ScanEntry *) + odr_malloc (stream, sizeof(so->entries) * (so->num_entries)); + + + zebra_scan (zh, stream, zapt, attributeset, + &so->position, &so->num_entries, + (ZebraScanEntry **) &so->entries, &so->is_partial); + + logf(LOG_DEBUG, + "scan res: pos:%d, num:%d, partial:%d", + so->position, so->num_entries, so->is_partial); +} + +ScanEntry *getScanEntry(ScanObj *so, int pos) { + return (&so->entries[pos-1]); +} + /* --------------------------------------------------------------------------- Record retrieval 2 phase retrieval - I didn't manage to return array of blessed references diff --git a/perl/zebra_perl.h b/perl/zebra_perl.h index aadc620..5abd5cc 100644 --- a/perl/zebra_perl.h +++ b/perl/zebra_perl.h @@ -39,4 +39,11 @@ typedef struct { char *term; /* scan term string */ } ScanEntry; +typedef struct { + int num_entries; + int position; + int is_partial; + ScanEntry *entries; +} ScanObj; + #endif -- 1.7.10.4