-/* $Id: zrpn.c,v 1.194 2005-06-02 11:59:54 adam Exp $
+/* $Id: zrpn.c,v 1.200 2005-06-14 20:28:54 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <assert.h>
#ifdef WIN32
#include <io.h>
-#else
+#endif
+#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <ctype.h>
Z_AttributesPlusTerm *zapt;
} AttrType;
-
static int log_level_set = 0;
static int log_level_rpn = 0;
struct grep_info *grep_info,
int reg_type, int complete_flag,
int num_bases, char **basenames,
- char *term_dst, int xpath_use);
+ char *term_dst, int xpath_use,
+ struct ord_list **ol);
static ZEBRA_RES term_trunc(ZebraHandle zh,
Z_AttributesPlusTerm *zapt,
struct rset_key_control *kc)
{
ZEBRA_RES res;
+ struct ord_list *ol;
*rset = 0;
grep_info->isam_p_indx = 0;
res = string_term(zh, zapt, term_sub, attributeSet, stream, grep_info,
reg_type, complete_flag, num_bases, basenames,
- term_dst, xpath_use);
+ term_dst, xpath_use, &ol);
if (res != ZEBRA_OK)
return res;
if (!*term_sub) /* no more terms ? */
grep_info->isam_p_indx, term_dst,
strlen(term_dst), rank_type, 1 /* preserve pos */,
zapt->term->which, rset_nmem,
- kc, kc->scope);
+ kc, kc->scope, ol, reg_type);
if (!*rset)
return ZEBRA_FAIL;
return ZEBRA_OK;
struct grep_info *grep_info,
int reg_type, int complete_flag,
int num_bases, char **basenames,
- char *term_dst, int xpath_use)
+ char *term_dst, int xpath_use,
+ struct ord_list **ol)
{
char term_dict[2*IT_MAX_WORD+4000];
int j, r, base_no;
int errCode = 0; /* err code (if any is not OK) */
char *errString = 0; /* addinfo */
+
+ *ol = ord_list_create(stream);
+
rpn_char_map_prepare (zh->reg, reg_type, &rcmi);
attr_init(&use, zapt, 1);
use_value = attr_find_ex(&use, &curAttributeSet, &use_string);
term_dict[prefix_len++] = ord_buf[i];
}
attp.local_attributes = 0; /* no more attributes */
+ *ol = ord_list_append(stream, *ol, ord);
}
else
{
local_attr->local);
if (ord < 0)
continue;
+ *ol = ord_list_append(stream, *ol, ord);
if (prefix_len)
term_dict[prefix_len++] = '|';
else
return ZEBRA_OK;
}
-char *normalize_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
- const char *termz, NMEM stream, unsigned reg_id)
-{
- WRBUF wrbuf = 0;
- AttrType truncation;
- int truncation_value;
- char *ex_list = 0;
-
- attr_init(&truncation, zapt, 5);
- truncation_value = attr_find(&truncation, NULL);
-
- switch (truncation_value)
- {
- default:
- ex_list = "";
- break;
- case 101:
- ex_list = "#";
- break;
- case 102:
- case 103:
- ex_list = 0;
- break;
- case 104:
- ex_list = "!#";
- break;
- case 105:
- ex_list = "!*";
- break;
- }
- if (ex_list)
- wrbuf = zebra_replace(zh->reg->zebra_maps, reg_id, ex_list,
- termz, strlen(termz));
- if (!wrbuf)
- return nmem_strdup(stream, termz);
- else
- {
- char *buf = (char*) nmem_malloc(stream, wrbuf_len(wrbuf)+1);
- memcpy (buf, wrbuf_buf(wrbuf), wrbuf_len(wrbuf));
- buf[wrbuf_len(wrbuf)] = '\0';
- return buf;
- }
-}
-
static void grep_info_delete(struct grep_info *grep_info)
{
#ifdef TERM_COUNT
/**
\brief Create result set(s) for list of terms
\param zh Zebra Handle
- \param termz_org term as used in query but converted to UTF-8
+ \param termz term as used in query but converted to UTF-8
\param attributeSet default attribute set
\param stream memory for result
\param reg_type register type ('w', 'p',..)
*/
static ZEBRA_RES term_list_trunc(ZebraHandle zh,
Z_AttributesPlusTerm *zapt,
- const char *termz_org,
+ const char *termz,
oid_value attributeSet,
NMEM stream,
int reg_type, int complete_flag,
{
char term_dst[IT_MAX_WORD+1];
struct grep_info grep_info;
- char *termz = normalize_term(zh, zapt, termz_org, stream, reg_type);
const char *termp = termz;
int alloc_sets = 0;
strlen(term_dst), rank_type,
0 /* preserve position */,
zapt->term->which, rset_nmem,
- kc, kc->scope);
+ kc, kc->scope, 0, reg_type);
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);
+ kc, kc->scope, 0, reg_type);
grep_info_delete(&grep_info);
return rset;
}
*dst = nmem_strdup(stream, term_src);
}
-static void count_set (RSET r, int *count)
+static void count_set(ZebraHandle zh, RSET rset, zint *count)
{
zint psysno = 0;
- int kno = 0;
struct it_key key;
RSFD rfd;
yaz_log(YLOG_DEBUG, "count_set");
+ rset->hits_limit = zh->approx_limit;
+
*count = 0;
- rfd = rset_open (r, RSETF_READ);
- while (rset_read (rfd, &key,0 /* never mind terms */))
+ rfd = rset_open(rset, RSETF_READ);
+ while (rset_read(rfd, &key,0 /* never mind terms */))
{
if (key.mem[0] != psysno)
{
psysno = key.mem[0];
- (*count)++;
+ if (rfd->counted_items >= rset->hits_limit)
+ break;
}
- kno++;
}
rset_close (rfd);
- yaz_log(YLOG_DEBUG, "%d keys, %d records", kno, *count);
+ *count = rset->hits_count;
}
ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
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);
+ kc, kc->scope, 0, reg_id);
}
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);
+ kc, kc->scope, 0, reg_id);
rset = rsmulti_or_create(rset_nmem, kc,
kc->scope, 0 /* termid */,
2, rsets);
}
if (lo >= 0)
{
+ zint count;
/* merge with limit_set if given */
if (limit_set)
{
2, rsets);
}
/* count it */
- count_set(rset, &glist[lo].occurrences);
+ count_set(zh, rset, &count);
+ glist[lo].occurrences = count;
rset_delete(rset);
}
}
const char *tst;
RSET rset;
int lo = before-1-i; /* offset in result list */
+ zint count;
for (j = 0; j <ord_no; j++)
{
(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);
+ kc, kc->scope, 0, reg_id);
ptr[j0]++;
glist[lo].term,
strlen(glist[lo].term), NULL, 0,
zapt->term->which, rset_nmem,
- kc, kc->scope);
+ kc, kc->scope, 0, reg_id);
rset = rsmulti_or_create(rset_nmem, kc,
kc->scope, 0 /* termid */, 2, rsets);
rset = rsmulti_and_create(rset_nmem, kc,
kc->scope, 2, rsets);
}
- count_set (rset, &glist[lo].occurrences);
+ count_set(zh, rset, &count);
+ glist[lo].occurrences = count;
rset_delete (rset);
}
(*kc->dec)(kc);