-/* $Id: rpnsearch.c,v 1.2 2006-10-12 12:28:42 adam Exp $
- Copyright (C) 1995-2006
+/* $Id: rpnsearch.c,v 1.8 2007-01-17 12:59:38 adam Exp $
+ Copyright (C) 1995-2007
Index Data ApS
This file is part of the Zebra server.
ISAM_P *isam_p_buf;
int isam_p_size;
int isam_p_indx;
+ int trunc_max;
ZebraHandle zh;
int reg_type;
ZebraSet termset;
};
-static void add_isam_p(const char *name, const char *info,
- struct grep_info *p)
+static int add_isam_p(const char *name, const char *info,
+ struct grep_info *p)
{
if (!log_level_set)
{
log_level_rpn = yaz_log_module_level("rpn");
log_level_set = 1;
}
+ /* we may have to stop this madness.. NOTE: -1 so that if
+ truncmax == trunxlimit we do *not* generate result sets */
+ if (p->isam_p_indx >= p->trunc_max - 1)
+ return 1;
+
if (p->isam_p_indx == p->isam_p_size)
{
ISAM_P *new_isam_p_buf;
index_name, term_tmp);
}
(p->isam_p_indx)++;
+ return 0;
}
static int grep_handle(char *name, const char *info, void *p)
{
- add_isam_p(name, info, (struct grep_info *) p);
- return 0;
+ return add_isam_p(name, info, (struct grep_info *) p);
}
static int term_pre(ZebraMaps zebra_maps, int reg_type, const char **src,
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)
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
+ grep_info->trunc_max = atoi(res_get_def(zh->res, "truncmax", "10000"));
grep_info->isam_p_size = 0;
grep_info->isam_p_buf = NULL;
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;
}
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;
Z_Operator *parent_op,
struct rset_key_control *kc);
+ZEBRA_RES rpn_get_top_approx_limit(ZebraHandle zh, Z_RPNStructure *zs,
+ zint *approx_limit)
+{
+ ZEBRA_RES res = ZEBRA_OK;
+ if (zs->which == Z_RPNStructure_complex)
+ {
+ if (res == ZEBRA_OK)
+ res = rpn_get_top_approx_limit(zh, zs->u.complex->s1,
+ approx_limit);
+ if (res == ZEBRA_OK)
+ res = rpn_get_top_approx_limit(zh, zs->u.complex->s2,
+ approx_limit);
+ }
+ else if (zs->which == Z_RPNStructure_simple)
+ {
+ if (zs->u.simple->which == Z_Operand_APT)
+ {
+ Z_AttributesPlusTerm *zapt = zs->u.simple->u.attributesPlusTerm;
+ AttrType global_hits_limit_attr;
+ int l;
+
+ attr_init_APT(&global_hits_limit_attr, zapt, 12);
+
+ l = attr_find(&global_hits_limit_attr, NULL);
+ if (l != -1)
+ *approx_limit = l;
+ }
+ }
+ return res;
+}
+
ZEBRA_RES rpn_search_top(ZebraHandle zh, Z_RPNStructure *zs,
oid_value attributeSet,
NMEM stream, NMEM rset_nmem,