X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fretrieve.c;h=aed206026e965e58c0c1cfca16bcb8d62902263c;hb=99b29133f76df10f9dc617a6b2ed876dded7ce52;hp=5b602ed19f532cb2353341994978c09651fcd517;hpb=0ef68e6e54cfd7a91a28ee3b1f305924ac34e787;p=idzebra-moved-to-github.git diff --git a/index/retrieve.c b/index/retrieve.c index 5b602ed..aed2060 100644 --- a/index/retrieve.c +++ b/index/retrieve.c @@ -209,16 +209,6 @@ int zebra_special_sort_fetch( int ord; ZebraHandle zh = fi->zh; - /* only accept XML and SUTRS requests */ - if (oid_oidcmp(input_format, yaz_oid_recsyn_xml) - && oid_oidcmp(input_format, yaz_oid_recsyn_sutrs)) - { - yaz_log(YLOG_WARN, "unsupported format for element set zebra::%s", - elemsetname); - *output_format = 0; - return YAZ_BIB1_NO_SYNTAXES_AVAILABLE_FOR_THIS_REQUEST; - } - if (!parse_zebra_elem(elemsetname, &retrieval_index, &retrieval_index_len, &retrieval_type, &retrieval_type_len)) @@ -248,49 +238,71 @@ int zebra_special_sort_fetch( return -1; /* is not a sort index */ else { - char dst_buf[IT_MAX_WORD]; - WRBUF str = wrbuf_alloc(); + WRBUF wrbuf_str = wrbuf_alloc(); const char *index_type; const char *db = 0; const char *string_index = 0; - WRBUF wrbuf = result; + WRBUF wrbuf_result = result; + int off = 0; - zebra_sort_sysno(zh->reg->sort_index, fi->sysno); - zebra_sort_type(zh->reg->sort_index, ord); - zebra_sort_read(zh->reg->sort_index, str); - - zebraExplain_lookup_ord(zh->reg->zei, ord, &index_type, &db, &string_index); - - zebra_term_untrans(zh, index_type, dst_buf, wrbuf_cstr(str)); - + zebraExplain_lookup_ord(zh->reg->zei, ord, &index_type, &db, + &string_index); if (!oid_oidcmp(input_format, yaz_oid_recsyn_xml)) { *output_format = yaz_oid_recsyn_xml; - wrbuf_printf(wrbuf, ZEBRA_XML_HEADER_STR + wrbuf_printf(wrbuf_result, ZEBRA_XML_HEADER_STR " sysno=\"" ZINT_FORMAT "\"" " set=\"zebra::index%s/\">\n", fi->sysno, elemsetname); - - wrbuf_printf(wrbuf, " ", index_type); - wrbuf_xmlputs(wrbuf, dst_buf); - wrbuf_printf(wrbuf, "\n"); - wrbuf_printf(wrbuf, "\n"); } else if (!oid_oidcmp(input_format, yaz_oid_recsyn_sutrs)) { *output_format = yaz_oid_recsyn_sutrs; + } + else + { + yaz_log(YLOG_WARN, "unsupported format for element set zebra::%s", + elemsetname); + *output_format = 0; + wrbuf_destroy(wrbuf_str); + return YAZ_BIB1_NO_SYNTAXES_AVAILABLE_FOR_THIS_REQUEST; + } + zebra_sort_type(zh->reg->sort_index, ord); + zebra_sort_sysno(zh->reg->sort_index, fi->sysno); + zebra_sort_read(zh->reg->sort_index, wrbuf_str); + + while (off != wrbuf_len(wrbuf_str)) + { + char dst_buf[IT_MAX_WORD]; + assert(off < wrbuf_len(wrbuf_str)); + zebra_term_untrans(zh, index_type, dst_buf, + wrbuf_buf(wrbuf_str)+off); - wrbuf_printf(wrbuf, "%s %s %s\n", string_index, index_type, - dst_buf); + if (!oid_oidcmp(input_format, yaz_oid_recsyn_xml)) + { + wrbuf_printf(wrbuf_result, " ", index_type); + wrbuf_xmlputs(wrbuf_result, dst_buf); + wrbuf_printf(wrbuf_result, "\n"); + } + else if (!oid_oidcmp(input_format, yaz_oid_recsyn_sutrs)) + { + wrbuf_printf(wrbuf_result, "%s %s %s\n", string_index, index_type, + dst_buf); + } + off += strlen(wrbuf_buf(wrbuf_str)+off) + 1; } - wrbuf_destroy(str); + if (!oid_oidcmp(input_format, yaz_oid_recsyn_xml)) + { + wrbuf_printf(wrbuf_result, "\n"); + } + wrbuf_destroy(wrbuf_str); return 0; } } -int zebra_special_index_fetch( +static int special_index_fetch( struct special_fetch_s *fi, const char *elemsetname, const Odr_oid *input_format, const Odr_oid **output_format, @@ -601,7 +613,7 @@ struct term_collect { zint set_occur; }; -zint freq_term(ZebraHandle zh, int ord, const char *term, RSET rset_set) +static zint freq_term(ZebraHandle zh, int ord, const char *term, RSET rset_set) { struct rset_key_control *kc = zebra_key_control_create(zh); char ord_buf[IT_MAX_WORD]; @@ -634,7 +646,7 @@ zint freq_term(ZebraHandle zh, int ord, const char *term, RSET rset_set) return hits; } -int term_qsort_handle(const void *a, const void *b) +static int term_qsort_handle(const void *a, const void *b) { const struct term_collect *l = a; const struct term_collect *r = b; @@ -650,9 +662,9 @@ int term_qsort_handle(const void *a, const void *b) } } -void term_collect_freq(ZebraHandle zh, - struct term_collect *col, int no_terms_collect, - int ord, RSET rset) +static void term_collect_freq(ZebraHandle zh, + struct term_collect *col, int no_terms_collect, + int ord, RSET rset) { int i; for (i = 0; i < no_terms_collect; i++) @@ -663,9 +675,9 @@ void term_collect_freq(ZebraHandle zh, qsort(col, no_terms_collect, sizeof(*col), term_qsort_handle); } -struct term_collect *term_collect_create(zebra_strmap_t sm, - int no_terms_collect, - NMEM nmem) +static struct term_collect *term_collect_create(zebra_strmap_t sm, + int no_terms_collect, + NMEM nmem) { const char *term; void *data_buf; @@ -705,7 +717,7 @@ struct term_collect *term_collect_create(zebra_strmap_t sm, return col; } -static ZEBRA_RES facet_fetch( +static int facet_fetch( struct special_fetch_s *fi, const char *elemsetname, const Odr_oid *input_format, const Odr_oid **output_format, @@ -736,23 +748,13 @@ static ZEBRA_RES facet_fetch( if (!spec_list || error) { - zebra_setError( - zh, - YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_, - 0); - return ZEBRA_FAIL; + return YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_; } for (spec = spec_list; spec; spec = spec->next) { if (!spec->index_type) - { - zebra_setError( - zh, - YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_, - 0); - return ZEBRA_FAIL; - } + return YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_; no_ord++; } @@ -766,11 +768,7 @@ static ZEBRA_RES facet_fetch( spec->index_name); if (ord == -1) { - zebra_setError( - zh, - YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_, - 0); - return ZEBRA_FAIL; + return YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_; } ord_array[i] = ord; } @@ -780,9 +778,8 @@ static ZEBRA_RES facet_fetch( poset = zebra_meta_records_create(zh, fi->setname, num_recs, pos_array); if (!poset) { - zebra_setError(zh, YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST, - fi->setname); - ret = ZEBRA_FAIL; + wrbuf_puts(addinfo, fi->setname); + return YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST; } else { @@ -921,12 +918,11 @@ static ZEBRA_RES facet_fetch( } -int zebra_special_fetch( +static int zebra_special_fetch( void *handle, const char *elemsetname, const Odr_oid *input_format, const Odr_oid **output_format, - WRBUF result, WRBUF addinfo - ) + WRBUF result, WRBUF addinfo) { Record rec = 0; struct special_fetch_s *fi = (struct special_fetch_s *) handle; @@ -1076,7 +1072,7 @@ int zebra_special_fetch( /* processing special elementsetnames zebra::index:: */ if (elemsetname && 0 == strncmp(elemsetname, "index", 5)) { - int ret = zebra_special_index_fetch( + int ret = special_index_fetch( fi, elemsetname + 5, input_format, output_format, result, addinfo, rec);