projects
/
idzebra-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Allow NULL config to be given for zebra_start and zebra_start_res.
[idzebra-moved-to-github.git]
/
index
/
zebraapi.c
diff --git
a/index/zebraapi.c
b/index/zebraapi.c
index
9a85e32
..
8b393ec
100644
(file)
--- a/
index/zebraapi.c
+++ b/
index/zebraapi.c
@@
-1,4
+1,4
@@
-/* $Id: zebraapi.c,v 1.176 2005-06-10 10:55:18 adam Exp $
+/* $Id: zebraapi.c,v 1.181 2005-08-17 21:29:44 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
Copyright (C) 1995-2005
Index Data ApS
@@
-27,7
+27,8
@@
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include <io.h>
#include <process.h>
#include <direct.h>
#include <io.h>
#include <process.h>
#include <direct.h>
-#else
+#endif
+#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <unistd.h>
#endif
@@
-38,6
+39,8
@@
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include <charmap.h>
#include <idzebra/api.h>
#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)
/* simple asserts to validate the most essential input args */
#define ASSERTZH assert(zh && zh->service)
#define ASSERTZHRES assert(zh && zh->service && zh->res)
@@
-115,7
+118,7
@@
ZebraHandle zebra_open (ZebraService zs)
zh->num_basenames = 0;
zh->basenames = 0;
zh->num_basenames = 0;
zh->basenames = 0;
- zh->approx_limit = 1000000000;
+ zh->approx_limit = DEFAULT_APPROX_LIMIT;
zh->trans_no = 0;
zh->trans_w_no = 0;
zh->trans_no = 0;
zh->trans_w_no = 0;
@@
-169,9
+172,9
@@
ZebraService zebra_start_res (const char *configName, Res def_res, Res over_res)
log_level = yaz_log_module_level("zebraapi");
log_level_initialized = 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)))
{
if ((res = res_open (configName, def_res, over_res)))
{
@@
-179,10
+182,7
@@
ZebraService zebra_start_res (const char *configName, Res def_res, Res over_res)
const char *passwd_encrypt = 0;
ZebraService zh = xmalloc(sizeof(*zh));
const char *passwd_encrypt = 0;
ZebraService zh = xmalloc(sizeof(*zh));
- yaz_log (YLOG_DEBUG, "Read resources `%s'", configName);
-
zh->global_res = res;
zh->global_res = res;
- zh->configName = xstrdup(configName);
zh->sessions = 0;
zebra_chdir (zh);
zh->sessions = 0;
zebra_chdir (zh);
@@
-234,22
+234,16
@@
Dict dict_open_res (BFiles bfs, const char *name, int cache, int rw,
{
int page_size = 4096;
char resource_str[200];
{
int page_size = 4096;
char resource_str[200];
- const char *v;
sprintf (resource_str, "dict.%.100s.pagesize", name);
assert(bfs);
assert(name);
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);
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);
}
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,
static
struct zebra_register *zebra_register_open (ZebraService zs, const char *name,
int rw, int useshadow, Res res,
@@
-319,6
+313,9
@@
struct zebra_register *zebra_register_open (ZebraService zs, const char *name,
reg->sortKeys.buf = 0;
reg->sortKeys.buf_max = 0;
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->records = 0;
reg->dict = 0;
@@
-483,6
+480,10
@@
static void zebra_register_close (ZebraService zs, struct zebra_register *reg)
xfree(reg->keys.buf);
if (reg->keys.codec_handle)
iscz1_stop(reg->keys.codec_handle);
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);
xfree(reg->key_buf);
xfree(reg->name);
xfree(reg);
@@
-507,7
+508,6
@@
ZEBRA_RES zebra_stop(ZebraService zs)
recTypeClass_destroy(zs->record_classes);
nmem_destroy(zs->nmem);
res_close (zs->global_res);
recTypeClass_destroy(zs->record_classes);
nmem_destroy(zs->nmem);
res_close (zs->global_res);
- xfree(zs->configName);
xfree(zs);
return ZEBRA_OK;
}
xfree(zs);
return ZEBRA_OK;
}
@@
-693,6
+693,12
@@
static void zebra_select_register (ZebraHandle zh, const char *new_reg)
zebra_close_res(zh);
}
}
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);
+ }
}
void map_basenames_func (void *vp, const char *name, const char *value)
}
void map_basenames_func (void *vp, const char *name, const char *value)
@@
-868,7
+874,7
@@
ZEBRA_RES zebra_select_databases (ZebraHandle zh, int num_bases,
ZEBRA_RES zebra_set_approx_limit(ZebraHandle zh, zint approx_limit)
{
if (approx_limit == 0)
ZEBRA_RES zebra_set_approx_limit(ZebraHandle zh, zint approx_limit)
{
if (approx_limit == 0)
- approx_limit = 2000000000;
+ approx_limit = DEFAULT_APPROX_LIMIT;
zh->approx_limit = approx_limit;
return ZEBRA_OK;
}
zh->approx_limit = approx_limit;
return ZEBRA_OK;
}
@@
-979,12
+985,20
@@
ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream,
}
else
{
}
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]);
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_meta_records_destroy(zh, poset, num_recs);
@@
-997,7
+1011,8
@@
ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream,
ZEBRA_RES zebra_scan_PQF(ZebraHandle zh, ODR stream, const char *query,
int *position,
int *num_entries, ZebraScanEntry **entries,
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;
{
YAZ_PQF_Parser pqf_parser = yaz_pqf_create ();
Z_AttributesPlusTerm *zapt;
@@
-1011,7
+1026,8
@@
ZEBRA_RES zebra_scan_PQF(ZebraHandle zh, ODR stream, const char *query,
}
else
res = zebra_scan(zh, stream, zapt, VAL_BIB1,
}
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;
}
yaz_pqf_destroy (pqf_parser);
return res;
}
@@
-1020,9
+1036,11
@@
ZEBRA_RES zebra_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
oid_value attributeset,
int *position,
int *num_entries, ZebraScanEntry **entries,
oid_value attributeset,
int *position,
int *num_entries, ZebraScanEntry **entries,
- int *is_partial)
+ int *is_partial,
+ const char *setname)
{
ZEBRA_RES res;
{
ZEBRA_RES res;
+ RSET limit_rset = 0;
ASSERTZH;
assert(stream);
assert(zapt);
ASSERTZH;
assert(stream);
assert(zapt);
@@
-1038,9
+1056,21
@@
ZEBRA_RES zebra_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
*num_entries = 0;
return ZEBRA_FAIL;
}
*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,
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;
}
zebra_end_read (zh);
return res;
}
@@
-2002,7
+2032,6
@@
const char *zebra_get_resource(ZebraHandle zh,
const char *v;
ASSERTZH;
assert(name);
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);
v = res_get_def (zh->res, name, (char *)defaultvalue);
zebra_clearError(zh);
yaz_log(log_level, "zebra_get_resource %s:%s", name, v);