-/* $Id: api.h,v 1.26 2005-06-09 10:39:52 adam Exp $
+/* $Id: api.h,v 1.27 2005-06-22 19:42:38 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
YAZ_EXPORT
ZEBRA_RES zebra_result_set_term_info(ZebraHandle zh, const char *setname,
int no, zint *count, int *approx,
- char *termbuf, size_t *termlen);
+ char *termbuf, size_t *termlen,
+ const char **term_ref_id);
/**
-/* $Id: rset.h,v 1.56 2005-06-07 14:53:38 adam Exp $
+/* $Id: rset.h,v 1.57 2005-06-22 19:42:37 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
int reg_type; /** register type */
RSET rset; /** the rset corresponding to this term */
void *rankpriv;/** private stuff for the ranking algorithm */
+ zint hits_limit;/** limit for hits if > 0 */
+ char *ref_id; /** reference for this term */
struct ord_list *ol;
};
typedef struct rset_term *TERMID;
TERMID rset_term_create (const char *name, int length, const char *flags,
int type, NMEM nmem, struct ord_list *ol,
- int reg_type);
+ int reg_type, zint hits_limit, const char *ref_id);
/** rsfd is a "file descriptor" for reading from a rset */
struct rsfd { /* the stuff common to all rsfd's. */
-/* $Id: index.h,v 1.143 2005-06-09 10:39:53 adam Exp $
+/* $Id: index.h,v 1.144 2005-06-22 19:42:38 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
const char *term, int length_term, const char *flags,
int preserve_position, int term_type, NMEM rset_nmem,
struct rset_key_control *kctrl, int scope,
- struct ord_list *ol, int reg_type);
+ struct ord_list *ol, int reg_type,
+ zint hits_limit, const char *term_ref_id);
void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type,
const char *db, int set,
-/* $Id: trunc.c,v 1.60 2005-06-07 14:53:39 adam Exp $
+/* $Id: trunc.c,v 1.61 2005-06-22 19:42:38 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
const char *term, int length, const char *flags,
int preserve_position, int term_type, NMEM rset_nmem,
struct rset_key_control *kctrl, int scope,
- struct ord_list *ol, int reg_type)
+ struct ord_list *ol, int reg_type,
+ zint hits_limit, const char *term_ref_id)
{
TERMID termid;
RSET result;
int trunc_chunk;
termid = rset_term_create(term, length, flags, term_type, rset_nmem, ol,
- reg_type);
+ reg_type, hits_limit, term_ref_id);
if (no < 1)
return rsnull_create(rset_nmem, kctrl, termid);
-/* $Id: zrpn.c,v 1.200 2005-06-14 20:28:54 adam Exp $
+/* $Id: zrpn.c,v 1.201 2005-06-22 19:42:38 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
char *term_dst, int xpath_use,
struct ord_list **ol);
+static ZEBRA_RES term_limits_APT(ZebraHandle zh,
+ Z_AttributesPlusTerm *zapt,
+ zint *hits_limit_value,
+ const char **term_ref_id_str)
+{
+ AttrType term_ref_id_attr;
+ AttrType hits_limit_attr;
+
+ attr_init(&hits_limit_attr, zapt, 9);
+ *hits_limit_value = attr_find(&hits_limit_attr, NULL);
+
+ attr_init(&term_ref_id_attr, zapt, 10);
+ attr_find_ex(&term_ref_id_attr, NULL, term_ref_id_str);
+
+ /* no limit given ? */
+ if (*hits_limit_value == -1)
+ if (*term_ref_id_str)
+ {
+ /* use global if term_ref is present */
+ *hits_limit_value = zh->approx_limit;
+ }
+ else
+ {
+ /* no counting if term_ref is not present */
+ *hits_limit_value = 0;
+ }
+ else if (*hits_limit_value == 0)
+ {
+ /* 0 is the same as global limit */
+ *hits_limit_value = zh->approx_limit;
+ }
+ yaz_log(YLOG_LOG, "term_limits_APT ref_id=%s limit=" ZINT_FORMAT,
+ *term_ref_id_str ? *term_ref_id_str : "none",
+ *hits_limit_value);
+ return ZEBRA_OK;
+}
+
static ZEBRA_RES term_trunc(ZebraHandle zh,
Z_AttributesPlusTerm *zapt,
const char **term_sub,
{
ZEBRA_RES res;
struct ord_list *ol;
+ zint hits_limit_value;
+ const char *term_ref_id_str = 0;
*rset = 0;
+
+ term_limits_APT(zh, zapt, &hits_limit_value, &term_ref_id_str);
grep_info->isam_p_indx = 0;
res = string_term(zh, zapt, term_sub, attributeSet, stream, grep_info,
reg_type, complete_flag, num_bases, basenames,
grep_info->isam_p_indx, term_dst,
strlen(term_dst), rank_type, 1 /* preserve pos */,
zapt->term->which, rset_nmem,
- kc, kc->scope, ol, reg_type);
+ kc, kc->scope, ol, reg_type, hits_limit_value,
+ term_ref_id_str);
if (!*rset)
return ZEBRA_FAIL;
return ZEBRA_OK;
return ZEBRA_OK;
}
+
static ZEBRA_RES rpn_search_APT_numeric(ZebraHandle zh,
Z_AttributesPlusTerm *zapt,
const char *termz,
ZEBRA_RES res;
struct grep_info grep_info;
int alloc_sets = 0;
+ zint hits_limit_value;
+ const char *term_ref_id_str = 0;
+
+ term_limits_APT(zh, zapt, &hits_limit_value, &term_ref_id_str);
yaz_log(log_level_rpn, "APT_numeric t='%s'", termz);
if (grep_info_prepare(zh, zapt, &grep_info, reg_type) == ZEBRA_FAIL)
strlen(term_dst), rank_type,
0 /* preserve position */,
zapt->term->which, rset_nmem,
- kc, kc->scope, 0, reg_type);
+ kc, kc->scope, 0, reg_type,
+ hits_limit_value,
+ term_ref_id_str);
if (!result_sets[num_result_sets])
break;
num_result_sets++;
rset = rset_trunc(zh, grep_info.isam_p_buf,
grep_info.isam_p_indx, term, strlen(term),
flags, 1, term_type,rset_nmem,
- kc, kc->scope, 0, reg_type);
+ kc, kc->scope, 0, reg_type, 0 /* hits_limit */,
+ 0 /* term_ref_id_str */);
grep_info_delete(&grep_info);
return rset;
}
rset = rset_trunc(zh, &scan_info_array[j0].list[ptr[j0]].isam_p, 1,
glist[lo].term, strlen(glist[lo].term),
NULL, 0, zapt->term->which, rset_nmem,
- kc, kc->scope, 0, reg_id);
+ kc, kc->scope, 0, reg_id, 0 /* hits_limit */,
+ 0 /* term_ref_id_str */);
}
ptr[j0]++; /* move index for this set .. */
/* get result set for remaining scan terms */
glist[lo].term,
strlen(glist[lo].term), NULL, 0,
zapt->term->which,rset_nmem,
- kc, kc->scope, 0, reg_id);
+ kc, kc->scope, 0, reg_id, 0 /* hits_limit */,
+ 0 /* term_ref_id_str */ );
rset = rsmulti_or_create(rset_nmem, kc,
kc->scope, 0 /* termid */,
2, rsets);
(zh, &scan_info_array[j0].list[before-1-ptr[j0]].isam_p, 1,
glist[lo].term, strlen(glist[lo].term),
NULL, 0, zapt->term->which, rset_nmem,
- kc, kc->scope, 0, reg_id);
+ kc, kc->scope, 0, reg_id, 0 /* hits_limit */,
+ 0 /* term_ref_id_str */);
ptr[j0]++;
glist[lo].term,
strlen(glist[lo].term), NULL, 0,
zapt->term->which, rset_nmem,
- kc, kc->scope, 0, reg_id);
+ kc, kc->scope, 0, reg_id, 0 /* hits_limit */,
+ 0 /* term_ref_id_str */);
rset = rsmulti_or_create(rset_nmem, kc,
kc->scope, 0 /* termid */, 2, rsets);
-/* $Id: zserver.c,v 1.136 2005-06-14 20:28:54 adam Exp $
+/* $Id: zserver.c,v 1.137 2005-06-22 19:42:38 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
size_t len = sizeof(outbuf);
zebra_result_set_term_info(zh, r->setname, i,
- &count, &approx, outbuf, &len);
+ &count, &approx, outbuf, &len,
+ 0 /* term_ref_id */ );
sr->elements[i] = odr_malloc (r->stream, sizeof(**sr->elements));
sr->elements[i]->subqueryId = 0;
-/* $Id: zsets.c,v 1.89 2005-06-09 10:39:53 adam Exp $
+/* $Id: zsets.c,v 1.90 2005-06-22 19:42:38 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
key_logdump_txt(log_level_searchhits, &key, termid->name);
if (this_sys != psysno)
{
- if (rfd->counted_items >= rset->hits_limit)
+ if (rfd->counted_items > rset->hits_limit)
break;
if (psysno)
{
if (approx_array)
approx_array[no] = rset->hits_approx;
#if 0
- yaz_log(YLOG_LOG, "rset=%p term=%s count=" ZINT_FORMAT,
- rset, rset->term->name, rset->hits_count);
+ yaz_log(YLOG_LOG, "rset=%p term=%s limit=" ZINT_FORMAT
+ " count=" ZINT_FORMAT,
+ rset, rset->term->name, rset->hits_limit, rset->hits_count);
#endif
no++;
}
ZEBRA_RES zebra_result_set_term_info(ZebraHandle zh, const char *setname,
int no, zint *count, int *approx,
- char *termbuf, size_t *termlen)
+ char *termbuf, size_t *termlen,
+ const char **term_ref_id)
{
ZebraSet sset = resultSetGet(zh, setname);
if (sset)
}
termbuf[*termlen] = '\0';
}
+ if (term_ref_id)
+ *term_ref_id = term_array[no]->ref_id;
xfree(term_array);
xfree(hits_array);
-/* $Id: rsbetween.c,v 1.41 2005-06-07 14:53:39 adam Exp $
+/* $Id: rsbetween.c,v 1.42 2005-06-22 19:42:39 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
{
if (!rs->term)
{
- rs->term = rset_term_create(tag, strlen(tag), "", 0, nmem, 0, 0);
+ rs->term = rset_term_create(tag, -1, "", 0, nmem, 0, 0, 0, 0);
rs->term->rset = rs;
}
}
-/* $Id: rset.c,v 1.51 2005-06-09 10:39:53 adam Exp $
+/* $Id: rset.c,v 1.52 2005-06-22 19:42:39 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
{
TERMID termid;
char buf[100];
- while(rfd->counted_items < rs->hits_limit
+ while(rfd->counted_items <= rs->hits_limit
&& rset_default_read(rfd, buf, &termid))
;
rs->hits_count = rfd->counted_items;
+ yaz_log(log_level, "rset_close rset=%p hits_count=" ZINT_FORMAT
+ " hits_limit=" ZINT_FORMAT,
+ rs, rs->hits_count, rs->hits_limit);
rs->hits_approx = 0;
- if (rs->hits_count >= rs->hits_limit)
+ if (rs->hits_count > rs->hits_limit)
{
double cur, tot;
zint est;
rset = (RSET) nmem_malloc(nmem, sizeof(*rset));
yaz_log(log_level, "rs_create(%s) rs=%p (nm=%p)", sel->desc, rset, nmem);
+ yaz_log(log_level, " ref_id=%s limit=" ZINT_FORMAT,
+ (term && term->ref_id ? term->ref_id : "null"),
+ rset->hits_limit);
rset->nmem = nmem;
rset->control = sel;
rset->refcount = 1;
rset->scope = scope;
rset->term = term;
if (term)
+ {
term->rset = rset;
-
+ rset->hits_limit = term->hits_limit;
+ }
rset->no_children = no_children;
rset->children = 0;
if (no_children)
\param nmem memory for term.
\param ol ord list
\param reg_type register type
+ \param hits_limit limit before counting stops and gets approximate
+ \param ref_id supplied ID for term that can be used to identify this
*/
TERMID rset_term_create(const char *name, int length, const char *flags,
int type, NMEM nmem, struct ord_list *ol,
- int reg_type)
+ int reg_type,
+ zint hits_limit, const char *ref_id)
{
TERMID t;
else if (length == -1)
t->name = nmem_strdup(nmem, name);
else
- {
- t->name = (char*) nmem_malloc(nmem, length+1);
- memcpy (t->name, name, length);
- t->name[length] = '\0';
- }
+ t->name = nmem_strdupn(nmem, name, length);
+ if (!ref_id)
+ t->ref_id = 0;
+ else
+ t->ref_id = nmem_strdup(nmem, ref_id);
if (!flags)
t->flags = NULL;
else
t->flags = nmem_strdup(nmem, flags);
+ t->hits_limit = hits_limit;
t->type = type;
t->reg_type = reg_type;
t->rankpriv = 0;