-/* $Id: zrpn.c,v 1.201 2005-06-22 19:42:38 adam Exp $
- Copyright (C) 1995-2005
+/* $Id: zrpn.c,v 1.213 2006-05-17 17:46:45 adam Exp $
+ Copyright (C) 1995-2006
Index Data ApS
This file is part of the Zebra server.
}
static int attr_find_ex(AttrType *src, oid_value *attributeSetP,
- const char **string_value)
+ const char **string_value)
{
int num_attributes;
{
const char *cp = zebra_maps_output(zh->reg->zebra_maps,
reg_type, &src);
- if (!cp && len < IT_MAX_WORD-1)
- dst[len++] = *src++;
+ if (!cp)
+ {
+ if (len < IT_MAX_WORD-1)
+ dst[len++] = *src;
+ src++;
+ }
else
while (*cp && len < IT_MAX_WORD-1)
dst[len++] = *cp++;
const char *db;
int set, use;
char term_tmp[IT_MAX_WORD];
- int su_code = 0;
- int len = key_SU_decode (&su_code, name);
+ int ord = 0;
+ int len = key_SU_decode (&ord, (const unsigned char *) name);
zebra_term_untrans (p->zh, p->reg_type, term_tmp, name+len+1);
- yaz_log(log_level_rpn, "grep: %d %c %s", su_code, name[len], term_tmp);
+ yaz_log(log_level_rpn, "grep: %d %c %s", ord, name[len], term_tmp);
zebraExplain_lookup_ord (p->zh->reg->zei,
- su_code, &db, &set, &use);
+ ord, 0 /* index_type */, &db, &set, &use, 0);
yaz_log(log_level_rpn, "grep: set=%d use=%d db=%s", set, use, db);
resultSetAddTerm(p->zh, p->termset, name[len], db,
break;
case 3:
case 102:
+ case 103:
case -1:
+ if (!**term_sub)
+ return 1;
yaz_log(log_level_rpn, "Relation =");
if (!term_100(zh->reg->zebra_maps, reg_type, term_sub,
term_component, space_split, term_dst))
static ZEBRA_RES term_limits_APT(ZebraHandle zh,
Z_AttributesPlusTerm *zapt,
zint *hits_limit_value,
- const char **term_ref_id_str)
+ const char **term_ref_id_str,
+ NMEM nmem)
{
AttrType term_ref_id_attr;
AttrType hits_limit_attr;
+ int term_ref_id_int;
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);
+ term_ref_id_int = attr_find_ex(&term_ref_id_attr, NULL, term_ref_id_str);
+ if (term_ref_id_int >= 0)
+ {
+ char *res = nmem_malloc(nmem, 20);
+ sprintf(res, "%d", term_ref_id_int);
+ *term_ref_id_str = res;
+ }
/* no limit given ? */
if (*hits_limit_value == -1)
+ {
if (*term_ref_id_str)
{
/* use global if term_ref is present */
/* 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,
+ yaz_log(YLOG_DEBUG, "term_limits_APT ref_id=%s limit=" ZINT_FORMAT,
*term_ref_id_str ? *term_ref_id_str : "none",
*hits_limit_value);
return ZEBRA_OK;
const char *term_ref_id_str = 0;
*rset = 0;
- term_limits_APT(zh, zapt, &hits_limit_value, &term_ref_id_str);
+ term_limits_APT(zh, zapt, &hits_limit_value, &term_ref_id_str,
+ stream);
grep_info->isam_p_indx = 0;
res = string_term(zh, zapt, term_sub, attributeSet, stream, grep_info,
reg_type, complete_flag, num_bases, basenames,
return ZEBRA_OK;
}
-static char *nmem_strdup_i(NMEM nmem, int v)
-{
- char val_str[64];
- sprintf(val_str, "%d", v);
- return nmem_strdup(nmem, val_str);
-}
-
static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
const char **term_sub,
oid_value attributeSet, NMEM stream,
int space_split = complete_flag ? 0 : 1;
int bases_ok = 0; /* no of databases with OK attribute */
- int errCode = 0; /* err code (if any is not OK) */
- char *errString = 0; /* addinfo */
-
*ol = ord_list_create(stream);
}
else if (use_string &&
(ord = zebraExplain_lookup_attr_str(zh->reg->zei,
+ reg_type,
use_string)) >= 0)
{
/* we have a match for a raw string attribute */
if (r == -1)
{
/* set was found, but value wasn't defined */
- errCode = YAZ_BIB1_UNSUPP_USE_ATTRIBUTE;
if (use_string)
- errString = nmem_strdup(stream, use_string);
+ zebra_setError(zh,
+ YAZ_BIB1_UNSUPP_USE_ATTRIBUTE,
+ use_string);
else
- errString = nmem_strdup_i (stream, use_value);
+ zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE,
+ use_value);
}
else
{
oident.value = curAttributeSet;
oid_ent_to_oid (&oident, oid);
- errCode = YAZ_BIB1_UNSUPP_ATTRIBUTE_SET;
- errString = nmem_strdup(stream, oident.desc);
+ zebra_setError(zh,
+ YAZ_BIB1_UNSUPP_ATTRIBUTE_SET,
+ oident.desc);
+
}
continue;
}
int i, ord_len;
ord = zebraExplain_lookup_attr_su(zh->reg->zei,
+ reg_type,
attp.attset_ordinal,
local_attr->local);
if (ord < 0)
term_dict[prefix_len++] = 1;
term_dict[prefix_len++] = ord_buf[i];
}
+ if (ord_len > init_pos)
+ init_pos = ord_len;
}
bases_ok++;
if (prefix_len)
attr_ok = 1;
term_dict[prefix_len++] = ')';
- term_dict[prefix_len++] = 1;
- term_dict[prefix_len++] = reg_type;
- yaz_log(log_level_rpn, "reg_type = %d", term_dict[prefix_len-1]);
term_dict[prefix_len] = '\0';
j = prefix_len;
switch (truncation_value)
case 103: /* Regexp-2 */
regex_range = 1;
term_dict[j++] = '(';
- init_pos = 2;
if (!term_103(zh->reg->zebra_maps, reg_type,
&termp, term_dict + j, ®ex_range,
space_split, term_dst))
}
}
if (!bases_ok)
- {
- zebra_setError(zh, errCode, errString);
return ZEBRA_FAIL;
- }
*term_sub = termp;
yaz_log(YLOG_DEBUG, "%d positions", grep_info->isam_p_indx);
return ZEBRA_OK;
case Z_Term_general:
if (zh->iconv_to_utf8 != 0)
{
- char *inbuf = term->u.general->buf;
+ char *inbuf = (char *) term->u.general->buf;
size_t inleft = term->u.general->len;
char *outbuf = termz;
size_t outleft = IT_MAX_WORD-1;
struct grep_info grep_info;
const char *termp = termz;
int alloc_sets = 0;
+ int empty_term = *termz ? 0 : 1;
+ empty_term = 0;
*num_result_sets = 0;
*term_dst = 0;
if (grep_info_prepare(zh, zapt, &grep_info, reg_type) == ZEBRA_FAIL)
if ((*result_sets)[*num_result_sets] == 0)
break;
(*num_result_sets)++;
+
+ if (empty_term)
+ break;
+ if (!*termp)
+ break;
}
grep_info_delete(&grep_info);
return ZEBRA_OK;
struct rpn_char_map_info rcmi;
int bases_ok = 0; /* no of databases with OK attribute */
- int errCode = 0; /* err code (if any is not OK) */
- char *errString = 0; /* addinfo */
rpn_char_map_prepare (zh->reg, reg_type, &rcmi);
attr_init(&use, zapt, 1);
else
{
if ((r = att_getentbyatt (zh, &attp, curAttributeSet, use_value,
- use_string)))
+ use_string)))
{
yaz_log(YLOG_DEBUG, "att_getentbyatt fail. set=%d use=%d r=%d",
curAttributeSet, use_value, r);
if (r == -1)
{
- errCode = YAZ_BIB1_UNSUPP_USE_ATTRIBUTE;
if (use_string)
- errString = nmem_strdup(stream, use_string);
+ zebra_setError(zh,
+ YAZ_BIB1_UNSUPP_USE_ATTRIBUTE,
+ use_string);
else
- errString = nmem_strdup_i (stream, use_value);
+ zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE,
+ use_value);
}
else
- errCode = YAZ_BIB1_UNSUPP_ATTRIBUTE_SET;
+ zebra_setError(zh, YAZ_BIB1_UNSUPP_ATTRIBUTE_SET, 0);
continue;
}
}
int i, ord_len;
ord = zebraExplain_lookup_attr_su(zh->reg->zei,
+ reg_type,
attp.attset_ordinal,
local_attr->local);
if (ord < 0)
continue;
}
bases_ok++;
- term_dict[prefix_len++] = ')';
- term_dict[prefix_len++] = 1;
- term_dict[prefix_len++] = reg_type;
- yaz_log(YLOG_DEBUG, "reg_type = %d", term_dict[prefix_len-1]);
+ term_dict[prefix_len++] = ')';
term_dict[prefix_len] = '\0';
if (!numeric_relation(zh, zapt, &termp, term_dict,
attributeSet, grep_info, &max_pos, reg_type,
}
}
if (!bases_ok)
- {
- zebra_setError(zh, errCode, errString);
return ZEBRA_FAIL;
- }
*term_sub = termp;
yaz_log(YLOG_DEBUG, "%d positions", grep_info->isam_p_indx);
return ZEBRA_OK;
zint hits_limit_value;
const char *term_ref_id_str = 0;
- term_limits_APT(zh, zapt, &hits_limit_value, &term_ref_id_str);
+ term_limits_APT(zh, zapt, &hits_limit_value, &term_ref_id_str, stream);
yaz_log(log_level_rpn, "APT_numeric t='%s'", termz);
if (grep_info_prepare(zh, zapt, &grep_info, reg_type) == ZEBRA_FAIL)
char term_dict[2048];
char ord_buf[32];
int prefix_len = 0;
- int ord = zebraExplain_lookup_attr_su(zh->reg->zei, curAttributeSet, use);
+ int ord = zebraExplain_lookup_attr_su(zh->reg->zei, reg_type,
+ curAttributeSet, use);
int ord_len, i, r, max_pos;
int term_type = Z_Term_characterString;
const char *flags = "void";
term_dict[prefix_len++] = ord_buf[i];
}
term_dict[prefix_len++] = ')';
- term_dict[prefix_len++] = 1;
- term_dict[prefix_len++] = reg_type;
-
strcpy(term_dict+prefix_len, term);
grep_info.isam_p_indx = 0;
num_bases, basenames, rset_nmem,
rset, kc);
}
+ else if (!strcmp(search_type, "always"))
+ {
+ *termz = '\0';
+ res = rpn_search_APT_phrase(zh, zapt, termz, attributeSet, stream,
+ reg_id, complete_flag, rank_type,
+ xpath_use,
+ num_bases, basenames, rset_nmem,
+ rset, kc);
+ }
else
{
zebra_setError(zh, YAZ_BIB1_UNSUPP_STRUCTURE_ATTRIBUTE, 0);
}
if (use_string &&
- (ord = zebraExplain_lookup_attr_str(zh->reg->zei,
+ (ord = zebraExplain_lookup_attr_str(zh->reg->zei, reg_id,
use_string)) >= 0)
{
/* we have a match for a raw string attribute */
for (local_attr = attp.local_attributes; local_attr && ord_no < 32;
local_attr = local_attr->next)
{
- ord = zebraExplain_lookup_attr_su(zh->reg->zei,
+ ord = zebraExplain_lookup_attr_su(zh->reg->zei, reg_id,
attp.attset_ordinal,
local_attr->local);
if (ord > 0)
scan_info->list[j].term = NULL;
prefix_len += key_SU_encode (ords[i], termz + prefix_len);
- termz[prefix_len++] = reg_id;
termz[prefix_len] = 0;
strcpy(scan_info->prefix, termz);
return ZEBRA_OK;
}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+