From: Dennis Schafroth Date: Tue, 24 Aug 2010 15:37:35 +0000 (+0200) Subject: Fix: Work-around since zoom-sru handle_srw_response does not work with zero-based... X-Git-Tag: v4.1.0~39 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=83fe7a135733a28f6baecbfb054271163e8f46f6 Fix: Work-around since zoom-sru handle_srw_response does not work with zero-based records --- diff --git a/src/solr.c b/src/solr.c index eaf822c..dac8587 100644 --- a/src/solr.c +++ b/src/solr.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "sru-p.h" @@ -75,10 +76,12 @@ int yaz_solr_decode_response(ODR o, Z_HTTP_Response *hres, Z_SRW_PDU **pdup) odr_intdup(o, odr_atoi( (const char *) attr->children->content)); + yaz_log(YLOG_DEBUG, "SOLR total results: %d ", atoi( attr->children->content)); } else if (!strcmp((const char *) attr->name, "start")) { start = odr_atoi((const char *) attr->children->content); + yaz_log(YLOG_DEBUG, "SOLR start: %d ", atoi( attr->children->content)); } } } @@ -92,6 +95,7 @@ int yaz_solr_decode_response(ODR o, Z_HTTP_Response *hres, Z_SRW_PDU **pdup) for (node = ptr->children; node; node = node->next) if (node->type == XML_ELEMENT_NODE) sr->num_records++; + yaz_log(YLOG_DEBUG, "SOLR results in response: %d ", sr->num_records); sr->records = odr_malloc(o, sizeof(*sr->records) * sr->num_records); @@ -113,7 +117,9 @@ int yaz_solr_decode_response(ODR o, Z_HTTP_Response *hres, Z_SRW_PDU **pdup) record->recordData_buf = odr_malloc(o, buf->use + 1); memcpy(record->recordData_buf, buf->content, buf->use); record->recordData_buf[buf->use] = '\0'; - record->recordPosition = odr_intdup(o, start + offset); + // TODO Solve the real problem: Making the recordPosition 1-based due to "funny" code in zoom-sru + record->recordPosition = odr_intdup(o, start + offset + 1); + yaz_log(YLOG_DEBUG, "SOLR pos=" ODR_INT_PRINTF, *record->recordPosition); xmlBufferFree(buf); diff --git a/src/zoom-sru.c b/src/zoom-sru.c index 2319387..87155a1 100644 --- a/src/zoom-sru.c +++ b/src/zoom-sru.c @@ -283,8 +283,10 @@ static zoom_ret handle_srw_response(ZOOM_connection c, } else { - if (res->numberOfRecords) + if (res->numberOfRecords) { resultset->size = *res->numberOfRecords; + yaz_log(YLOG_DEBUG, "res numberOfRecords " ODR_INT_PRINTF, *res->numberOfRecords); + } for (i = 0; inum_records; i++) { int pos; @@ -294,12 +296,16 @@ static zoom_ret handle_srw_response(ZOOM_connection c, Z_NamePlusRecord *npr = (Z_NamePlusRecord *) odr_malloc(c->odr_in, sizeof(Z_NamePlusRecord)); - + /* + * TODO This does not work with 0-based recordPositions. + * We will iterate over one twice + */ if (res->records[i].recordPosition && *res->records[i].recordPosition > 0) pos = *res->records[i].recordPosition - 1; else pos = *start + i; + yaz_log(YLOG_DEBUG, "pos %d start %d ", pos, *start); sru_rec = &res->records[i]; @@ -336,9 +342,9 @@ static zoom_ret handle_srw_response(ZOOM_connection c, *start += i; if (*count + *start > resultset->size) *count = resultset->size - *start; + yaz_log(YLOG_DEBUG, "SRU result set size " ODR_INT_PRINTF " start %d count %d", resultset->size, *start, *count); if (*count < 0) *count = 0; - nmem = odr_extract_mem(c->odr_in); nmem_transfer(odr_getmem(resultset->odr), nmem); nmem_destroy(nmem);