-/* $Id: rpnscan.c,v 1.14 2007-10-29 09:25:40 adam Exp $
+/* $Id: rpnscan.c,v 1.22 2007-11-13 13:41:51 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
#define RPN_MAX_ORDS 32
-int log_scan = YLOG_LOG;
-
/* convert APT SCAN term to internal cmap */
static ZEBRA_RES trans_scan_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
- char *termz, int reg_type)
+ char *termz, zebra_map_t zm)
{
char termz0[IT_MAX_WORD];
while ((len = (cp_end - cp)) > 0)
{
- map = zebra_maps_input(zh->reg->zebra_maps, reg_type, &cp, len, 0);
+ map = zebra_maps_input(zm, &cp, len, 0);
if (**map == *CHR_SPACE)
space_map = *map;
else
return ZEBRA_OK;
}
-static void count_set(ZebraHandle zh, RSET rset, zint *count)
+static void count_set(ZebraHandle zh, RSET rset, zint *count, zint approx_limit)
{
zint psysno = 0;
struct it_key key;
yaz_log(YLOG_DEBUG, "count_set");
- rset->hits_limit = zh->approx_limit;
+ rset->hits_limit = approx_limit;
*count = 0;
rfd = rset_open(rset, RSETF_READ);
Z_AttributesPlusTerm *zapt,
RSET limit_set,
const char *term,
- int index_type,
+ const char *index_type,
struct scan2_info_entry *ar, int ord_no,
ZebraScanEntry *glist, int pos)
{
int i;
RSET rset = 0;
+ zint approx_limit = zh->approx_limit;
+ 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;
+
for (i = 0; i < ord_no; i++)
{
if (ar[i].isam_p && strcmp(wrbuf_cstr(ar[i].term), term) == 0)
wrbuf_buf(ar[i].term), wrbuf_len(ar[i].term),
NULL, 1, zapt->term->which, nmem,
kc, kc->scope, ol, index_type,
- 0 /* hits_limit */,
+ 0 /* hits_limit_value */,
0 /* term_ref_id_str */);
if (!rset)
rset = rset_t;
rset = rset_create_and(nmem, kc, kc->scope, 2, rsets);
}
/* count it */
- count_set(zh, rset, &count);
+ count_set(zh, rset, &count, approx_limit);
if (pos != -1)
{
}
return 0;
}
-
-static ZEBRA_RES rpn_scan_ver2(ZebraHandle zh, ODR stream, NMEM nmem,
+
+static ZEBRA_RES rpn_scan_norm(ZebraHandle zh, ODR stream, NMEM nmem,
struct rset_key_control *kc,
Z_AttributesPlusTerm *zapt,
int *position, int *num_entries,
ZebraScanEntry **list,
int *is_partial, RSET limit_set,
- int index_type, int ord_no, int *ords)
+ const char *index_type,
+ int ord_no, int *ords)
{
struct scan2_info_entry *ar = nmem_malloc(nmem, sizeof(*ar) * ord_no);
struct rpn_char_map_info rcmi;
+ zebra_map_t zm = zebra_map_get_or_add(zh->reg->zebra_maps, index_type);
int i, dif;
int after_pos;
int pos = 0;
*num_entries = 0;
return ZEBRA_OK;
}
- rpn_char_map_prepare(zh->reg, index_type, &rcmi);
+ rpn_char_map_prepare(zh->reg, zm, &rcmi);
for (i = 0; i < ord_no; i++)
ar[i].term = wrbuf_alloc();
termz[prefix_len] = 0;
strcpy(ar[i].prefix, termz);
- if (trans_scan_term(zh, zapt, termz+prefix_len, index_type) ==
+ if (trans_scan_term(zh, zapt, termz+prefix_len, zm) ==
ZEBRA_FAIL)
{
for (i = 0; i < ord_no; i++)
termz[prefix_len] = 0;
strcpy(ar[i].prefix, termz);
- if (trans_scan_term(zh, zapt, termz+prefix_len, index_type) ==
+ if (trans_scan_term(zh, zapt, termz+prefix_len, zm) ==
ZEBRA_FAIL)
return ZEBRA_FAIL;
wrbuf_rewind(ar[i].term);
const Odr_oid *attributeset,
int num_bases, char **basenames,
int *position, int *num_entries, ZebraScanEntry **list,
- int *is_partial, RSET limit_set)
+ int *is_partial, const char *set_name)
{
int base_no;
int ords[RPN_MAX_ORDS], ord_no = 0;
- unsigned index_type;
+ const char *index_type;
char *search_type = NULL;
char rank_type[128];
int complete_flag;
NMEM nmem;
ZEBRA_RES res;
struct rset_key_control *kc = 0;
+ RSET limit_set = 0;
*list = 0;
*is_partial = 0;
if (!attributeset)
attributeset = yaz_oid_attset_bib_1;
- if (!limit_set) /* no limit set given already */
+ if (!set_name)
{
/* see if there is a @attr 8=set */
AttrType termset;
int termset_value_numeric;
- const char *termset_value_string;
+ const char *termset_value_string = 0;
attr_init_APT(&termset, zapt, 8);
termset_value_numeric =
attr_find_ex(&termset, NULL, &termset_value_string);
if (termset_value_numeric != -1)
{
- char resname[32];
- const char *termset_name = 0;
-
if (termset_value_numeric != -2)
{
+ char resname[32];
sprintf(resname, "%d", termset_value_numeric);
- termset_name = resname;
+ set_name = odr_strdup(stream, resname);
}
else
- termset_name = termset_value_string;
-
- limit_set = resultSetRef(zh, termset_name);
-
- if (!limit_set)
- {
- zebra_setError(zh,
- YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
- termset_name);
- return ZEBRA_FAIL;
- }
+ set_name = odr_strdup(stream, termset_value_string);
}
}
+
+ if (set_name)
+ {
+ limit_set = resultSetRef(zh, set_name);
+ if (!limit_set)
+ {
+ zebra_setError(zh,
+ YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
+ set_name);
+ return ZEBRA_FAIL;
+ }
+ }
+
yaz_log(YLOG_DEBUG, "position = %d, num = %d",
*position, *num_entries);
zebra_setError(zh, YAZ_BIB1_TOO_MANY_DATABASES_SPECIFIED, 0);
return ZEBRA_FAIL;
}
-
+ if (sort_flag)
+ {
+ return rpn_facet(zh, stream, zapt, attributeset, position, num_entries,
+ list, is_partial, set_name);
+ }
for (base_no = 0; base_no < num_bases; base_no++)
{
int ord;
nmem = nmem_create();
kc = zebra_key_control_create(zh);
- res = rpn_scan_ver2(zh, stream, nmem, kc, zapt, position, num_entries,
- list,
- is_partial, limit_set, index_type, ord_no, ords);
+ res = rpn_scan_norm(zh, stream, nmem, kc, zapt, position, num_entries,
+ list, is_partial, limit_set,
+ index_type, ord_no, ords);
nmem_destroy(nmem);
(*kc->dec)(kc);
return res;