X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=ztest%2Fztest.c;h=1f09c41050c02806672986cca9d0464f070c929f;hp=0a58c958e693794a2a13fa64bad7a0543e95abd5;hb=8121243279bcd990bbbca2b80715467472003565;hpb=ca1469bd104ff54c175f0ad25afc4cbf6d948551 diff --git a/ztest/ztest.c b/ztest/ztest.c index 0a58c95..1f09c41 100644 --- a/ztest/ztest.c +++ b/ztest/ztest.c @@ -1,16 +1,18 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2010 Index Data + * Copyright (C) 1995-2011 Index Data * See the file LICENSE for details. */ - /** \file * \brief yaz-ztest Generic Frontend Server */ +#if HAVE_CONFIG_H +#include +#endif + #include #include #include -#include #if HAVE_SYS_TIME_H #include @@ -210,8 +212,8 @@ static void ztest_sleep(double d) Sleep( (DWORD) (d * 1000)); #else struct timeval tv; - tv.tv_sec = floor(d); - tv.tv_usec = (d - floor(d)) * 1000000; + tv.tv_sec = d; + tv.tv_usec = (d - (long) d) * 1000000; select(0, 0, 0, 0, &tv); #endif } @@ -228,36 +230,66 @@ static void do_delay(const struct delay *delayp) } } -static void addterms(ODR odr, Z_FacetField *facet_field) { +static void addterms(ODR odr, Z_FacetField *facet_field, const char *facet_name) +{ int index; int freq = 100; - const char *key = "key"; - for (index = 0; index < facet_field->num_terms; index++) { - Z_FacetTerm *facet_term = facet_term_create(odr, term_create(odr, key), freq); + int length = strlen(facet_name) + 10; + char *key = odr_malloc(odr, length); + key[0] = '\0'; + for (index = 0; index < facet_field->num_terms; index++) + { + Z_FacetTerm *facet_term; + sprintf(key, "%s%d", facet_name, index); + yaz_log(YLOG_DEBUG, "facet add term %s %d %s", facet_name, index, key); + + facet_term = facet_term_create_cstr(odr, key, freq); freq = freq - 10 ; facet_field_term_set(odr, facet_field, facet_term, index); } } + Z_OtherInformation *build_facet_response(ODR odr, Z_FacetList *facet_list) { - int index; - Z_OtherInformation *oi = odr_malloc(odr, sizeof(*oi)); - Z_OtherInformationUnit *oiu = odr_malloc(odr, sizeof(*oiu)); + int index, new_index = 0; Z_FacetList *new_list = facet_list_create(odr, facet_list->num); for (index = 0; index < facet_list->num; index++) { - new_list->elements[index] = facet_field_create(odr, facet_list->elements[index]->attributes, 3); - addterms(odr, facet_list->elements[index]); + struct yaz_facet_attr attrvalues; + yaz_facet_attr_init(&attrvalues); + attrvalues.limit = 10; + yaz_facet_attr_get_z_attributes(facet_list->elements[index]->attributes, + &attrvalues); + yaz_log(YLOG_LOG, "Attributes: %s %d ", attrvalues.useattr, attrvalues.limit); + if (attrvalues.errstring) + yaz_log(YLOG_LOG, "Error parsing attributes: %s", attrvalues.errstring); + if (attrvalues.limit > 0 && attrvalues.useattr) { + new_list->elements[new_index] = facet_field_create(odr, facet_list->elements[index]->attributes, attrvalues.limit); + addterms(odr, new_list->elements[new_index], attrvalues.useattr); + new_index++; + } + else { + yaz_log(YLOG_DEBUG, "Facet: skipping %s due to 0 limit.", attrvalues.useattr); + } + + } + new_list->num = new_index; + if (new_index > 0) { + Z_OtherInformation *oi = odr_malloc(odr, sizeof(*oi)); + Z_OtherInformationUnit *oiu = odr_malloc(odr, sizeof(*oiu)); + oi->num_elements = 1; + oi->list = odr_malloc(odr, oi->num_elements * sizeof(*oi->list)); + oiu->category = 0; + oiu->which = Z_OtherInfo_externallyDefinedInfo; + oiu->information.externallyDefinedInfo = odr_malloc(odr, sizeof(*oiu->information.externallyDefinedInfo)); + oiu->information.externallyDefinedInfo->direct_reference = odr_oiddup(odr, yaz_oid_userinfo_facet_1); + oiu->information.externallyDefinedInfo->descriptor = 0; + oiu->information.externallyDefinedInfo->indirect_reference = 0; + oiu->information.externallyDefinedInfo->which = Z_External_userFacets; + oiu->information.externallyDefinedInfo->u.facetList = new_list; + oi->list[0] = oiu; + return oi; } - oi->num_elements = 1; - oi->list = odr_malloc(odr, oi->num_elements * sizeof(*oi->list)); - oiu->category = 0; - oiu->which = Z_OtherInfo_externallyDefinedInfo; - oiu->information.externallyDefinedInfo = odr_malloc(odr, sizeof(*oiu->information.externallyDefinedInfo)); - oiu->information.externallyDefinedInfo->direct_reference = odr_oiddup(odr, yaz_oid_userinfo_facet_1); - oiu->information.externallyDefinedInfo->which = Z_External_userFacets; - oiu->information.externallyDefinedInfo->u.facetList = facet_list; - oi->list[0] = oiu; - return oi; + return 0; } int ztest_search(void *handle, bend_search_rr *rr) @@ -367,11 +399,14 @@ int ztest_search(void *handle, bend_search_rr *rr) if (1) { - /* TODO Not general. Only handles one (Facet) OtherInformation. Overwrite */ - Z_FacetList *facet_list = extract_facet_request(rr->stream, rr->search_input); + Z_FacetList *facet_list = yaz_oi_get_facetlist(&rr->search_input); if (facet_list) { + yaz_log(YLOG_LOG, "%d Facets in search request.", facet_list->num); rr->search_info = build_facet_response(rr->stream, facet_list); } + else + yaz_log(YLOG_DEBUG, "No facets parsed search request."); + } do_delay(&new_set->search_delay); new_set->hits = rr->hits; @@ -975,8 +1010,8 @@ int ztest_scan(void *handle, bend_scan_rr *q) strcpy(term, "0"); for (p = term; *p; p++) - if (islower(*(unsigned char *) p)) - *p = toupper(*p); + if (yaz_islower(*p)) + *p = yaz_toupper(*p); fseek(f, 0, SEEK_SET); q->num_entries = 0;