X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=index%2Fzebraapi.c;h=3d9d89f246a9de2427fd4fd41cc5af20b12d4776;hp=0b854ea60dbc82bd1f478d8720201754b8a05f24;hb=13bf0c380e98816595127291b64368dd9b8ca639;hpb=4a3a97df9d47b8d099e403308f8015f130366994 diff --git a/index/zebraapi.c b/index/zebraapi.c index 0b854ea..3d9d89f 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.120 2004-07-28 08:15:45 adam Exp $ +/* $Id: zebraapi.c,v 1.128 2004-09-03 14:59:49 heikki 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,7 +36,7 @@ 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) @@ -249,6 +250,10 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, reg->keys.buf_max = 0; reg->keys.buf = 0; +#if IT_KEY_NEW + reg->keys.codec_handle = iscz1_start(); +#endif + reg->sortKeys.buf = 0; reg->sortKeys.buf_max = 0; @@ -257,9 +262,7 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, reg->sortIdx = 0; reg->isams = 0; reg->matchDict = 0; - reg->isam = 0; reg->isamc = 0; - reg->isamd = 0; reg->isamb = 0; reg->zei = 0; reg->matchDict = 0; @@ -305,15 +308,6 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, return 0; } } - if (res_get_match (res, "isam", "i", ISAM_DEFAULT)) - { - if (!(reg->isam = is_open (reg->bfs, FNAME_ISAM, key_compare, rw, - sizeof (struct it_key), res))) - { - logf (LOG_WARN, "is_open"); - return 0; - } - } if (res_get_match (res, "isam", "c", ISAM_DEFAULT)) { struct ISAMC_M_s isamc_m; @@ -324,17 +318,6 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, return 0; } } - if (res_get_match (res, "isam", "d", ISAM_DEFAULT)) - { - struct ISAMD_M_s isamd_m; - - if (!(reg->isamd = isamd_open (reg->bfs, FNAME_ISAMD, - rw, key_isamd_m(res, &isamd_m)))) - { - logf (LOG_WARN, "isamd_open"); - return 0; - } - } if (res_get_match (res, "isam", "b", ISAM_DEFAULT)) { struct ISAMC_M_s isamc_m; @@ -420,12 +403,8 @@ static void zebra_register_close (ZebraService zs, struct zebra_register *reg) sortIdx_close (reg->sortIdx); if (reg->isams) isams_close (reg->isams); - if (reg->isam) - is_close (reg->isam); if (reg->isamc) isc_close (reg->isamc); - if (reg->isamd) - isamd_close (reg->isamd); if (reg->isamb) isamb_close (reg->isamb); rec_close (®->records); @@ -439,6 +418,10 @@ static void zebra_register_close (ZebraService zs, struct zebra_register *reg) xfree (reg->sortKeys.buf); xfree (reg->keys.buf); +#if IT_KEY_NEW + if (reg->keys.codec_handle) + iscz1_stop(reg->keys.codec_handle); +#endif xfree (reg->key_buf); xfree (reg->name); @@ -783,6 +766,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; @@ -798,8 +783,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_LOG,"limiting hits to "ZINT_FORMAT, maxhits); + *hits=maxhits; /* round it down to two digits, to look like rounded */ + } + else + *hits = zh->hits; return 0; } @@ -1028,7 +1026,7 @@ int zebra_admin_import_end (ZebraHandle zh) int zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment) { - int sysno; + SYSNO sysno; int i; ASSERTZH; yaz_log(LOG_API,"zebra_admin_import_segment"); @@ -1072,7 +1070,7 @@ int zebra_admin_exchange_record (ZebraHandle zh, /* 3 = delete. Fail if does not exist */ /* 4 = update. Insert/replace */ { - int sysno = 0; + SYSNO sysno = 0; char *rinfo = 0; char recid_z[256]; ASSERTZH; @@ -1579,7 +1577,8 @@ int zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status) zebra_register_close (zh->service, zh->reg); zh->reg = 0; - yaz_log (LOG_LOG, "Records: %7d i/u/d %d/%d/%d", + yaz_log (LOG_LOG, "Records: "ZINT_FORMAT" i/u/d " + ZINT_FORMAT"/"ZINT_FORMAT"/"ZINT_FORMAT, zh->records_processed, zh->records_inserted, zh->records_updated, zh->records_deleted); @@ -1948,17 +1947,17 @@ NOTE: Now returns 0 at success and updates sysno, which is an int* int zebra_add_record(ZebraHandle zh, const char *buf, int buf_size) { - int sysno = 0; + SYSNO sysno = 0; return zebra_update_record(zh, 0, &sysno, 0, 0, buf, buf_size, 0); } int zebra_insert_record (ZebraHandle zh, const char *recordType, - int *sysno, const char *match, const char *fname, + SYSNO *sysno, const char *match, const char *fname, const char *buf, int buf_size, int force_update) { int res; - yaz_log(LOG_API,"zebra_insert_record sysno=%d", *sysno); + yaz_log(LOG_API,"zebra_insert_record sysno=" ZINT_FORMAT, *sysno); if (buf_size < 1) buf_size = strlen(buf); @@ -1978,13 +1977,13 @@ int zebra_insert_record (ZebraHandle zh, int zebra_update_record (ZebraHandle zh, const char *recordType, - int* sysno, const char *match, const char *fname, + SYSNO* sysno, const char *match, const char *fname, const char *buf, int buf_size, int force_update) { int res; - yaz_log(LOG_API,"zebra_update_record sysno=%d", *sysno); + yaz_log(LOG_API,"zebra_update_record sysno=" ZINT_FORMAT, *sysno); if (buf_size < 1) buf_size = strlen(buf); @@ -1998,19 +1997,18 @@ int zebra_update_record (ZebraHandle zh, match, fname, force_update, 1); /* allow_update */ - yaz_log(LOG_LOG, "zebra_update_record returned res=%d", res); zebra_end_trans(zh); return res; } int zebra_delete_record (ZebraHandle zh, const char *recordType, - int *sysno, const char *match, const char *fname, + SYSNO *sysno, const char *match, const char *fname, const char *buf, int buf_size, int force_update) { int res; - yaz_log(LOG_API,"zebra_delete_record sysno=%d", *sysno); + yaz_log(LOG_API,"zebra_delete_record sysno=" ZINT_FORMAT, *sysno); if (buf_size < 1) buf_size = strlen(buf); @@ -2061,7 +2059,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,