-/* $Id: zebraapi.c,v 1.173 2005-06-02 11:59:53 adam Exp $
+/* $Id: zebraapi.c,v 1.184 2005-08-22 09:04:18 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <io.h>
#include <process.h>
#include <direct.h>
-#else
+#endif
+#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <charmap.h>
#include <idzebra/api.h>
+#define DEFAULT_APPROX_LIMIT 2000000000
+
/* simple asserts to validate the most essential input args */
#define ASSERTZH assert(zh && zh->service)
#define ASSERTZHRES assert(zh && zh->service && zh->res)
zh->num_basenames = 0;
zh->basenames = 0;
+ zh->approx_limit = DEFAULT_APPROX_LIMIT;
zh->trans_no = 0;
zh->trans_w_no = 0;
zh->lock_shadow = 0;
zh->shadow_enable = 1;
+ zh->m_staticrank = 0;
default_encoding = res_get_def(zs->global_res, "encoding", "ISO-8859-1");
log_level = yaz_log_module_level("zebraapi");
log_level_initialized = 1;
}
-
- yaz_log(YLOG_LOG, "zebra_start %s %s",configName, ZEBRAVER);
- assert(configName);
+
+ yaz_log(YLOG_LOG, "zebra_start %s %s", ZEBRAVER,
+ configName ? configName : "");
if ((res = res_open (configName, def_res, over_res)))
{
const char *passwd_encrypt = 0;
ZebraService zh = xmalloc(sizeof(*zh));
- yaz_log (YLOG_DEBUG, "Read resources `%s'", configName);
-
zh->global_res = res;
- zh->configName = xstrdup(configName);
zh->sessions = 0;
zebra_chdir (zh);
{
int page_size = 4096;
char resource_str[200];
- const char *v;
sprintf (resource_str, "dict.%.100s.pagesize", name);
assert(bfs);
assert(name);
- v = res_get(res, resource_str);
- if (v)
- {
- page_size = atoi(v);
+ if (res_get_int(res, resource_str, &page_size) == ZEBRA_OK)
yaz_log(YLOG_LOG, "Using custom dictionary page size %d for %s",
page_size, name);
- }
return dict_open(bfs, name, cache, rw, compact_flag, page_size);
}
-
static
struct zebra_register *zebra_register_open (ZebraService zs, const char *name,
int rw, int useshadow, Res res,
reg->sortKeys.buf = 0;
reg->sortKeys.buf_max = 0;
+#if NATTR
+ reg->sortKeys.codec_handle = iscz1_start();
+#endif
reg->records = 0;
reg->dict = 0;
reg->key_file_no = 0;
reg->ptr_i = 0;
- zebraRankInstall (reg, rank1_class);
- zebraRankInstall (reg, rankzv_class);
+ zebraRankInstall (reg, rank_1_class);
+ zebraRankInstall (reg, rank_zv_class);
+ zebraRankInstall (reg, rank_static_class);
recordCompression = res_get_def (res, "recordCompression", "none");
if (!strcmp (recordCompression, "none"))
xfree(reg->keys.buf);
if (reg->keys.codec_handle)
iscz1_stop(reg->keys.codec_handle);
+#if NATTR
+ if (reg->sortKeys.codec_handle)
+ iscz1_stop(reg->sortKeys.codec_handle);
+#endif
xfree(reg->key_buf);
xfree(reg->name);
xfree(reg);
recTypeClass_destroy(zs->record_classes);
nmem_destroy(zs->nmem);
res_close (zs->global_res);
- xfree(zs->configName);
xfree(zs);
return ZEBRA_OK;
}
zebra_close_res(zh);
}
}
+ if (zh->res)
+ {
+ int approx = 0;
+ if (res_get_int(zh->res, "estimatehits", &approx) == ZEBRA_OK)
+ zebra_set_approx_limit(zh, approx);
+ }
+ if (zh->res)
+ {
+ if (res_get_int(zh->res, "staticrank", &zh->m_staticrank) == ZEBRA_OK)
+ yaz_log(YLOG_LOG, "static rank set and is %d", zh->m_staticrank);
+ else
+ yaz_log(YLOG_LOG, "static rank unset");
+ }
}
void map_basenames_func (void *vp, const char *name, const char *value)
return ZEBRA_OK;
}
+ZEBRA_RES zebra_set_approx_limit(ZebraHandle zh, zint approx_limit)
+{
+ if (approx_limit == 0)
+ approx_limit = DEFAULT_APPROX_LIMIT;
+ zh->approx_limit = approx_limit;
+ return ZEBRA_OK;
+}
+
ZEBRA_RES zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
const char *setname, zint *hits)
{
{
char *buf;
int len;
+ zebra_snippets *hit_snippet = zebra_snippets_create();
- zebra_get_hit_vector(zh, setname, poset[i].sysno);
+ zebra_snippets_hit_vector(zh, setname, poset[i].sysno,
+ hit_snippet);
recs[i].errCode =
zebra_record_fetch(zh, poset[i].sysno, poset[i].score,
+ hit_snippet,
stream, input_format, comp,
&recs[i].format, &buf, &len,
&recs[i].base, &recs[i].errString);
+
recs[i].len = len;
if (len > 0)
{
recs[i].buf = buf;
recs[i].score = poset[i].score;
recs[i].sysno = poset[i].sysno;
+ zebra_snippets_destroy(hit_snippet);
}
else
{
- if (ret == ZEBRA_OK) /* only need to set it once */
+ /* only need to set it once */
+ if (pos_array[i] < zh->approx_limit && ret == ZEBRA_OK)
+ {
zebra_setError_zint(zh,
YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE,
pos_array[i]);
- ret = ZEBRA_FAIL;
- break;
+ ret = ZEBRA_FAIL;
+ break;
+ }
+ recs[i].buf = 0; /* no record and no error issued */
+ recs[i].len = 0;
+ recs[i].errCode = 0;
+ recs[i].format = VAL_NONE;
+ recs[i].sysno = 0;
}
}
zebra_meta_records_destroy(zh, poset, num_recs);
ZEBRA_RES zebra_scan_PQF(ZebraHandle zh, ODR stream, const char *query,
int *position,
int *num_entries, ZebraScanEntry **entries,
- int *is_partial)
+ int *is_partial,
+ const char *setname)
{
YAZ_PQF_Parser pqf_parser = yaz_pqf_create ();
Z_AttributesPlusTerm *zapt;
}
else
res = zebra_scan(zh, stream, zapt, VAL_BIB1,
- position, num_entries, entries, is_partial);
+ position, num_entries, entries, is_partial,
+ setname);
yaz_pqf_destroy (pqf_parser);
return res;
}
oid_value attributeset,
int *position,
int *num_entries, ZebraScanEntry **entries,
- int *is_partial)
+ int *is_partial,
+ const char *setname)
{
ZEBRA_RES res;
+ RSET limit_rset = 0;
ASSERTZH;
assert(stream);
assert(zapt);
*num_entries = 0;
return ZEBRA_FAIL;
}
+ if (setname)
+ {
+ limit_rset = resultSetRef(zh, setname);
+ if (!limit_rset)
+ {
+ zebra_setError(zh,
+ YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
+ setname);
+ zebra_end_read (zh);
+ return ZEBRA_FAIL;
+ }
+ }
res = rpn_scan (zh, stream, zapt, attributeset,
zh->num_basenames, zh->basenames, position,
- num_entries, entries, is_partial, 0, 0);
+ num_entries, entries, is_partial, limit_rset, 0);
zebra_end_read (zh);
return res;
}
Odr_oct *oct = fragment->u.notExternallyTagged;
sysno = 0;
- if ( zebra_update_record(zh,
- 0, /* record Type */
- &sysno,
- 0, /* match */
- 0, /* fname */
- oct->buf, oct->len,
- 0) == ZEBRA_FAIL)
+ if (zebra_update_record(zh,
+ 0, /* record Type */
+ &sysno,
+ 0, /* match */
+ 0, /* fname */
+ (const char *) oct->buf, oct->len,
+ 0) == ZEBRA_FAIL)
res = ZEBRA_FAIL;
}
}
const char *v;
ASSERTZH;
assert(name);
- assert(defaultvalue);
v = res_get_def (zh->res, name, (char *)defaultvalue);
zebra_clearError(zh);
yaz_log(log_level, "zebra_get_resource %s:%s", name, v);