X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fzebraapi.c;h=22d249a871dbad0846bac8154cdd198db434f503;hb=d2462e5d299a6772dace31311998d3fccacf86af;hp=054bc0b8a9d30df4beff47fa385a1bf372806099;hpb=8e1f2d86ffca33a892160b77147deb37f95d75d1;p=idzebra-moved-to-github.git diff --git a/index/zebraapi.c b/index/zebraapi.c index 054bc0b..22d249a 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.124 2004-08-10 08:19:15 heikki Exp $ +/* $Id: zebraapi.c,v 1.131 2004-09-13 09:02:16 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -22,6 +22,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include +#include #ifdef WIN32 #include #include @@ -35,20 +36,14 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include "index.h" #include -#include "zebraapi.h" +#include /* simple asserts to validate the most essential input args */ #define ASSERTZH assert(zh && zh->service) #define ASSERTZHRES assert(zh && zh->service && zh->res) #define ASSERTZS assert(zs) -/* A simple log macro */ -/* don't break with older yazen that lack log_app2 */ -#ifdef LOG_APP2 #define LOG_API LOG_APP2 -#else -#define LOG_API LOG_DEBUG -#endif static Res zebra_open_res (ZebraHandle zh); static void zebra_close_res (ZebraHandle zh); @@ -156,7 +151,7 @@ ZebraService zebra_start_res (const char *configName, Res def_res, Res over_res) { Res res; - yaz_log(LOG_API|LOG_LOG,"zebra_start %s",configName); + yaz_log(LOG_API,"zebra_start %s",configName); if ((res = res_open (configName, def_res, over_res))) { @@ -195,6 +190,25 @@ void zebra_pidfname(ZebraService zs, char *path) strcat(path, "zebrasrv.pid"); } +Dict dict_open_res (BFiles bfs, const char *name, int cache, int rw, + int compact_flag, Res res) +{ + int page_size = 4096; + char resource_str[200]; + const char *v; + sprintf (resource_str, "dict.%.100s.pagesize", name); + + v = res_get(res, resource_str); + if (v) + { + page_size = atoi(v); + yaz_log(LOG_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, @@ -218,7 +232,7 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, assert (res); - yaz_log (LOG_LOG|LOG_API, "zebra_register_open rw = %d useshadow=%d p=%p,n=%s,rp=%s", + yaz_log (LOG_DEBUG, "zebra_register_open rw=%d useshadow=%d p=%p n=%s rp=%s", rw, useshadow, reg, name, reg_path ? reg_path : "(none)"); reg->dh = data1_createx (DATA1_FLAG_XML); @@ -235,7 +249,7 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, getcwd(cwd, sizeof(cwd)-1); profilePath = res_get_def(res, "profilePath", DEFAULT_PROFILE_PATH); - yaz_log(LOG_LOG, "profilePath=%s cwd=%s", profilePath, cwd); + yaz_log(LOG_DEBUG, "profilePath=%s cwd=%s", profilePath, cwd); data1_set_tabpath (reg->dh, profilePath); data1_set_tabroot (reg->dh, reg_path); @@ -285,9 +299,9 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, } if (rw) { - reg->matchDict = dict_open (reg->bfs, GMATCH_DICT, 20, 1, 0); + reg->matchDict = dict_open_res (reg->bfs, GMATCH_DICT, 20, 1, 0, res); } - if (!(reg->dict = dict_open (reg->bfs, FNAME_DICT, 40, rw, 0))) + if (!(reg->dict = dict_open_res (reg->bfs, FNAME_DICT, 40, rw, 0, res))) { logf (LOG_WARN, "dict_open"); return 0; @@ -390,7 +404,7 @@ int zebra_admin_start (ZebraHandle zh) static void zebra_register_close (ZebraService zs, struct zebra_register *reg) { ASSERTZS; - yaz_log(LOG_LOG|LOG_API, "zebra_register_close p=%p", reg); + yaz_log(LOG_DEBUG, "zebra_register_close p=%p", reg); reg->stop_flag = 0; zebra_chdir (zs); if (reg->records) @@ -431,7 +445,7 @@ int zebra_stop(ZebraService zs) { if (!zs) return 0; - yaz_log (LOG_LOG|LOG_API, "zebra_stop"); + yaz_log (LOG_API, "zebra_stop"); while (zs->sessions) { @@ -672,7 +686,7 @@ void map_basenames (ZebraHandle zh, ODR stream, *num_bases = info.new_num_bases; *basenames = info.new_basenames; for (i = 0; i<*num_bases; i++) - logf (LOG_LOG, "base %s", (*basenames)[i]); + logf (LOG_DEBUG, "base %s", (*basenames)[i]); } int zebra_select_database (ZebraHandle zh, const char *basename) @@ -765,6 +779,8 @@ int zebra_select_databases (ZebraHandle zh, int num_bases, int zebra_search_RPN (ZebraHandle zh, ODR o, Z_RPNQuery *query, const char *setname, int *hits) { + const char *max; + zint maxhits; ASSERTZH; yaz_log(LOG_API,"zebra_search_rpn"); zh->errCode=0; @@ -780,8 +796,21 @@ int zebra_search_RPN (ZebraHandle zh, ODR o, zh->num_basenames, zh->basenames, setname); zebra_end_read (zh); - - *hits = zh->hits; + max = res_get (zh->res, "maxhits"); + if (max) + maxhits=atoi(max); + else { + int i=0; + maxhits=INT_MAX; + while (maxhits>100) { maxhits/=10; i++;} + while (i--) maxhits *= 10; + } + if (zh->hits > maxhits) { /* too large for yaz to handle */ + logf(LOG_DEBUG,"limiting hits to "ZINT_FORMAT, maxhits); + *hits=maxhits; /* round it down to two digits, to look like rounded */ + } + else + *hits = zh->hits; return 0; } @@ -1374,7 +1403,7 @@ int zebra_begin_trans (ZebraHandle zh, int rw) zebra_get_state (zh, &val, &seqno); if (val == 'c') { - yaz_log (LOG_LOG, "previous transaction didn't finish commit"); + yaz_log (LOG_WARN, "previous transaction didn't finish commit"); zebra_unlock (zh->lock_shadow); zebra_unlock (zh->lock_normal); zebra_commit (zh); @@ -1386,7 +1415,7 @@ int zebra_begin_trans (ZebraHandle zh, int rw) { BFiles bfs = bfs_create (res_get (zh->res, "shadow"), zh->path_reg); - yaz_log (LOG_LOG, "previous transaction didn't reach commit"); + yaz_log (LOG_WARN, "previous transaction didn't reach commit"); bf_commitClean (bfs, rval); bfs_destroy (bfs); } @@ -1463,13 +1492,13 @@ int zebra_begin_trans (ZebraHandle zh, int rw) dirty = 1; else if (seqno != zh->reg->seqno) { - yaz_log (LOG_LOG, "reopen seqno cur/old %d/%d", + yaz_log (LOG_DEBUG, "reopen seqno cur/old %d/%d", seqno, zh->reg->seqno); dirty = 1; } else if (zh->reg->last_val != val) { - yaz_log (LOG_LOG, "reopen last cur/old %d/%d", + yaz_log (LOG_DEBUG, "reopen last cur/old %d/%d", val, zh->reg->last_val); dirty = 1; } @@ -1549,7 +1578,7 @@ int zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status) zh->trans_no--; zh->trans_w_no = 0; - yaz_log (LOG_LOG, "zebra_end_trans"); + yaz_log (LOG_DEBUG, "zebra_end_trans"); rval = res_get (zh->res, "shadow"); zebraExplain_runNumberIncrement (zh->reg->zei, 1); @@ -1575,7 +1604,7 @@ int zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status) if (val != 'd') { BFiles bfs = bfs_create (rval, zh->path_reg); - yaz_log (LOG_LOG, "deleting shadow stuff val=%c", val); + yaz_log (LOG_DEBUG, "deleting shadow val=%c", val); bf_commitClean (bfs, rval); bfs_destroy (bfs); } @@ -1603,7 +1632,7 @@ int zebra_repository_update (ZebraHandle zh, const char *path) { ASSERTZH; zh->errCode=0; - logf (LOG_LOG|LOG_API, "updating %s", path); + logf (LOG_API, "updating %s", path); repositoryUpdate (zh, path); return zh->errCode; } @@ -1612,7 +1641,7 @@ int zebra_repository_delete (ZebraHandle zh, const char *path) { ASSERTZH; zh->errCode=0; - logf (LOG_LOG|LOG_API, "deleting %s", path); + logf (LOG_API, "deleting %s", path); repositoryDelete (zh, path); return zh->errCode; } @@ -1665,13 +1694,13 @@ static int zebra_commit_ex (ZebraHandle zh, int clean_only) { zebra_set_state (zh, 'c', seqno); - logf (LOG_LOG, "commit start"); + logf (LOG_DEBUG, "commit start"); bf_commitExec (bfs); #ifndef WIN32 sync (); #endif } - logf (LOG_LOG, "commit clean"); + logf (LOG_DEBUG, "commit clean"); bf_commitClean (bfs, rval); seqno++; zebra_set_state (zh, 'o', seqno); @@ -1716,6 +1745,8 @@ int zebra_init (ZebraHandle zh) bfs = bfs_create (res_get (zh->service->global_res, "register"), zh->path_reg); + if (!bfs) + return -1; if (rval && *rval) bf_cache (bfs, rval); @@ -1941,7 +1972,7 @@ int zebra_insert_record (ZebraHandle zh, const char *buf, int buf_size, int force_update) { int res; - yaz_log(LOG_API,"zebra_insert_record sysno=" ZINT_FORMAT, *sysno); + yaz_log(LOG_API, "zebra_insert_record sysno=" ZINT_FORMAT, *sysno); if (buf_size < 1) buf_size = strlen(buf); @@ -1967,7 +1998,7 @@ int zebra_update_record (ZebraHandle zh, { int res; - yaz_log(LOG_API,"zebra_update_record sysno=" ZINT_FORMAT, *sysno); + yaz_log(LOG_API, "zebra_update_record sysno=" ZINT_FORMAT, *sysno); if (buf_size < 1) buf_size = strlen(buf); @@ -1992,7 +2023,7 @@ int zebra_delete_record (ZebraHandle zh, int force_update) { int res; - yaz_log(LOG_API,"zebra_delete_record sysno=" ZINT_FORMAT, *sysno); + yaz_log(LOG_API, "zebra_delete_record sysno=" ZINT_FORMAT, *sysno); if (buf_size < 1) buf_size = strlen(buf); @@ -2043,7 +2074,6 @@ int zebra_search_PQF (ZebraHandle zh, const char *pqf_query, /* --------------------------------------------------------------------------- Sort - a simplified interface, with optional read locks. - FIXME - This is a horrible name, will conflict with half the applications */ int zebra_sort_by_specstr (ZebraHandle zh, ODR stream,