From: Adam Dickmeiss Date: Mon, 2 Sep 2013 13:49:04 +0000 (+0200) Subject: Refactor for string based queruType (SRU 2.0) X-Git-Tag: v5.0.0~71 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=1331fd610a8bfc1e5a849d2c4d598c11557a8372;p=yaz-moved-to-github.git Refactor for string based queruType (SRU 2.0) --- diff --git a/client/client.c b/client/client.c index 0147b06..925c503 100644 --- a/client/client.c +++ b/client/client.c @@ -1417,12 +1417,12 @@ static int send_SRW_scanRequest(const char *arg, Odr_int *pos, int num) switch (queryType) { case QueryType_CQL: - sr->u.scan_request->query_type = Z_SRW_query_type_cql; - sr->u.scan_request->scanClause.cql = encode_SRW_term(out, arg); + sr->u.scan_request->queryType = "cql"; + sr->u.scan_request->scanClause = encode_SRW_term(out, arg); break; case QueryType_Prefix: - sr->u.scan_request->query_type = Z_SRW_query_type_pqf; - sr->u.scan_request->scanClause.pqf = encode_SRW_term(out, arg); + sr->u.scan_request->queryType = "pqf"; + sr->u.scan_request->scanClause = encode_SRW_term(out, arg); break; default: printf("Only CQL and PQF supported in SRW\n"); @@ -1456,18 +1456,18 @@ static int send_SRW_searchRequest(const char *arg) switch (queryType) { case QueryType_CQL: - srw_sr->u.request->query_type = Z_SRW_query_type_cql; - srw_sr->u.request->query.cql = encode_SRW_term(srw_sr_odr_out, arg); + srw_sr->u.request->queryType = "cql"; + srw_sr->u.request->query = encode_SRW_term(srw_sr_odr_out, arg); - sr->u.request->query_type = Z_SRW_query_type_cql; - sr->u.request->query.cql = encode_SRW_term(srw_sr_odr_out, arg); + sr->u.request->queryType = "cql"; + sr->u.request->query = encode_SRW_term(srw_sr_odr_out, arg); break; case QueryType_Prefix: - srw_sr->u.request->query_type = Z_SRW_query_type_pqf; - srw_sr->u.request->query.pqf = encode_SRW_term(srw_sr_odr_out, arg); + srw_sr->u.request->queryType = "pqf"; + srw_sr->u.request->query = encode_SRW_term(srw_sr_odr_out, arg); - sr->u.request->query_type = Z_SRW_query_type_pqf; - sr->u.request->query.pqf = encode_SRW_term(srw_sr_odr_out, arg); + sr->u.request->queryType = "pqf"; + sr->u.request->query = encode_SRW_term(srw_sr_odr_out, arg); break; default: printf("Only CQL and PQF supported in SRW\n"); diff --git a/include/yaz/srw.h b/include/yaz/srw.h index 556d7e7..9dfc82b 100644 --- a/include/yaz/srw.h +++ b/include/yaz/srw.h @@ -66,15 +66,8 @@ typedef struct { typedef struct { -#define Z_SRW_query_type_cql 1 -#define Z_SRW_query_type_xcql 2 -#define Z_SRW_query_type_pqf 3 - int query_type; - union { - char *cql; - char *xcql; - char *pqf; - } query; + char *queryType; + char *query; #define Z_SRW_sort_type_none 1 #define Z_SRW_sort_type_sort 2 @@ -127,12 +120,8 @@ typedef struct { } Z_SRW_explainResponse; typedef struct { - int query_type; - union { - char *cql; - char *xcql; - char *pqf; - } scanClause; + char *queryType; + char *scanClause; Odr_int *responsePosition; Odr_int *maximumTerms; char *stylesheet; diff --git a/src/rpn2solr.c b/src/rpn2solr.c index 16f9f24..085de95 100644 --- a/src/rpn2solr.c +++ b/src/rpn2solr.c @@ -210,9 +210,9 @@ static int rpn2solr_simple(solr_transform_t ct, const char *sterm = 0; size_t lterm = 0; Odr_int trunc = get_truncation(apt); + char *close_range = 0; wrbuf_rewind(w); - char *close_range = 0; ret = rpn2solr_attr(ct, apt->attributes, w, &close_range); if (trunc == 0 || trunc == 1 || trunc == 100 || trunc == 104) diff --git a/src/seshigh.c b/src/seshigh.c index 3b49190..30bf9e2 100644 --- a/src/seshigh.c +++ b/src/seshigh.c @@ -933,11 +933,11 @@ static void srw_bend_search(association *assoc, rr.present_number = srw_req->maximumRecords ? *srw_req->maximumRecords : 0; - if (srw_req->query_type == Z_SRW_query_type_cql) + if (!srw_req->queryType || !strcmp(srw_req->queryType, "cql")) { if (assoc->server && assoc->server->cql_transform) { - int srw_errcode = cql2pqf(assoc->encode, srw_req->query.cql, + int srw_errcode = cql2pqf(assoc->encode, srw_req->query, assoc->server->cql_transform, rr.query, &rr.srw_sortKeys); @@ -959,21 +959,20 @@ static void srw_bend_search(association *assoc, ext->indirect_reference = 0; ext->descriptor = 0; ext->which = Z_External_CQL; - ext->u.cql = srw_req->query.cql; + ext->u.cql = srw_req->query; rr.query->which = Z_Query_type_104; rr.query->u.type_104 = ext; } } - else if (srw_req->query_type == Z_SRW_query_type_pqf) + else if (!strcmp(srw_req->queryType, "pqf")) { Z_RPNQuery *RPNquery; YAZ_PQF_Parser pqf_parser; pqf_parser = yaz_pqf_create(); - RPNquery = yaz_pqf_parse(pqf_parser, assoc->decode, - srw_req->query.pqf); + RPNquery = yaz_pqf_parse(pqf_parser, assoc->decode, srw_req->query); if (!RPNquery) { const char *pqf_msg; @@ -1175,21 +1174,8 @@ static void srw_bend_search(association *assoc, } if (log_request) { - const char *querystr = "?"; - const char *querytype = "?"; WRBUF wr = wrbuf_alloc(); - switch (srw_req->query_type) - { - case Z_SRW_query_type_cql: - querytype = "CQL"; - querystr = srw_req->query.cql; - break; - case Z_SRW_query_type_pqf: - querytype = "PQF"; - querystr = srw_req->query.pqf; - break; - } wrbuf_printf(wr, "SRWSearch %s ", srw_req->database); if (srw_res->num_diagnostics) wrbuf_printf(wr, "ERROR %s", srw_res->diagnostics[0].uri); @@ -1206,7 +1192,8 @@ static void srw_bend_search(association *assoc, srw_res->resultSetId : "-"), (srw_req->startRecord ? *srw_req->startRecord : 1), srw_res->num_records); - yaz_log(log_request, "%s %s: %s", wrbuf_cstr(wr), querytype, querystr); + yaz_log(log_request, "%s %s: %s", wrbuf_cstr(wr), srw_req->queryType, + srw_req->query); wrbuf_destroy(wr); } } @@ -1349,20 +1336,20 @@ static void srw_bend_scan(association *assoc, } save_entries = bsrr->entries; /* save it so we can compare later */ - if (srw_req->query_type == Z_SRW_query_type_pqf && + if (srw_req->queryType && !strcmp(srw_req->queryType, "pqf") && assoc->init->bend_scan) { YAZ_PQF_Parser pqf_parser = yaz_pqf_create(); bsrr->term = yaz_pqf_scan(pqf_parser, assoc->decode, &bsrr->attributeset, - srw_req->scanClause.pqf); + srw_req->scanClause); yaz_pqf_destroy(pqf_parser); bsrr->scanClause = 0; ((int (*)(void *, bend_scan_rr *)) (*assoc->init->bend_scan))(assoc->backend, bsrr); } - else if (srw_req->query_type == Z_SRW_query_type_cql + else if ((!srw_req->queryType || !strcmp(srw_req->queryType, "cql")) && assoc->init->bend_scan && assoc->server && assoc->server->cql_transform) { @@ -1372,7 +1359,7 @@ static void srw_bend_scan(association *assoc, bsrr->term = (Z_AttributesPlusTerm *) odr_malloc(assoc->decode, sizeof(*bsrr->term)); srw_error = cql2pqf_scan(assoc->encode, - srw_req->scanClause.cql, + srw_req->scanClause, assoc->server->cql_transform, bsrr->term); if (srw_error) @@ -1385,12 +1372,12 @@ static void srw_bend_scan(association *assoc, (*assoc->init->bend_scan))(assoc->backend, bsrr); } } - else if (srw_req->query_type == Z_SRW_query_type_cql + else if ((!srw_req->queryType || !strcmp(srw_req->queryType, "cql")) && assoc->init->bend_srw_scan) { bsrr->term = 0; bsrr->attributeset = 0; - bsrr->scanClause = srw_req->scanClause.cql; + bsrr->scanClause = srw_req->scanClause; ((int (*)(void *, bend_scan_rr *)) (*assoc->init->bend_srw_scan))(assoc->backend, bsrr); } @@ -1451,24 +1438,6 @@ static void srw_bend_scan(association *assoc, if (log_request) { WRBUF wr = wrbuf_alloc(); - const char *querytype = 0; - const char *querystr = 0; - - switch(srw_req->query_type) - { - case Z_SRW_query_type_pqf: - querytype = "PQF"; - querystr = srw_req->scanClause.pqf; - break; - case Z_SRW_query_type_cql: - querytype = "CQL"; - querystr = srw_req->scanClause.cql; - break; - default: - querytype = "UNKNOWN"; - querystr = ""; - } - wrbuf_printf(wr, "SRWScan %s ", srw_req->database); if (srw_res->num_diagnostics) @@ -1484,7 +1453,7 @@ static void srw_bend_scan(association *assoc, (srw_req->maximumTerms ? *srw_req->maximumTerms : 1)); /* there is no step size in SRU/W ??? */ - wrbuf_printf(wr, "%s: %s ", querytype, querystr); + wrbuf_printf(wr, "%s: %s ", srw_req->queryType, srw_req->scanClause); yaz_log(log_request, "%s ", wrbuf_cstr(wr) ); wrbuf_destroy(wr); } diff --git a/src/solr.c b/src/solr.c index 088fb63..ca35e56 100644 --- a/src/solr.c +++ b/src/solr.c @@ -461,19 +461,10 @@ int yaz_solr_encode_request(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu, { Z_SRW_searchRetrieveRequest *request = srw_pdu->u.request; solr_op = "select"; - switch (srw_pdu->u.request->query_type) - { - case Z_SRW_query_type_pqf: - yaz_add_name_value_str(encode, name, value, &i, - "q", request->query.pqf); - break; - case Z_SRW_query_type_cql: - yaz_add_name_value_str(encode, name, value, &i, - "q", request->query.cql); - break; - default: + if (!srw_pdu->u.request->query) return -1; - } + /* not considering query type here ! */ + yaz_add_name_value_str(encode, name, value, &i, "q", request->query); if (srw_pdu->u.request->startRecord) { Odr_int start = *request->startRecord - 1; @@ -506,32 +497,33 @@ int yaz_solr_encode_request(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu, else if (srw_pdu->which == Z_SRW_scan_request) { Z_SRW_scanRequest *request = srw_pdu->u.scan_request; solr_op = "terms"; - switch (srw_pdu->u.scan_request->query_type) + if (!srw_pdu->u.scan_request->scanClause) + return -1; + if (!strcmp(srw_pdu->u.scan_request->queryType, "pqf")) { - case Z_SRW_query_type_pqf: + yaz_add_name_value_str(encode, name, value, &i, + "terms.fl", request->scanClause); + yaz_add_name_value_str(encode, name, value, &i, + "terms.lower", request->scanClause); + } + else if (!strcmp(srw_pdu->u.scan_request->queryType, "cql")) + { + q = request->scanClause; + pos = strchr(q, ':'); + if (pos != NULL) { yaz_add_name_value_str(encode, name, value, &i, - "terms.fl", request->scanClause.pqf); + "terms.lower", odr_strdup(encode, pos + 1)); + *pos = '\0'; yaz_add_name_value_str(encode, name, value, &i, - "terms.lower", request->scanClause.pqf); - break; - case Z_SRW_query_type_cql: - q = request->scanClause.cql; - pos = strchr(q, ':'); - if (pos != NULL) { - yaz_add_name_value_str(encode, name, value, &i, - "terms.lower", odr_strdup(encode, pos + 1)); - *pos = '\0'; - yaz_add_name_value_str(encode, name, value, &i, - "terms.fl", odr_strdup(encode, q)); - *pos = ':'; - } else { - yaz_add_name_value_str(encode, name, value, &i, - "terms.lower", odr_strdup(encode, q)); - } - break; - default: - return -1; + "terms.fl", odr_strdup(encode, q)); + *pos = ':'; + } else { + yaz_add_name_value_str(encode, name, value, &i, + "terms.lower", odr_strdup(encode, q)); + } } + else + return -1; yaz_add_name_value_str(encode, name, value, &i, "terms.sort", "index"); yaz_add_name_value_int(encode, name, value, &i, diff --git a/src/srw.c b/src/srw.c index d4fbfc6..82e1acd 100644 --- a/src/srw.c +++ b/src/srw.c @@ -753,8 +753,8 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, (*p)->which = Z_SRW_searchRetrieve_request; req = (*p)->u.request = (Z_SRW_searchRetrieveRequest *) odr_malloc(o, sizeof(*req)); - req->query_type = Z_SRW_query_type_cql; - req->query.cql = 0; + req->queryType = "cql"; + req->query = 0; req->sort_type = Z_SRW_sort_type_none; req->sort.none = 0; req->startRecord = 0; @@ -771,15 +771,18 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, if (match_xsd_string(ptr, "version", o, &(*p)->srw_version)) ; + else if (match_xsd_string(ptr, "queryType", o, + &req->queryType)) + ; else if (match_xsd_string(ptr, "query", o, - &req->query.cql)) - req->query_type = Z_SRW_query_type_cql; + &req->query)) + ; else if (match_xsd_string(ptr, "pQuery", o, - &req->query.pqf)) - req->query_type = Z_SRW_query_type_pqf; + &req->query)) + req->queryType = "pqf"; else if (match_xsd_string(ptr, "xQuery", o, - &req->query.xcql)) - req->query_type = Z_SRW_query_type_xcql; + &req->query)) + req->queryType = "xcql"; else if (match_xsd_integer(ptr, "startRecord", o, &req->startRecord)) ; @@ -807,7 +810,7 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, else match_xsd_string(ptr, "database", o, &req->database); } - if (!req->query.cql && !req->query.pqf && !req->query.xcql) + if (!req->query) { /* should put proper diagnostic here */ return -1; @@ -938,8 +941,8 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, (*p)->which = Z_SRW_scan_request; req = (*p)->u.scan_request = (Z_SRW_scanRequest *) odr_malloc(o, sizeof(*req)); - req->query_type = Z_SRW_query_type_cql; - req->scanClause.cql = 0; + req->queryType = "cql"; + req->scanClause = 0; req->responsePosition = 0; req->maximumTerms = 0; req->stylesheet = 0; @@ -955,12 +958,12 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, &(*p)->extraResponseData_len)) ; else if (match_xsd_string(ptr, "scanClause", o, - &req->scanClause.cql)) + &req->scanClause)) ; else if (match_xsd_string(ptr, "pScanClause", o, - &req->scanClause.pqf)) + &req->scanClause)) { - req->query_type = Z_SRW_query_type_pqf; + req->queryType = "pqf"; } else if (match_xsd_integer(ptr, "responsePosition", o, &req->responsePosition)) @@ -1025,23 +1028,28 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, if ((*p)->which == Z_SRW_searchRetrieve_request) { Z_SRW_searchRetrieveRequest *req = (*p)->u.request; + const char *queryType = req->queryType; ptr = xmlNewChild(pptr, 0, BAD_CAST "searchRetrieveRequest", 0); ns_srw = xmlNewNs(ptr, BAD_CAST ns, BAD_CAST "zs"); xmlSetNs(ptr, ns_srw); if ((*p)->srw_version) add_xsd_string(ptr, "version", (*p)->srw_version); - switch (req->query_type) + + if (strcmp((*p)->srw_version, "2.") > 0) { - case Z_SRW_query_type_cql: - add_xsd_string(ptr, "query", req->query.cql); - break; - case Z_SRW_query_type_xcql: - add_xsd_string(ptr, "xQuery", req->query.xcql); - break; - case Z_SRW_query_type_pqf: - add_xsd_string(ptr, "pQuery", req->query.pqf); - break; + if (queryType) + add_xsd_string(ptr, "queryType", queryType); + add_xsd_string(ptr, "query", req->query); + } + else + { + if (!queryType || !strcmp(queryType, "cql")) + add_xsd_string(ptr, "query", req->query); + else if (!strcmp(queryType, "xcql")) + add_xsd_string(ptr, "xQuery", req->query); + else if (!strcmp(queryType, "pqf")) + add_xsd_string(ptr, "pQuery", req->query); } add_xsd_integer(ptr, "startRecord", req->startRecord); add_xsd_integer(ptr, "maximumRecords", req->maximumRecords); @@ -1129,19 +1137,25 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, else if ((*p)->which == Z_SRW_scan_request) { Z_SRW_scanRequest *req = (*p)->u.scan_request; + const char *queryType = req->queryType; ptr = xmlNewChild(pptr, 0, BAD_CAST "scanRequest", 0); ns_srw = xmlNewNs(ptr, BAD_CAST ns, BAD_CAST "zs"); xmlSetNs(ptr, ns_srw); add_xsd_string(ptr, "version", (*p)->srw_version); - switch (req->query_type) + + if (strcmp((*p)->srw_version, "2.") > 0) { - case Z_SRW_query_type_cql: - add_xsd_string(ptr, "scanClause", req->scanClause.cql); - break; - case Z_SRW_query_type_pqf: - add_xsd_string(ptr, "pScanClause", req->scanClause.pqf); - break; + if (queryType && strcmp(queryType, "cql")) + add_xsd_string(ptr, "queryType", queryType); + add_xsd_string(ptr, "scanClause", req->scanClause); + } + else + { + if (!queryType || !strcmp(queryType, "cql")) + add_xsd_string(ptr, "scanClause", req->scanClause); + else if (!strcmp(queryType, "pqf")) + add_xsd_string(ptr, "pScanClause", req->scanClause); } add_xsd_integer(ptr, "responsePosition", req->responsePosition); add_xsd_integer(ptr, "maximumTerms", req->maximumTerms); diff --git a/src/srwutil.c b/src/srwutil.c index 38ee0d0..9420a21 100644 --- a/src/srwutil.c +++ b/src/srwutil.c @@ -378,13 +378,12 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, const char *operation = 0; char *version = 0; char *query = 0; - char *pQuery = 0; + char *queryType = "cql"; char *username = 0; char *password = 0; char *sortKeys = 0; char *stylesheet = 0; char *scanClause = 0; - char *pScanClause = 0; char *recordXPath = 0; char *recordSchema = 0; char *recordPacking = "xml"; /* xml packing is default for SRU */ @@ -422,7 +421,12 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, if (!strcmp(n, "query")) query = v; else if (!strcmp(n, "x-pquery")) - pQuery = v; + { + query = v; + queryType = "pqf"; + } + else if (!strcmp(n, "queryType")) + queryType = v; else if (!strcmp(n, "x-username")) username = v; else if (!strcmp(n, "x-password")) @@ -444,7 +448,10 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, else if (!strcmp(n, "scanClause")) scanClause = v; else if (!strcmp(n, "x-pScanClause")) - pScanClause = v; + { + scanClause = v; + queryType = "pqf"; + } else if (!strcmp(n, "maximumRecords")) maximumRecords = v; else if (!strcmp(n, "startRecord")) @@ -507,17 +514,11 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, sr->extra_args = extra_args; *srw_pdu = sr; yaz_srw_decodeauth(sr, hreq, username, password, decode); - if (query) - { - sr->u.request->query_type = Z_SRW_query_type_cql; - sr->u.request->query.cql = query; - } - else if (pQuery) - { - sr->u.request->query_type = Z_SRW_query_type_pqf; - sr->u.request->query.pqf = pQuery; - } - else + + sr->u.request->queryType = queryType; + sr->u.request->query = query; + + if (!query) yaz_add_srw_diagnostic( decode, diag, num_diag, YAZ_SRW_MANDATORY_PARAMETER_NOT_SUPPLIED, "query"); @@ -598,17 +599,10 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, *srw_pdu = sr; yaz_srw_decodeauth(sr, hreq, username, password, decode); - if (scanClause) - { - sr->u.scan_request->query_type = Z_SRW_query_type_cql; - sr->u.scan_request->scanClause.cql = scanClause; - } - else if (pScanClause) - { - sr->u.scan_request->query_type = Z_SRW_query_type_pqf; - sr->u.scan_request->scanClause.pqf = pScanClause; - } - else + sr->u.scan_request->queryType = queryType; + sr->u.scan_request->scanClause = scanClause; + + if (!scanClause) yaz_add_srw_diagnostic( decode, diag, num_diag, YAZ_SRW_MANDATORY_PARAMETER_NOT_SUPPLIED, "scanClause"); @@ -744,8 +738,8 @@ Z_SRW_PDU *yaz_srw_get_pdu(ODR o, int which, const char *version) case Z_SRW_searchRetrieve_request: sr->u.request = (Z_SRW_searchRetrieveRequest *) odr_malloc(o, sizeof(*sr->u.request)); - sr->u.request->query_type = Z_SRW_query_type_cql; - sr->u.request->query.cql = 0; + sr->u.request->queryType = "cql"; + sr->u.request->query = 0; sr->u.request->sort_type = Z_SRW_sort_type_none; sr->u.request->sort.none = 0; sr->u.request->startRecord = 0; @@ -800,8 +794,8 @@ Z_SRW_PDU *yaz_srw_get_pdu(ODR o, int which, const char *version) sr->u.scan_request->stylesheet = 0; sr->u.scan_request->maximumTerms = 0; sr->u.scan_request->responsePosition = 0; - sr->u.scan_request->query_type = Z_SRW_query_type_cql; - sr->u.scan_request->scanClause.cql = 0; + sr->u.scan_request->queryType = "cql"; + sr->u.scan_request->scanClause = 0; break; case Z_SRW_scan_response: sr->u.scan_response = (Z_SRW_scanResponse *) @@ -869,28 +863,40 @@ static int yaz_get_sru_parms(const Z_SRW_PDU *srw_pdu, ODR encode, char **name, char **value, int max_names) { int i = 0; + char *queryType; yaz_add_name_value_str(encode, name, value, &i, "version", srw_pdu->srw_version); name[i] = "operation"; - switch(srw_pdu->which) + switch (srw_pdu->which) { case Z_SRW_searchRetrieve_request: value[i++] = "searchRetrieve"; - switch(srw_pdu->u.request->query_type) + queryType = srw_pdu->u.request->queryType; + if (strcmp(srw_pdu->srw_version, "2.") > 0) { - case Z_SRW_query_type_cql: + yaz_add_name_value_str(encode, name, value, &i, "queryType", + queryType); yaz_add_name_value_str(encode, name, value, &i, "query", - srw_pdu->u.request->query.cql); - break; - case Z_SRW_query_type_pqf: - yaz_add_name_value_str(encode, name, value, &i, "x-pquery", - srw_pdu->u.request->query.pqf); - break; - case Z_SRW_query_type_xcql: - yaz_add_name_value_str(encode, name, value, &i, "x-cql", - srw_pdu->u.request->query.xcql); - break; + srw_pdu->u.request->query); + } + else + { + if (!strcmp(queryType, "cql")) + { + yaz_add_name_value_str(encode, name, value, &i, "query", + srw_pdu->u.request->query); + } + else if (!strcmp(queryType, "pqf")) + { + yaz_add_name_value_str(encode, name, value, &i, "x-pquery", + srw_pdu->u.request->query); + } + else if (!strcmp(queryType, "pqf")) + { + yaz_add_name_value_str(encode, name, value, &i, "x-cql", + srw_pdu->u.request->query); + } } - switch(srw_pdu->u.request->sort_type) + switch (srw_pdu->u.request->sort_type) { case Z_SRW_sort_type_none: break; @@ -921,21 +927,27 @@ static int yaz_get_sru_parms(const Z_SRW_PDU *srw_pdu, ODR encode, break; case Z_SRW_scan_request: value[i++] = "scan"; - - switch(srw_pdu->u.scan_request->query_type) + queryType = srw_pdu->u.request->queryType; + if (strcmp(srw_pdu->srw_version, "2.") > 0) { - case Z_SRW_query_type_cql: - yaz_add_name_value_str(encode, name, value, &i, "scanClause", - srw_pdu->u.scan_request->scanClause.cql); - break; - case Z_SRW_query_type_pqf: - yaz_add_name_value_str(encode, name, value, &i, "x-pScanClause", - srw_pdu->u.scan_request->scanClause.pqf); - break; - case Z_SRW_query_type_xcql: - yaz_add_name_value_str(encode, name, value, &i, "x-cqlScanClause", - srw_pdu->u.scan_request->scanClause.xcql); - break; + if (queryType && strcmp(queryType, "cql")) + yaz_add_name_value_str(encode, name, value, &i, "queryType", + queryType); + yaz_add_name_value_str(encode, name, value, &i, "query", + srw_pdu->u.request->query); + } + else + { + if (!queryType || !strcmp(queryType, "cql")) + yaz_add_name_value_str(encode, name, value, &i, "scanClause", + srw_pdu->u.scan_request->scanClause); + else if (!strcmp(queryType, "pqf")) + yaz_add_name_value_str(encode, name, value, &i, "x-pScanClause", + srw_pdu->u.scan_request->scanClause); + else if (!strcmp(queryType, "xcql")) + yaz_add_name_value_str(encode, name, value, &i, + "x-cqlScanClause", + srw_pdu->u.scan_request->scanClause); } yaz_add_name_value_int(encode, name, value, &i, "responsePosition", srw_pdu->u.scan_request->responsePosition); diff --git a/src/zoom-sru.c b/src/zoom-sru.c index b829738..12f226f 100644 --- a/src/zoom-sru.c +++ b/src/zoom-sru.c @@ -87,15 +87,15 @@ zoom_ret ZOOM_connection_srw_send_scan(ZOOM_connection c) /* SRU scan can only carry CQL and PQF */ if (z_query->which == Z_Query_type_104) { - sr->u.scan_request->query_type = Z_SRW_query_type_cql; - sr->u.scan_request->scanClause.cql = + sr->u.scan_request->queryType = "cql"; + sr->u.scan_request->scanClause = odr_strdup(c->odr_out, ZOOM_query_get_query_string(scan->query)); } else if (z_query->which == Z_Query_type_1 || z_query->which == Z_Query_type_101) { - sr->u.scan_request->query_type = Z_SRW_query_type_pqf; - sr->u.scan_request->scanClause.pqf = + sr->u.scan_request->queryType = "pqf"; + sr->u.scan_request->scanClause = odr_strdup(c->odr_out, ZOOM_query_get_query_string(scan->query)); } else @@ -194,13 +194,13 @@ zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c) if (z_query->which == Z_Query_type_104 && z_query->u.type_104->which == Z_External_CQL) { - sr->u.request->query_type = Z_SRW_query_type_cql; - sr->u.request->query.cql = z_query->u.type_104->u.cql; + sr->u.request->queryType = "cql"; + sr->u.request->query = z_query->u.type_104->u.cql; } else if (z_query->which == Z_Query_type_1 && z_query->u.type_1) { - sr->u.request->query_type = Z_SRW_query_type_pqf; - sr->u.request->query.pqf = + sr->u.request->queryType = "pqf"; + sr->u.request->query = odr_strdup(c->odr_out, ZOOM_query_get_query_string(resultset->query)); } diff --git a/util/srwtst.c b/util/srwtst.c index cd10a51..e62e888 100644 --- a/util/srwtst.c +++ b/util/srwtst.c @@ -53,18 +53,7 @@ int main(int argc, char **argv) if (sr->which == Z_SRW_searchRetrieve_request) { Z_SRW_searchRetrieveRequest *req = sr->u.request; - switch(req->query_type) - { - case Z_SRW_query_type_cql: - fprintf(stderr, "CQL: %s\n", req->query.cql); - break; - case Z_SRW_query_type_xcql: - fprintf(stderr, "XCQL\n"); - break; - case Z_SRW_query_type_pqf: - fprintf(stderr, "PQF: %s\n", req->query.pqf); - break; - } + fprintf(stderr, "%s: %s\n", req->queryType, req->query); } else if (sr->which == Z_SRW_searchRetrieve_response) {