X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=index%2Fzebraapi.c;h=e3b7f8e05664c30b4a35e1b979c5362355d0fa2a;hb=ac5747296ef5b85e2125da04fa1f7d33852ad971;hp=02fa99d1cc7be17daf12a1ad8112ab2c2309d0a1;hpb=066ce352a46a7e50987bab404994d199eef748ff;p=idzebra-moved-to-github.git diff --git a/index/zebraapi.c b/index/zebraapi.c index 02fa99d..e3b7f8e 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.76 2002-10-30 14:35:09 adam Exp $ +/* $Id: zebraapi.c,v 1.87 2003-03-04 23:05:30 pop Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -35,13 +35,22 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include "index.h" #include +#include "zebraapi.h" + +/* 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) static Res zebra_open_res (ZebraHandle zh); static void zebra_close_res (ZebraHandle zh); -static void zebra_chdir (ZebraService zh) + +static void zebra_chdir (ZebraService zs) { - const char *dir = res_get (zh->global_res, "chdir"); + const char *dir ; + ASSERTZS; + dir = res_get (zs->global_res, "chdir"); if (!dir) return; logf (LOG_DEBUG, "chdir %s", dir); @@ -54,6 +63,8 @@ static void zebra_chdir (ZebraService zh) static void zebra_flush_reg (ZebraHandle zh) { + ASSERTZH; + zh->errCode=0; zebraExplain_flush (zh->reg->zei, zh); extract_flushWriteKeys (zh); @@ -71,6 +82,7 @@ ZebraHandle zebra_open (ZebraService zs) { ZebraHandle zh; const char *default_encoding; + ASSERTZS; if (!zs) return 0; @@ -169,6 +181,8 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, int record_compression = REC_COMPRESS_NONE; char *recordCompression = 0; + ASSERTZS; + reg = xmalloc (sizeof(*reg)); assert (name); @@ -206,6 +220,8 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, reg->keys.buf_max = 0; reg->keys.buf = 0; + reg->sortKeys.buf = 0; + reg->sortKeys.buf_max = 0; reg->records = 0; reg->dict = 0; @@ -218,8 +234,10 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, reg->isamb = 0; reg->zei = 0; reg->matchDict = 0; + reg->key_file_no = 0; zebraRankInstall (reg, rank1_class); + zebraRankInstall (reg, rankzv_class); recordCompression = res_get_def (res, "recordCompression", "none"); if (!strcmp (recordCompression, "none")) @@ -334,6 +352,9 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, void zebra_admin_shutdown (ZebraHandle zh) { + ASSERTZH; + zh->errCode=0; + zebra_mutex_cond_lock (&zh->service->session_lock); zh->service->stop_flag = 1; zebra_mutex_cond_unlock (&zh->service->session_lock); @@ -341,14 +362,17 @@ void zebra_admin_shutdown (ZebraHandle zh) void zebra_admin_start (ZebraHandle zh) { - ZebraService zs = zh->service; - zh->errCode = 0; + ZebraService zs; + ASSERTZH; + zh->errCode=0; + zs = zh->service; zebra_mutex_cond_lock (&zs->session_lock); zebra_mutex_cond_unlock (&zs->session_lock); } static void zebra_register_close (ZebraService zs, struct zebra_register *reg) { + ASSERTZS; yaz_log(LOG_DEBUG, "zebra_register_close p=%p", reg); reg->stop_flag = 0; zebra_chdir (zs); @@ -378,16 +402,18 @@ static void zebra_register_close (ZebraService zs, struct zebra_register *reg) bfs_destroy (reg->bfs); data1_destroy (reg->dh); + xfree (reg->sortKeys.buf); + xfree (reg->keys.buf); + xfree (reg->key_buf); xfree (reg->name); xfree (reg); - yaz_log(LOG_DEBUG, "zebra_register_close 2"); } void zebra_stop(ZebraService zs) { if (!zs) - return ; + return ; yaz_log (LOG_LOG, "zebra_stop"); while (zs->sessions) @@ -410,23 +436,29 @@ void zebra_close (ZebraHandle zh) { ZebraService zs; struct zebra_session **sp; + int i; if (!zh) return; - + ASSERTZH; + zh->errCode=0; + zs = zh->service; yaz_log (LOG_DEBUG, "zebra_close zh=%p", zh); if (!zh) - return ; + return ; resultSetDestroy (zh, -1, 0, 0); - if (zh->reg) zebra_register_close (zh->service, zh->reg); zebra_close_res (zh); xfree (zh->record_encoding); + for (i = 0; i < zh->num_basenames; i++) + xfree (zh->basenames[i]); + xfree (zh->basenames); + if (zh->iconv_to_utf8 != 0) yaz_iconv_close (zh->iconv_to_utf8); if (zh->iconv_from_utf8 != 0) @@ -447,10 +479,9 @@ void zebra_close (ZebraHandle zh) } sp = &(*sp)->next; } -// if (!zs->sessions && zs->stop_flag) -// zebra_register_deactivate(zs); zebra_mutex_cond_unlock (&zs->session_lock); xfree (zh->reg_name); + zh->service=0; /* more likely to trigger an assert */ xfree (zh); } @@ -468,6 +499,9 @@ static Res zebra_open_res (ZebraHandle zh) { Res res = 0; char fname[512]; + ASSERTZH; + zh->errCode=0; + if (zh->path_reg) { sprintf (fname, "%.200s/zebra.cfg", zh->path_reg); @@ -489,6 +523,8 @@ static Res zebra_open_res (ZebraHandle zh) static void zebra_close_res (ZebraHandle zh) { + ASSERTZH; + zh->errCode=0; if (zh->res != zh->service->global_res) res_close (zh->res); zh->res = 0; @@ -496,6 +532,8 @@ static void zebra_close_res (ZebraHandle zh) static int zebra_select_register (ZebraHandle zh, const char *new_reg) { + ASSERTZH; + zh->errCode=0; if (zh->res && strcmp (zh->reg_name, new_reg) == 0) return 0; if (!zh->res) @@ -572,7 +610,7 @@ void map_basenames_func (void *vp, const char *name, const char *value) return ; no--; for (i = 0; inum_bases; i++) - if (p->basenames[i] && !strcmp (p->basenames[i], fromdb)) + if (p->basenames[i] && !STRCASECMP (p->basenames[i], fromdb)) { p->basenames[i] = 0; for (i = 0; i < no; i++) @@ -592,6 +630,8 @@ void map_basenames (ZebraHandle zh, ODR stream, struct map_baseinfo info; struct map_baseinfo *p = &info; int i; + ASSERTZH; + zh->errCode=0; info.zh = zh; info.num_bases = *num_bases; @@ -618,6 +658,8 @@ void map_basenames (ZebraHandle zh, ODR stream, int zebra_select_database (ZebraHandle zh, const char *basename) { + ASSERTZH; + zh->errCode=0; return zebra_select_databases (zh, 1, &basename); } @@ -628,6 +670,8 @@ int zebra_select_databases (ZebraHandle zh, int num_bases, const char *cp; int len = 0; char *new_reg = 0; + ASSERTZH; + zh->errCode=0; if (num_bases < 1) { @@ -699,6 +743,8 @@ int zebra_select_databases (ZebraHandle zh, int num_bases, void zebra_search_rpn (ZebraHandle zh, ODR decode, ODR stream, Z_RPNQuery *query, const char *setname, int *hits) { + ASSERTZH; + zh->errCode=0; zh->hits = 0; *hits = 0; @@ -719,6 +765,8 @@ void zebra_records_retrieve (ZebraHandle zh, ODR stream, { ZebraPosSet poset; int i, *pos_array; + ASSERTZH; + zh->errCode=0; if (!zh->res) { @@ -785,6 +833,8 @@ void zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, int *position, int *num_entries, ZebraScanEntry **entries, int *is_partial) { + ASSERTZH; + zh->errCode=0; if (zebra_begin_read (zh)) { *entries = 0; @@ -802,6 +852,8 @@ void zebra_sort (ZebraHandle zh, ODR stream, const char *output_setname, Z_SortKeySpecList *sort_sequence, int *sort_status) { + ASSERTZH; + zh->errCode=0; if (zebra_begin_read (zh)) return; resultSetSort (zh, stream->mem, num_input_setnames, input_setnames, @@ -814,6 +866,8 @@ int zebra_deleleResultSet(ZebraHandle zh, int function, int *statuses) { int i, status; + ASSERTZH; + zh->errCode=0; if (zebra_begin_read(zh)) return Z_DeleteStatus_systemProblemAtTarget; switch (function) @@ -835,22 +889,31 @@ int zebra_deleleResultSet(ZebraHandle zh, int function, int zebra_errCode (ZebraHandle zh) { - return zh->errCode; + if (zh) + return zh->errCode; + return 0; } const char *zebra_errString (ZebraHandle zh) { - return diagbib1_str (zh->errCode); + if (zh) + return diagbib1_str (zh->errCode); + return ""; } char *zebra_errAdd (ZebraHandle zh) { - return zh->errString; + if (zh) + return zh->errString; + return ""; } int zebra_auth (ZebraHandle zh, const char *user, const char *pass) { - ZebraService zs = zh->service; + ZebraService zs; + ASSERTZH; + zh->errCode=0; + zs= zh->service; if (!zs->passwd_db || !passwd_db_auth (zs->passwd_db, user, pass)) { logf(LOG_APP,"AUTHOK:%s", user?user:"ANONYMOUS"); @@ -864,6 +927,8 @@ int zebra_auth (ZebraHandle zh, const char *user, const char *pass) void zebra_admin_import_begin (ZebraHandle zh, const char *database, const char *record_type) { + ASSERTZH; + zh->errCode=0; if (zebra_select_database(zh, database)) return; zebra_begin_trans (zh); @@ -873,6 +938,8 @@ void zebra_admin_import_begin (ZebraHandle zh, const char *database, void zebra_admin_import_end (ZebraHandle zh) { + ASSERTZH; + zh->errCode=0; zebra_end_trans (zh); } @@ -880,6 +947,8 @@ void zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment) { int sysno; int i; + ASSERTZH; + zh->errCode=0; for (i = 0; inum_segmentRecords; i++) { Z_NamePlusRecord *npr = segment->segmentRecords[i]; @@ -922,6 +991,8 @@ int zebra_admin_exchange_record (ZebraHandle zh, int sysno = 0; char *rinfo = 0; char recid_z[256]; + ASSERTZH; + zh->errCode=0; if (!recid_buf || recid_len <= 0 || recid_len >= sizeof(recid_z)) return -1; @@ -957,6 +1028,8 @@ int zebra_admin_exchange_record (ZebraHandle zh, void zebra_admin_create (ZebraHandle zh, const char *database) { ZebraService zs; + ASSERTZH; + zh->errCode=0; if (zebra_select_database (zh, database)) return; @@ -978,6 +1051,8 @@ int zebra_string_norm (ZebraHandle zh, unsigned reg_id, char *output_str, int output_len) { WRBUF wrbuf; + ASSERTZH; + zh->errCode=0; if (!zh->reg->zebra_maps) return -1; wrbuf = zebra_replace(zh->reg->zebra_maps, reg_id, "", @@ -999,6 +1074,8 @@ void zebra_set_state (ZebraHandle zh, int val, int seqno) char *fname; long p = getpid(); FILE *f; + ASSERTZH; + zh->errCode=0; sprintf (state_fname, "state.%s.LCK", zh->reg_name); fname = zebra_mk_fname (res_get(zh->res, "lockDir"), state_fname); @@ -1016,6 +1093,8 @@ void zebra_get_state (ZebraHandle zh, char *val, int *seqno) char *fname; FILE *f; + ASSERTZH; + zh->errCode=0; sprintf (state_fname, "state.%s.LCK", zh->reg_name); fname = zebra_mk_fname (res_get(zh->res, "lockDir"), state_fname); f = fopen (fname, "r"); @@ -1035,6 +1114,7 @@ int zebra_begin_read (ZebraHandle zh) int dirty = 0; char val; int seqno; + ASSERTZH; assert (zh->res); @@ -1045,6 +1125,7 @@ int zebra_begin_read (ZebraHandle zh) zebra_flush_reg (zh); return 0; } + zh->errCode=0; #if HAVE_SYS_TIMES_H times (&zh->tms1); #endif @@ -1104,11 +1185,11 @@ int zebra_begin_read (ZebraHandle zh) void zebra_end_read (ZebraHandle zh) { + ASSERTZH; (zh->trans_no)--; if (zh->trans_no != 0) return; - #if HAVE_SYS_TIMES_H times (&zh->tms2); logf (LOG_LOG, "user/system: %ld/%ld", @@ -1127,6 +1208,7 @@ void zebra_begin_trans (ZebraHandle zh) int seqno = 0; char val = '?'; const char *rval = 0; + ASSERTZHRES; assert (zh->res); @@ -1135,6 +1217,7 @@ void zebra_begin_trans (ZebraHandle zh) { return; } + zh->errCode=0; yaz_log (LOG_LOG, "zebra_begin_trans"); @@ -1205,16 +1288,29 @@ void zebra_begin_trans (ZebraHandle zh) zh->reg->seqno = seqno; } -void zebra_end_trans (ZebraHandle zh) +void zebra_end_trans (ZebraHandle zh) { + ZebraTransactionStatus dummy; + zebra_end_transaction(zh, &dummy); +} + +void zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status) { char val; int seqno; const char *rval; + ASSERTZH; + + status->processed = 0; + status->inserted = 0; + status->updated = 0; + status->deleted = 0; + status->utime = 0; + status->stime = 0; + zh->trans_no--; if (zh->trans_no != 0) return; - yaz_log (LOG_LOG, "zebra_end_trans"); rval = res_get (zh->res, "shadow"); @@ -1225,11 +1321,15 @@ void zebra_end_trans (ZebraHandle zh) zebra_register_close (zh->service, zh->reg); zh->reg = 0; - yaz_log (LOG_LOG, "Records: %7d i/u/d %d/%d/%d", zh->records_processed, zh->records_inserted, zh->records_updated, zh->records_deleted); + status->processed = zh->records_processed; + status->inserted = zh->records_inserted; + status->updated = zh->records_updated; + status->deleted = zh->records_deleted; + zebra_get_state (zh, &val, &seqno); if (val != 'd') { @@ -1251,23 +1351,33 @@ void zebra_end_trans (ZebraHandle zh) (long) (zh->tms2.tms_utime - zh->tms1.tms_utime), (long) (zh->tms2.tms_stime - zh->tms1.tms_stime)); + status->utime = (long) (zh->tms2.tms_utime - zh->tms1.tms_utime); + status->stime = (long) (zh->tms2.tms_stime - zh->tms1.tms_stime); #endif + + return; } void zebra_repository_update (ZebraHandle zh) { + ASSERTZH; + zh->errCode=0; logf (LOG_LOG, "updating %s", zh->rGroup.path); repositoryUpdate (zh); } void zebra_repository_delete (ZebraHandle zh) { + ASSERTZH; + zh->errCode=0; logf (LOG_LOG, "deleting %s", zh->rGroup.path); repositoryDelete (zh); } void zebra_repository_show (ZebraHandle zh) { + ASSERTZH; + zh->errCode=0; repositoryShow (zh); } @@ -1277,6 +1387,8 @@ int zebra_commit (ZebraHandle zh) char val; const char *rval; BFiles bfs; + ASSERTZH; + zh->errCode=0; if (!zh->res) { @@ -1329,6 +1441,8 @@ int zebra_init (ZebraHandle zh) { const char *rval; BFiles bfs = 0; + ASSERTZH; + zh->errCode=0; if (!zh->res) { @@ -1351,6 +1465,8 @@ int zebra_init (ZebraHandle zh) int zebra_compact (ZebraHandle zh) { BFiles bfs; + ASSERTZH; + zh->errCode=0; if (!zh->res) { zh->errCode = 109; @@ -1365,7 +1481,12 @@ int zebra_compact (ZebraHandle zh) int zebra_record_insert (ZebraHandle zh, const char *buf, int len) { int sysno = 0; + int olderr; + ASSERTZH; + zh->errCode=0; zebra_begin_trans (zh); + if (zh->errCode) + return 0; /* bad sysno */ extract_rec_in_mem (zh, "grs.sgml", buf, len, "Default", /* database */ @@ -1375,40 +1496,396 @@ int zebra_record_insert (ZebraHandle zh, const char *buf, int len) 1 /* store_keys */, 1 /* store_data */, 0 /* match criteria */); + olderr=zh->errCode; zebra_end_trans (zh); + if (olderr) + zh->errCode=olderr; return sysno; } void zebra_set_group (ZebraHandle zh, struct recordGroup *rg) { + ASSERTZH; + zh->errCode=0; memcpy (&zh->rGroup, rg, sizeof(*rg)); } void zebra_result (ZebraHandle zh, int *code, char **addinfo) { + ASSERTZH; *code = zh->errCode; *addinfo = zh->errString; } void zebra_shadow_enable (ZebraHandle zh, int value) { + ASSERTZH; + zh->errCode=0; zh->shadow_enable = value; } int zebra_record_encoding (ZebraHandle zh, const char *encoding) { + ASSERTZH; + zh->errCode=0; xfree (zh->record_encoding); + + /* + * Fixme! + */ + + if (zh->iconv_to_utf8 != 0) + yaz_iconv_close(zh->iconv_to_utf8); + if (zh->iconv_from_utf8 != 0) + yaz_iconv_close(zh->iconv_from_utf8); + zh->record_encoding = xstrdup (encoding); + + logf(LOG_DEBUG, "Reset record encoding: %s", encoding); + + zh->iconv_to_utf8 = + yaz_iconv_open ("UTF-8", encoding); + if (zh->iconv_to_utf8 == 0) + yaz_log (LOG_WARN, "iconv: %s to UTF-8 unsupported", encoding); + zh->iconv_from_utf8 = + yaz_iconv_open (encoding, "UTF-8"); + if (zh->iconv_to_utf8 == 0) + yaz_log (LOG_WARN, "iconv: UTF-8 to %s unsupported", encoding); + return 0; } void zebra_set_resource(ZebraHandle zh, const char *name, const char *value) { + ASSERTZH; + zh->errCode=0; res_put(zh->res, name, value); } const char *zebra_get_resource(ZebraHandle zh, const char *name, const char *defaultvalue) { + ASSERTZH; + zh->errCode=0; return res_get_def( zh->res, name, (char *)defaultvalue); } + +/* moved from zebra_api_ext.c by pop */ + +int zebra_trans_no (ZebraHandle zh) { + return (zh->trans_no); +} + + + +int zebra_get_shadow_enable (ZebraHandle zh) { + return (zh->shadow_enable); +} + +void zebra_set_shadow_enable (ZebraHandle zh, int value) { + zh->shadow_enable = value; +} + +void init_recordGroup (struct recordGroup *rg) { + rg->groupName = NULL; + rg->databaseName = NULL; + rg->path = NULL; + rg->recordId = NULL; + rg->recordType = NULL; + rg->flagStoreData = -1; + rg->flagStoreKeys = -1; + rg->flagRw = 1; + rg->databaseNamePath = 0; + rg->explainDatabase = 0; + rg->fileVerboseLimit = 100000; + rg->followLinks = -1; +} + + +/* This is from extract.c... it seems useful, when extract_rec_in mem is + called... and in general... Should be moved to somewhere else */ +void res_get_recordGroup (ZebraHandle zh, + struct recordGroup *rGroup, + const char *ext) { + char gprefix[128]; + char ext_res[128]; + + if (!rGroup->groupName || !*rGroup->groupName) + *gprefix = '\0'; + else + sprintf (gprefix, "%s.", rGroup->groupName); + + /* determine file type - depending on extension */ + if (!rGroup->recordType) { + sprintf (ext_res, "%srecordType.%s", gprefix, ext); + if (!(rGroup->recordType = res_get (zh->res, ext_res))) { + sprintf (ext_res, "%srecordType", gprefix); + rGroup->recordType = res_get (zh->res, ext_res); + } + } + /* determine match criteria */ + if (!rGroup->recordId) { + sprintf (ext_res, "%srecordId.%s", gprefix, ext); + if (!(rGroup->recordId = res_get (zh->res, ext_res))) { + sprintf (ext_res, "%srecordId", gprefix); + rGroup->recordId = res_get (zh->res, ext_res); + } + } + + /* determine database name */ + if (!rGroup->databaseName) { + sprintf (ext_res, "%sdatabase.%s", gprefix, ext); + if (!(rGroup->databaseName = res_get (zh->res, ext_res))) { + sprintf (ext_res, "%sdatabase", gprefix); + rGroup->databaseName = res_get (zh->res, ext_res); + } + } + if (!rGroup->databaseName) + rGroup->databaseName = "Default"; + + /* determine if explain database */ + sprintf (ext_res, "%sexplainDatabase", gprefix); + rGroup->explainDatabase = + atoi (res_get_def (zh->res, ext_res, "0")); + + /* storeData */ + if (rGroup->flagStoreData == -1) { + const char *sval; + sprintf (ext_res, "%sstoreData.%s", gprefix, ext); + if (!(sval = res_get (zh->res, ext_res))) { + sprintf (ext_res, "%sstoreData", gprefix); + sval = res_get (zh->res, ext_res); + } + if (sval) + rGroup->flagStoreData = atoi (sval); + } + if (rGroup->flagStoreData == -1) rGroup->flagStoreData = 0; + + /* storeKeys */ + if (rGroup->flagStoreKeys == -1) { + const char *sval; + + sprintf (ext_res, "%sstoreKeys.%s", gprefix, ext); + sval = res_get (zh->res, ext_res); + if (!sval) { + sprintf (ext_res, "%sstoreKeys", gprefix); + sval = res_get (zh->res, ext_res); + } + if (!sval) sval = res_get (zh->res, "storeKeys"); + if (sval) rGroup->flagStoreKeys = atoi (sval); + } + if (rGroup->flagStoreKeys == -1) rGroup->flagStoreKeys = 0; + +} + + +/* almost the same as zebra_records_retrieve ... but how did it work? + I mean for multiple records ??? CHECK ??? */ +void api_records_retrieve (ZebraHandle zh, ODR stream, + const char *setname, Z_RecordComposition *comp, + oid_value input_format, int num_recs, + ZebraRetrievalRecord *recs) +{ + ZebraPosSet poset; + int i, *pos_array; + + if (!zh->res) + { + zh->errCode = 30; + zh->errString = odr_strdup (stream, setname); + return; + } + + zh->errCode = 0; + + if (zebra_begin_read (zh)) + return; + + pos_array = (int *) xmalloc (num_recs * sizeof(*pos_array)); + for (i = 0; ierrCode = 30; + zh->errString = nmem_strdup (stream->mem, setname); + } + else + { + for (i = 0; ierrCode = 13; + zh->errString = odr_strdup (stream, num_str); + break; + } + + } + zebraPosSetDestroy (zh, poset, num_recs); + } + zebra_end_read (zh); + xfree (pos_array); +} + + +/* --------------------------------------------------------------------------- + Record insert(=update), delete + + If sysno is provided, then it's used to identify the reocord. + If not, and match_criteria is provided, then sysno is guessed + If not, and a record is provided, then sysno is got from there +*/ + +int zebra_update_record (ZebraHandle zh, + struct recordGroup *rGroup, + const char *recordType, + int sysno, const char *match, const char *fname, + const char *buf, int buf_size) + +{ + int res; + + if (buf_size < 1) buf_size = strlen(buf); + + zebra_begin_trans(zh); + res=bufferExtractRecord (zh, buf, buf_size, rGroup, + 0, // delete_flag + 0, // test_mode, + recordType, + &sysno, + match, fname); + zebra_end_trans(zh); + return sysno; +} + +int zebra_delete_record (ZebraHandle zh, + struct recordGroup *rGroup, + const char *recordType, + int sysno, const char *match, const char *fname, + const char *buf, int buf_size) +{ + int res; + + if (buf_size < 1) buf_size = strlen(buf); + + zebra_begin_trans(zh); + res=bufferExtractRecord (zh, buf, buf_size, rGroup, + 1, // delete_flag + 0, // test_mode, + recordType, + &sysno, + match,fname); + zebra_end_trans(zh); + return sysno; +} + +/* --------------------------------------------------------------------------- + Searching + + zebra_search_RPN is the same as zebra_search_rpn, except that read locking + is not mandatory. (it's repeatable now, also in zebraapi.c) +*/ + +void zebra_search_RPN (ZebraHandle zh, ODR decode, ODR stream, + Z_RPNQuery *query, const char *setname, int *hits) +{ + zh->hits = 0; + *hits = 0; + + if (zebra_begin_read (zh)) + return; + resultSetAddRPN (zh, decode, stream, query, + zh->num_basenames, zh->basenames, setname); + + zebra_end_read (zh); + + *hits = zh->hits; +} + +int zebra_search_PQF (ZebraHandle zh, + ODR odr_input, ODR odr_output, + const char *pqf_query, + const char *setname) + +{ + int hits; + Z_RPNQuery *query; + query = p_query_rpn (odr_input, PROTO_Z3950, pqf_query); + + if (!query) { + logf (LOG_WARN, "bad query %s\n", pqf_query); + odr_reset (odr_input); + return(0); + } + zebra_search_RPN (zh, odr_input, odr_output, query, setname, &hits); + + odr_reset (odr_input); + odr_reset (odr_output); + + return(hits); +} + +/* --------------------------------------------------------------------------- + Sort - a simplified interface, with optional read locks. +*/ +int sort (ZebraHandle zh, + ODR stream, + const char *sort_spec, + const char *output_setname, + const char **input_setnames + ) +{ + int num_input_setnames = 0; + int sort_status = 0; + Z_SortKeySpecList *sort_sequence = yaz_sort_spec (stream, sort_spec); + if (!sort_sequence) { + logf(LOG_WARN,"invalid sort specs '%s'", sort_spec); + zh->errCode = 207; + return (-1); + } + + /* we can do this, since the perl typemap code for char** will + put a NULL at the end of list */ + while (input_setnames[num_input_setnames]) num_input_setnames++; + + if (zebra_begin_read (zh)) + return; + + resultSetSort (zh, stream->mem, num_input_setnames, input_setnames, + output_setname, sort_sequence, &sort_status); + + zebra_end_read(zh); + return (sort_status); +}