X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Frpnsearch.c;h=aaae58a5a1c6c5d0369d0ca3bc977d4f2b9f59c9;hb=4e67b823f05b521f193af096a40c0f64758c5fc1;hp=d35350ab07f5eee18c5117a4f7ee21adbae2f9d2;hpb=4e476a533ed351b90fd331a0dd827084686a9158;p=idzebra-moved-to-github.git diff --git a/index/rpnsearch.c b/index/rpnsearch.c index d35350a..aaae58a 100644 --- a/index/rpnsearch.c +++ b/index/rpnsearch.c @@ -1,5 +1,5 @@ -/* $Id: rpnsearch.c,v 1.4 2006-12-20 14:19:21 adam Exp $ - Copyright (C) 1995-2006 +/* $Id: rpnsearch.c,v 1.10 2007-03-19 21:50:39 adam Exp $ + Copyright (C) 1995-2007 Index Data ApS This file is part of the Zebra server. @@ -1183,7 +1183,9 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, grep_info, &max_pos, ord_len /* number of "exact" chars */, grep_handle); - if (r) + if (r == 1) + zebra_set_partial_result(zh); + else if (r) yaz_log(YLOG_WARN, "dict_lookup_grep fail %d", r); } if (!bases_ok) @@ -1208,10 +1210,6 @@ static ZEBRA_RES grep_info_prepare(ZebraHandle zh, struct grep_info *grep_info, int reg_type) { - AttrType termset; - int termset_value_numeric; - const char *termset_value_string; - #ifdef TERM_COUNT grep_info->term_no = 0; #endif @@ -1221,35 +1219,50 @@ static ZEBRA_RES grep_info_prepare(ZebraHandle zh, grep_info->zh = zh; grep_info->reg_type = reg_type; grep_info->termset = 0; - if (!zapt) - return ZEBRA_OK; - attr_init_APT(&termset, zapt, 8); - termset_value_numeric = - attr_find_ex(&termset, NULL, &termset_value_string); - if (termset_value_numeric != -1) + if (zapt) + { + AttrType truncmax; + int truncmax_value; + + attr_init_APT(&truncmax, zapt, 13); + truncmax_value = attr_find(&truncmax, NULL); + if (truncmax_value != -1) + grep_info->trunc_max = truncmax_value; + } + if (zapt) { + AttrType termset; + int termset_value_numeric; + const char *termset_value_string; + + attr_init_APT(&termset, zapt, 8); + termset_value_numeric = + attr_find_ex(&termset, NULL, &termset_value_string); + if (termset_value_numeric != -1) + { #if TERMSET_DISABLE - zebra_setError(zh, YAZ_BIB1_UNSUPP_SEARCH, "termset"); - return ZEBRA_FAIL; + zebra_setError(zh, YAZ_BIB1_UNSUPP_SEARCH, "termset"); + return ZEBRA_FAIL; #else - char resname[32]; - const char *termset_name = 0; - if (termset_value_numeric != -2) - { - - sprintf(resname, "%d", termset_value_numeric); - termset_name = resname; - } - else + char resname[32]; + const char *termset_name = 0; + if (termset_value_numeric != -2) + { + + sprintf(resname, "%d", termset_value_numeric); + termset_name = resname; + } + else termset_name = termset_value_string; - yaz_log(log_level_rpn, "creating termset set %s", termset_name); - grep_info->termset = resultSetAdd(zh, termset_name, 1); - if (!grep_info->termset) - { - zebra_setError(zh, YAZ_BIB1_ILLEGAL_RESULT_SET_NAME, termset_name); - return ZEBRA_FAIL; - } + yaz_log(log_level_rpn, "creating termset set %s", termset_name); + grep_info->termset = resultSetAdd(zh, termset_name, 1); + if (!grep_info->termset) + { + zebra_setError(zh, YAZ_BIB1_ILLEGAL_RESULT_SET_NAME, termset_name); + return ZEBRA_FAIL; + } #endif + } } return ZEBRA_OK; } @@ -1699,7 +1712,10 @@ static int numeric_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt, yaz_log(log_level_rpn, "dict_lookup_grep: %s", term_tmp); r = dict_lookup_grep(zh->reg->dict, term_dict, 0, grep_info, max_pos, 0, grep_handle); - if (r) + + if (r == 1) + zebra_set_partial_result(zh); + else if (r) yaz_log(YLOG_WARN, "dict_lookup_grep fail, rel = gt: %d", r); yaz_log(log_level_rpn, "%d positions", grep_info->isam_p_indx); return 1; @@ -1870,21 +1886,35 @@ static ZEBRA_RES rpn_search_APT_local(ZebraHandle zh, RSET *rset, struct rset_key_control *kc) { - RSFD rsfd; - struct it_key key; - int sys; - *rset = rset_create_temp(rset_nmem, kc, kc->scope, - res_get (zh->res, "setTmpDir"),0 ); - rsfd = rset_open(*rset, RSETF_WRITE); + Record rec; + zint sysno = atozint(termz); - sys = atoi(termz); - if (sys <= 0) - sys = 1; - key.mem[0] = sys; - key.mem[1] = 1; - key.len = 2; - rset_write (rsfd, &key); - rset_close (rsfd); + if (sysno <= 0) + sysno = 0; + rec = rec_get(zh->reg->records, sysno); + if (!rec) + sysno = 0; + + rec_free(&rec); + + if (sysno <= 0) + { + *rset = rset_create_null(rset_nmem, kc, 0); + } + else + { + RSFD rsfd; + struct it_key key; + *rset = rset_create_temp(rset_nmem, kc, kc->scope, + res_get(zh->res, "setTmpDir"), 0); + rsfd = rset_open(*rset, RSETF_WRITE); + + key.mem[0] = sysno; + key.mem[1] = 1; + key.len = 2; + rset_write(rsfd, &key); + rset_close(rsfd); + } return ZEBRA_OK; } @@ -2145,26 +2175,25 @@ ZEBRA_RES rpn_search_xpath(ZebraHandle zh, cp++; } } - wrbuf_puts(wbuf, ""); rset_attr = xpath_trunc( - zh, stream, '0', wrbuf_buf(wbuf), ZEBRA_XPATH_ATTR_NAME, + zh, stream, '0', wrbuf_cstr(wbuf), ZEBRA_XPATH_ATTR_NAME, rset_nmem, kc); - wrbuf_free(wbuf, 1); + wrbuf_destroy(wbuf); } else { if (!first_path) { - wrbuf_free(xpath_rev, 1); + wrbuf_destroy(xpath_rev); continue; } } - yaz_log(log_level_rpn, "xpath_rev (%d) = %.*s", level, - wrbuf_len(xpath_rev), wrbuf_buf(xpath_rev)); + yaz_log(log_level_rpn, "xpath_rev (%d) = %s", level, + wrbuf_cstr(xpath_rev)); if (wrbuf_len(xpath_rev)) { rset_start_tag = xpath_trunc(zh, stream, '0', - wrbuf_buf(xpath_rev), + wrbuf_cstr(xpath_rev), ZEBRA_XPATH_ELM_BEGIN, rset_nmem, kc); if (always_matches) @@ -2172,7 +2201,7 @@ ZEBRA_RES rpn_search_xpath(ZebraHandle zh, else { rset_end_tag = xpath_trunc(zh, stream, '0', - wrbuf_buf(xpath_rev), + wrbuf_cstr(xpath_rev), ZEBRA_XPATH_ELM_END, rset_nmem, kc); @@ -2181,7 +2210,7 @@ ZEBRA_RES rpn_search_xpath(ZebraHandle zh, rset_end_tag, rset_attr); } } - wrbuf_free(xpath_rev, 1); + wrbuf_destroy(xpath_rev); first_path = 0; } }