X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fzoom-sru.c;h=bf89a4494fc51265920510ddbda00337298a8ece;hp=ad241cd52dc20c971be5277c9dd25c953153e3db;hb=4d1450cc691292cef5bcfdd41cefc030e4dabbf6;hpb=c65e569219f8a60e2cba17ddc648a48a7b8b5096 diff --git a/src/zoom-sru.c b/src/zoom-sru.c index ad241cd..bf89a44 100644 --- a/src/zoom-sru.c +++ b/src/zoom-sru.c @@ -35,8 +35,7 @@ static zoom_ret send_srw(ZOOM_connection c, Z_SRW_PDU *sr) const char *database = ZOOM_options_get(c->options, "databaseName"); gdu = z_get_HTTP_Request_uri(c->odr_out, c->host_port, - database, - c->proxy ? 1 : 0); + database, c->proxy_mode); if (c->sru_mode == zoom_sru_get) { @@ -145,7 +144,6 @@ zoom_ret ZOOM_connection_srw_send_scan(ZOOM_connection c) #if YAZ_HAVE_XML2 zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c) { - const char *facets = 0; int i; int *start, *count; ZOOM_resultset resultset = 0; @@ -163,43 +161,16 @@ zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c) resultset = c->tasks->u.search.resultset; -#if HAVE_LIBMEMCACHED_MEMCACHED_H - /* TODO: add sorting */ - if (c->mc_st && resultset->live_set == 0) - { - size_t v_len; - uint32_t flags; - memcached_return_t rc; - char *v = memcached_get(c->mc_st, wrbuf_buf(resultset->mc_key), - wrbuf_len(resultset->mc_key), - &v_len, &flags, &rc); - if (v) - { - ZOOM_Event event; - WRBUF w = wrbuf_alloc(); - - wrbuf_write(w, v, v_len); - free(v); - resultset->size = odr_atoi(wrbuf_cstr(w)); - - yaz_log(YLOG_LOG, "For key %s got value %s", - wrbuf_cstr(resultset->mc_key), wrbuf_cstr(w)); + ZOOM_memcached_search(c, resultset); - wrbuf_destroy(w); - event = ZOOM_Event_create(ZOOM_EVENT_RECV_SEARCH); - ZOOM_connection_put_event(c, event); - resultset->live_set = 1; - } - } -#endif if (!resultset->setname) - resultset->setname = xstrdup("default"); + resultset->setname = odr_strdup(resultset->odr, "default"); ZOOM_options_set(resultset->options, "setname", resultset->setname); start = &c->tasks->u.search.start; count = &c->tasks->u.search.count; - facets = ZOOM_options_get(resultset->options, "facets"); - if (facets) - facet_list = yaz_pqf_parse_facet_list(c->odr_out, facets); + if (resultset->req_facets) + facet_list = yaz_pqf_parse_facet_list(c->odr_out, + resultset->req_facets); schema = c->tasks->u.search.schema; if (resultset->live_set) @@ -282,6 +253,7 @@ static zoom_ret handle_srw_response(ZOOM_connection c, Z_SRW_searchRetrieveResponse *res) { ZOOM_resultset resultset = 0; + int *start, *count; int i; NMEM nmem; ZOOM_Event event; @@ -294,6 +266,8 @@ static zoom_ret handle_srw_response(ZOOM_connection c, return zoom_complete; resultset = c->tasks->u.search.resultset; + start = &c->tasks->u.search.start; + count = &c->tasks->u.search.count; syntax = c->tasks->u.search.syntax; elementSetName = c->tasks->u.search.elementSetName; schema = c->tasks->u.search.schema; @@ -322,24 +296,33 @@ static zoom_ret handle_srw_response(ZOOM_connection c, { if (res->numberOfRecords) { - resultset->size = *res->numberOfRecords; -#if HAVE_LIBMEMCACHED_MEMCACHED_H - if (c->mc_st && resultset->live_set == 0) + Z_OtherInformation *oi = 0; + if (res->facetList) { - uint32_t flags = 0; - memcached_return_t rc; - time_t expiration = 36000; - char str[40]; - - sprintf(str, ODR_INT_PRINTF, resultset->size); - rc = memcached_set(c->mc_st, - wrbuf_buf(resultset->mc_key),wrbuf_len(resultset->mc_key), - str, strlen(str), expiration, flags); - yaz_log(YLOG_LOG, "Store SRU hit count key=%s value=%s rc=%u %s", - wrbuf_cstr(resultset->mc_key), str, (unsigned) rc, - memcached_last_error_message(c->mc_st)); + ODR o = c->odr_in; + Z_External *ext = (Z_External *) + odr_malloc(o, sizeof(*ext)); + + ext->which = Z_External_userFacets; + ext->u.facetList = res->facetList; + ext->direct_reference = + odr_oiddup(o, yaz_oid_userinfo_facet_1); + ext->indirect_reference = 0; + ext->descriptor = 0; + oi = (Z_OtherInformation *) odr_malloc(o, sizeof(*oi)); + oi->num_elements = 1; + oi->list = (Z_OtherInformationUnit **) + odr_malloc(o, sizeof(*oi->list)); + oi->list[0] = (Z_OtherInformationUnit *) + odr_malloc(o, sizeof(**oi->list)); + oi->list[0]->category = 0; + oi->list[0]->which = Z_OtherInfo_externallyDefinedInfo; + oi->list[0]->information.externallyDefinedInfo = ext; } -#endif + resultset->size = *res->numberOfRecords; + ZOOM_memcached_hitcount(c, resultset, oi, + res->resultCountPrecision ? + res->resultCountPrecision : "exact"); } resultset->live_set = 2; if (res->suggestions) @@ -393,6 +376,10 @@ static zoom_ret handle_srw_response(ZOOM_connection c, schema, diag); } } + *count -= i; + if (*count < 0) + *count = 0; + *start += i; nmem = odr_extract_mem(c->odr_in); nmem_transfer(odr_getmem(resultset->odr), nmem); nmem_destroy(nmem); @@ -404,14 +391,14 @@ static zoom_ret handle_srw_response(ZOOM_connection c, #endif #if YAZ_HAVE_XML2 -static void handle_srw_scan_response(ZOOM_connection c, - Z_SRW_scanResponse *res) +static zoom_ret handle_srw_scan_response(ZOOM_connection c, + Z_SRW_scanResponse *res) { NMEM nmem = odr_extract_mem(c->odr_in); ZOOM_scanset scan; if (!c->tasks || c->tasks->which != ZOOM_TASK_SCAN) - return; + return zoom_complete; scan = c->tasks->u.scan.scan; if (res->num_diagnostics > 0) @@ -423,6 +410,7 @@ static void handle_srw_scan_response(ZOOM_connection c, ZOOM_options_set_int(scan->options, "number", res->num_terms); nmem_destroy(nmem); + return zoom_complete; } #endif @@ -447,7 +435,7 @@ int ZOOM_handle_sru(ZOOM_connection c, Z_HTTP_Response *hres, if (sr->which == Z_SRW_searchRetrieve_response) *cret = handle_srw_response(c, sr->u.response); else if (sr->which == Z_SRW_scan_response) - handle_srw_scan_response(c, sr->u.scan_response); + *cret = handle_srw_scan_response(c, sr->u.scan_response); } } else @@ -473,7 +461,7 @@ int ZOOM_handle_sru(ZOOM_connection c, Z_HTTP_Response *hres, if (sr->which == Z_SRW_searchRetrieve_response) *cret = handle_srw_response(c, sr->u.response); else if (sr->which == Z_SRW_scan_response) - handle_srw_scan_response(c, sr->u.scan_response); + *cret = handle_srw_scan_response(c, sr->u.scan_response); else ret = -1; }