X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fzebraapi.c;h=fabd5e4037ea7bacc54e0fe4ca741ab9a49c97c2;hb=47ea1fc957c7b97bb30a26698f072109cae275e4;hp=0cf60f36d6aa472e9e93b1d9a316647414324b19;hpb=764b78fb481cf1084a5a583ffefbe8a0f32af28c;p=idzebra-moved-to-github.git diff --git a/index/zebraapi.c b/index/zebraapi.c index 0cf60f3..fabd5e4 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2002, Index Data * All rights reserved. * - * $Id: zebraapi.c,v 1.57 2002-04-16 22:31:42 adam Exp $ + * $Id: zebraapi.c,v 1.63 2002-07-25 13:06:43 adam Exp $ */ #include @@ -37,7 +37,7 @@ static void zebra_chdir (ZebraService zh) static void zebra_flush_reg (ZebraHandle zh) { - zebraExplain_flush (zh->reg->zei, 1, zh); + zebraExplain_flush (zh->reg->zei, zh); extract_flushWriteKeys (zh); zebra_index_merge (zh); @@ -50,12 +50,10 @@ static struct zebra_register *zebra_register_open (ZebraService zs, const char *reg_path); static void zebra_register_close (ZebraService zs, struct zebra_register *reg); -static int zebra_begin_read (ZebraHandle zh); -static void zebra_end_read (ZebraHandle zh); - ZebraHandle zebra_open (ZebraService zs) { ZebraHandle zh; + const char *default_encoding; if (!zs) return 0; @@ -85,6 +83,21 @@ ZebraHandle zebra_open (ZebraService zs) zh->shadow_enable = 1; + default_encoding = res_get_def(zs->global_res, "encoding", "ISO-8859-1"); + zh->record_encoding = xstrdup (default_encoding); +#if HAVE_ICONV_H + zh->iconv_to_utf8 = + iconv_open ("UTF-8", default_encoding); + if (zh->iconv_to_utf8 == (iconv_t)(-1)) + yaz_log (LOG_WARN, "iconv: %s to UTF-8 unsupported", + default_encoding); + zh->iconv_from_utf8 = + iconv_open (default_encoding, "UTF-8"); + if (zh->iconv_to_utf8 == (iconv_t)(-1)) + yaz_log (LOG_WARN, "iconv: UTF-8 to %s unsupported", + default_encoding); +#endif + zebra_mutex_cond_lock (&zs->session_lock); zh->next = zs->sessions; @@ -263,7 +276,29 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, struct ISAMC_M_s isamc_m; if (!(reg->isamb = isamb_open (reg->bfs, "isamb", - rw, key_isamc_m(res, &isamc_m)))) + rw, key_isamc_m(res, &isamc_m), 0))) + { + logf (LOG_WARN, "isamb_open"); + return 0; + } + } + if (res_get_match (res, "isam", "bc", ISAM_DEFAULT)) + { + struct ISAMC_M_s isamc_m; + + if (!(reg->isamb = isamb_open (reg->bfs, "isamb", + rw, key_isamc_m(res, &isamc_m), 1))) + { + logf (LOG_WARN, "isamb_open"); + return 0; + } + } + if (res_get_match (res, "isam", "null", ISAM_DEFAULT)) + { + struct ISAMC_M_s isamc_m; + + if (!(reg->isamb = isamb_open (reg->bfs, "isamb", + rw, key_isamc_m(res, &isamc_m), -1))) { logf (LOG_WARN, "isamb_open"); return 0; @@ -304,7 +339,7 @@ static void zebra_register_close (ZebraService zs, struct zebra_register *reg) zebra_chdir (zs); if (reg->records) { - zebraExplain_close (reg->zei, 0); + zebraExplain_close (reg->zei); dict_close (reg->dict); if (reg->matchDict) dict_close (reg->matchDict); @@ -378,6 +413,14 @@ void zebra_close (ZebraHandle zh) zebra_register_close (zh->service, zh->reg); zebra_close_res (zh); + xfree (zh->record_encoding); +#if HAVE_ICONV_H + if (zh->iconv_to_utf8 != (iconv_t) (-1)) + iconv_close (zh->iconv_to_utf8); + if (zh->iconv_from_utf8 != (iconv_t) (-1)) + iconv_close (zh->iconv_from_utf8); +#endif + xfree (zh->admin_databaseName); zebra_mutex_cond_lock (&zs->session_lock); zebra_lock_destroy (zh->lock_normal); @@ -667,6 +710,8 @@ void zebra_records_retrieve (ZebraHandle zh, ODR stream, zh->errString = odr_strdup (stream, setname); return; } + + zh->errCode = 0; if (zebra_begin_read (zh)) return; @@ -922,7 +967,7 @@ void zebra_get_state (ZebraHandle zh, char *val, int *seqno) xfree (fname); } -static int zebra_begin_read (ZebraHandle zh) +int zebra_begin_read (ZebraHandle zh) { int dirty = 0; char val; @@ -937,6 +982,9 @@ static int zebra_begin_read (ZebraHandle zh) zebra_flush_reg (zh); return 0; } +#if HAVE_SYS_TIMES_H + times (&zh->tms1); +#endif if (!zh->res) { (zh->trans_no)--; @@ -985,13 +1033,21 @@ static int zebra_begin_read (ZebraHandle zh) return 0; } -static void zebra_end_read (ZebraHandle zh) +void zebra_end_read (ZebraHandle zh) { (zh->trans_no)--; if (zh->trans_no != 0) return; +#if HAVE_SYS_TIMES_H + times (&zh->tms2); + logf (LOG_LOG, "user/system: %ld/%ld", + (long) (zh->tms2.tms_utime - zh->tms1.tms_utime), + (long) (zh->tms2.tms_stime - zh->tms1.tms_stime)); + +#endif + zebra_unlock (zh->lock_normal); zebra_unlock (zh->lock_shadow); } @@ -1093,6 +1149,8 @@ void zebra_end_trans (ZebraHandle zh) yaz_log (LOG_LOG, "zebra_end_trans"); rval = res_get (zh->res, "shadow"); + zebraExplain_runNumberIncrement (zh->reg->zei, 1); + zebra_flush_reg (zh); zebra_register_close (zh->service, zh->reg); @@ -1180,9 +1238,6 @@ int zebra_commit (ZebraHandle zh) zebra_set_state (zh, 'c', seqno); logf (LOG_LOG, "commit start"); -#ifndef WIN32 - sleep (2); -#endif bf_commitExec (bfs); #ifndef WIN32 sync (); @@ -1273,3 +1328,9 @@ void zebra_shadow_enable (ZebraHandle zh, int value) zh->shadow_enable = value; } +int zebra_record_encoding (ZebraHandle zh, const char *encoding) +{ + xfree (zh->record_encoding); + zh->record_encoding = xstrdup (encoding); + return 0; +}