X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fseshigh.c;h=803f767bf8d35ce520b6a7992a5a2fcc32decb05;hp=25558230b3ef739c8f40f0fdf5b05c1ff199d7a9;hb=3d95738e1464a966faae513cbaff87e9f9ff2b47;hpb=62d24093ae987d90e07a40a8d75f1338b5bbb14b diff --git a/src/seshigh.c b/src/seshigh.c index 2555823..803f767 100644 --- a/src/seshigh.c +++ b/src/seshigh.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2012 Index Data + * Copyright (C) 1995-2013 Index Data * See the file LICENSE for details. */ /** @@ -639,23 +639,57 @@ static int retrieve_fetch(association *assoc, bend_fetch_rr *rr) rr->request_format = backend_syntax; } (*assoc->init->bend_fetch)(assoc->backend, rr); - if (rc && rr->record && rr->errcode == 0 && rr->len > 0) + if (rc && rr->record && rr->errcode == 0) { /* post conversion must take place .. */ WRBUF output_record = wrbuf_alloc(); - int r = yaz_record_conv_record(rc, rr->record, rr->len, output_record); - if (r) - { - const char *details = yaz_record_conv_get_error(rc); - rr->errcode = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS; - if (details) - rr->errstring = odr_strdup(rr->stream, details); + int r = 1; + const char *details = 0; + if (rr->len > 0) + { + r = yaz_record_conv_record(rc, rr->record, rr->len, output_record); + if (r) + details = yaz_record_conv_get_error(rc); + } + else if (rr->len == -1 && rr->output_format && + !oid_oidcmp(rr->output_format, yaz_oid_recsyn_opac)) + { + r = yaz_record_conv_opac_record( + rc, (Z_OPACRecord *) rr->record, output_record); + if (r) + details = yaz_record_conv_get_error(rc); + } + if (r == 0 && match_syntax && + !oid_oidcmp(match_syntax, yaz_oid_recsyn_opac)) + { + yaz_marc_t mt = yaz_marc_create(); + Z_OPACRecord *opac = 0; + if (yaz_xml_to_opac(mt, wrbuf_buf(output_record), + wrbuf_len(output_record), + &opac, 0 /* iconv */, rr->stream->mem, 0) + && opac) + { + rr->len = -1; + rr->record = (char *) opac; + } + else + { + details = "XML to OPAC conversion failed"; + r = 1; + } + yaz_marc_destroy(mt); } - else + else if (r == 0) { rr->len = wrbuf_len(output_record); rr->record = (char *) odr_malloc(rr->stream, rr->len); memcpy(rr->record, wrbuf_buf(output_record), rr->len); } + if (r) + { + rr->errcode = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS; + if (details) + rr->errstring = odr_strdup(rr->stream, details); + } wrbuf_destroy(output_record); } if (match_syntax) @@ -671,7 +705,7 @@ static int retrieve_fetch(association *assoc, bend_fetch_rr *rr) static int srw_bend_fetch(association *assoc, int pos, Z_SRW_searchRetrieveRequest *srw_req, Z_SRW_record *record, - const char **addinfo) + const char **addinfo, int *last_in_set) { bend_fetch_rr rr; ODR o = assoc->encode; @@ -730,6 +764,8 @@ static int srw_bend_fetch(association *assoc, int pos, retrieve_fetch(assoc, &rr); + *last_in_set = rr.last_in_set; + if (rr.errcode && rr.surrogate_flag) { int code = yaz_diag_bib1_to_srw(rr.errcode); @@ -894,6 +930,8 @@ static void srw_bend_search(association *assoc, rr.query->u.type_1 = 0; rr.extra_args = sr->extra_args; rr.extra_response_data = 0; + rr.present_number = srw_req->maximumRecords ? + *srw_req->maximumRecords : 0; if (srw_req->query_type == Z_SRW_query_type_cql) { @@ -1088,6 +1126,7 @@ static void srw_bend_search(association *assoc, for (i = 0; irecords[j].recordPacking = packing; @@ -1096,7 +1135,7 @@ static void srw_bend_search(association *assoc, yaz_log(YLOG_DEBUG, "srw_bend_fetch %d", i+start); errcode = srw_bend_fetch(assoc, i+start, srw_req, srw_res->records + j, - &addinfo); + &addinfo, &last_in_set); if (errcode) { yaz_add_srw_diagnostic(assoc->encode, @@ -1109,6 +1148,8 @@ static void srw_bend_search(association *assoc, } if (srw_res->records[j].recordData_buf) j++; + if (last_in_set) + break; } srw_res->num_records = j; if (!j) @@ -2595,6 +2636,8 @@ static Z_Records *pack_records(association *a, char *setname, Odr_int start, return 0; reclist->records[reclist->num_records] = thisrec; reclist->num_records++; + if (freq.last_in_set) + break; } *num = reclist->num_records; return records; @@ -2643,6 +2686,7 @@ static Z_APDU *process_searchRequest(association *assoc, request *reqb) bsrr->errstring = NULL; bsrr->search_info = NULL; bsrr->search_input = req->otherInfo; + bsrr->present_number = *req->mediumSetPresentNumber; if (assoc->server && assoc->server->cql_transform && req->query->which == Z_Query_type_104