-/* $Id: bfile.c,v 1.40 2005-03-30 09:25:23 adam Exp $
+/* $Id: bfile.c,v 1.41 2005-04-15 10:47:47 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <unistd.h>
#endif
+#include <yaz/xmalloc.h>
#include <idzebra/util.h>
#include <idzebra/bfile.h>
#include "mfile.h"
-/* $Id: cfile.c,v 1.34 2005-03-30 09:25:23 adam Exp $
+/* $Id: cfile.c,v 1.35 2005-04-15 10:47:47 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <string.h>
#include <idzebra/util.h>
+#include <yaz/yaz-util.h>
#include "mfile.h"
#include "cfile.h"
-/* $Id: commit.c,v 1.24 2005-03-30 09:25:23 adam Exp $
+/* $Id: commit.c,v 1.25 2005-04-15 10:47:47 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <stdlib.h>
#include <idzebra/util.h>
+#include <yaz/xmalloc.h>
#include "mfile.h"
#include "cfile.h"
-/* $Id: mfile.c,v 1.59 2005-03-30 09:25:23 adam Exp $
+/* $Id: mfile.c,v 1.60 2005-04-15 10:47:47 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <zebra-lock.h>
#include <idzebra/util.h>
+#include <yaz/yaz-util.h>
#include "mfile.h"
static int scan_areadef(MFile_area ma, const char *ad, const char *base)
-/* $Id: grepper.c,v 1.13 2005-03-30 09:25:23 adam Exp $
+/* $Id: grepper.c,v 1.14 2005-04-15 10:47:47 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <assert.h>
#include <idzebra/util.h>
+#include <yaz/yaz-util.h>
#include <dfa.h>
#include "imalloc.h"
-/* $Id: imalloc.c,v 1.12 2005-03-30 09:25:23 adam Exp $
+/* $Id: imalloc.c,v 1.13 2005-04-15 10:47:47 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <stdlib.h>
#include <idzebra/util.h>
+#include <yaz/xmalloc.h>
#include "imalloc.h"
#if MEMDEBUG
-/* $Id: dictext.c,v 1.12 2005-03-30 09:25:23 adam Exp $
+/* $Id: dictext.c,v 1.13 2005-04-15 10:47:48 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <ctype.h>
#include <idzebra/util.h>
+#include <yaz/yaz-util.h>
char *prog;
char ipf_buf[1024];
prog = *argv;
- while ((ret = options ("8vh", argv, argc, &arg)) != -2)
+ while ((ret = options("8vh", argv, argc, &arg)) != -2)
{
if (ret == 0)
{
-/* $Id: dicttest.c,v 1.33 2005-03-30 09:25:23 adam Exp $
+/* $Id: dicttest.c,v 1.34 2005-04-15 10:47:48 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <idzebra/dict.h>
#include <idzebra/util.h>
#include <idzebra/res.h>
+#include <yaz/yaz-util.h>
char *prog;
static Dict dict;
-/* $Id: api.h,v 1.17 2005-04-13 08:52:26 adam Exp $
+/* $Id: api.h,v 1.18 2005-04-15 10:47:48 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
ZebraService zebra_start_res(const char *configName,
Res def_res, Res over_res);
-/** \fn int zebra_stop(ZebraService zs)
+/** \fn ZEBRA_RES zebra_stop(ZebraService zs)
\brief stops a Zebra service.
\param zs service handle
Frees resources used by the service.
*/
YAZ_EXPORT
-int zebra_stop(ZebraService zs);
+ZEBRA_RES zebra_stop(ZebraService zs);
/** \fn void zebra_filter_info(ZebraService zs, void *cd,
void(*cb)(void *cd, const char *name))
\brief destroys Zebra session handle.
\param zh zebra session handle.
*/
-YAZ_EXPORT int zebra_close(ZebraHandle zh);
+YAZ_EXPORT ZEBRA_RES zebra_close(ZebraHandle zh);
/** \fn int zebra_errCode(ZebraHandle zh)
\brief returns error code for last error
*/
YAZ_EXPORT void zebra_clearError(ZebraHandle zh);
-/** \fn int zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
+/** \fn ZEBRA_RES zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
const char *setname, int *hits)
\brief Search using PQF Query
\param zh session handle
\param setname name of resultset
\param hits of hits is returned
*/
-YAZ_EXPORT int zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
- const char *setname, zint *hits);
+YAZ_EXPORT ZEBRA_RES zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
+ const char *setname, zint *hits);
-/** \fn int zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
+/** \fn ZEBRA_RES zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
const char *setname, zint *hits)
\brief Search using RPN Query
\param zh session handle
\param setname name of resultset
\param hits number of hits is returned
*/
-YAZ_EXPORT int zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
- const char *setname, zint *hits);
+YAZ_EXPORT ZEBRA_RES zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
+ const char *setname, zint *hits);
/**
- \fn int zebra_records_retrieve(ZebraHandle zh, ODR stream,
+ \fn ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream,
const char *setname, Z_RecordComposition *comp, oid_value input_format,
int num_recs, ZebraRetrievalRecord *recs)
\brief retrieve records from result set (after search)
\param num_recs number of records to retrieve
\param recs store records in this structure (size is num_recs)
*/
-YAZ_EXPORT int zebra_records_retrieve(ZebraHandle zh, ODR stream,
- const char *setname, Z_RecordComposition *comp,
- oid_value input_format,
- int num_recs, ZebraRetrievalRecord *recs);
-
+YAZ_EXPORT
+ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream,
+ const char *setname,
+ Z_RecordComposition *comp,
+ oid_value input_format,
+ int num_recs,
+ ZebraRetrievalRecord *recs);
/**
\fn int zebra_deleteResultSet(ZebraHandle zh, int function,
int num_setnames, char **setnames, int *statuses)
\param setnames result set names
\param statuses status result
*/
-YAZ_EXPORT int zebra_deleteResultSet(ZebraHandle zh, int function,
- int num_setnames, char **setnames,
- int *statuses);
+YAZ_EXPORT
+int zebra_deleteResultSet(ZebraHandle zh, int function,
+ int num_setnames, char **setnames,
+ int *statuses);
/**
- \fn int zebra_scan(ZebraHandle zh, ODR stream,
+ \fn ZEBRA_RES zebra_scan(ZebraHandle zh, ODR stream,
Z_AttributesPlusTerm *zapt, oid_value attributeset,
int *position, int *num_entries, ZebraScanEntry **list, int *is_partial)
\brief performs Scan (Z39.50 style)
\param list list of resulting terms (ODR allocated)
\param is_partial upon return 1=partial, 0=complete
*/
-YAZ_EXPORT int zebra_scan(ZebraHandle zh, ODR stream,
- Z_AttributesPlusTerm *zapt,
- oid_value attributeset,
- int *position, int *num_entries,
- ZebraScanEntry **list,
- int *is_partial);
+YAZ_EXPORT ZEBRA_RES zebra_scan(ZebraHandle zh, ODR stream,
+ Z_AttributesPlusTerm *zapt,
+ oid_value attributeset,
+ int *position, int *num_entries,
+ ZebraScanEntry **list,
+ int *is_partial);
/**
- \fn int zebra_scan_PQF(ZebraHandle zh, ODR stream,
+ \fn ZEBRA_RES zebra_scan_PQF(ZebraHandle zh, ODR stream,
const char *query, int *position, int *num_entries, ZebraScanEntry **list, int *is_partial)
\brief performs Scan (taking PQF string)
\param zh session handle
\param list list of resulting terms (ODR allocated)
\param is_partial upon return 1=partial, 0=complete
*/
-YAZ_EXPORT int zebra_scan_PQF(ZebraHandle zh, ODR stream,
- const char *query,
- int *position, int *num_entries,
- ZebraScanEntry **entries,
- int *is_partial);
+YAZ_EXPORT ZEBRA_RES zebra_scan_PQF(ZebraHandle zh, ODR stream,
+ const char *query,
+ int *position, int *num_entries,
+ ZebraScanEntry **entries,
+ int *is_partial);
/**
- \fn int zebra_auth(ZebraHandle zh, const char *user, const char *pass)
+ \fn ZEBRA_RES zebra_auth(ZebraHandle zh, const char *user, const char *pass)
\brief authenticate user. Returns 0 if OK, != 0 on failure
\param zh session handle
\param user user name
\param pass password
*/
-YAZ_EXPORT int zebra_auth(ZebraHandle zh, const char *user, const char *pass);
-
+YAZ_EXPORT ZEBRA_RES zebra_auth(ZebraHandle zh,
+ const char *user, const char *pass);
/**
\fn int zebra_string_norm(ZebraHandle zh, unsigned reg_id,
char *output_str, int output_len);
/**
- \fn int zebra_create_database(ZebraHandle zh, const char *db)
+ \fn ZEBRA_RES zebra_create_database(ZebraHandle zh, const char *db)
\brief creates a database
\param zh session handle
\param db database to be created
*/
-YAZ_EXPORT int zebra_create_database(ZebraHandle zh, const char *db);
+YAZ_EXPORT ZEBRA_RES zebra_create_database(ZebraHandle zh, const char *db);
/**
\fn int zebra_drop_database(ZebraHandle zh, const char *db)
\param zh session handle
\param db database to be deleted
*/
-YAZ_EXPORT int zebra_drop_database(ZebraHandle zh, const char *db);
+YAZ_EXPORT
+ZEBRA_RES zebra_drop_database(ZebraHandle zh, const char *db);
-YAZ_EXPORT int zebra_admin_shutdown(ZebraHandle zh);
-YAZ_EXPORT int zebra_admin_start(ZebraHandle zh);
+YAZ_EXPORT
+ZEBRA_RES zebra_admin_shutdown(ZebraHandle zh);
-YAZ_EXPORT int zebra_shutdown(ZebraService zs);
+YAZ_EXPORT
+ZEBRA_RES zebra_admin_start(ZebraHandle zh);
-YAZ_EXPORT int zebra_admin_import_begin(ZebraHandle zh, const char *database,
- const char *record_type);
+YAZ_EXPORT
+ZEBRA_RES zebra_shutdown(ZebraService zs);
-YAZ_EXPORT int zebra_admin_import_segment(ZebraHandle zh,
- Z_Segment *segment);
+YAZ_EXPORT
+ZEBRA_RES zebra_admin_import_begin(ZebraHandle zh, const char *database,
+ const char *record_type);
-YAZ_EXPORT int zebra_admin_import_end(ZebraHandle zh);
+YAZ_EXPORT
+ZEBRA_RES zebra_admin_import_segment(ZebraHandle zh,
+ Z_Segment *segment);
+
+YAZ_EXPORT
+ZEBRA_RES zebra_admin_import_end(ZebraHandle zh);
+
+YAZ_EXPORT
+ZEBRA_RES zebra_admin_exchange_record(ZebraHandle zh,
+ const char *rec_buf,
+ size_t rec_len,
+ const char *recid_buf, size_t recid_len,
+ int action);
-YAZ_EXPORT int zebra_admin_exchange_record(ZebraHandle zh,
- const char *rec_buf,
- size_t rec_len,
- const char *recid_buf, size_t recid_len,
- int action);
+YAZ_EXPORT
+ZEBRA_RES zebra_begin_trans(ZebraHandle zh, int rw);
-YAZ_EXPORT int zebra_begin_trans(ZebraHandle zh, int rw);
-YAZ_EXPORT int zebra_end_trans(ZebraHandle zh);
-YAZ_EXPORT int zebra_end_transaction(ZebraHandle zh, ZebraTransactionStatus *stat);
+YAZ_EXPORT
+ZEBRA_RES zebra_end_trans(ZebraHandle zh);
-YAZ_EXPORT int zebra_commit(ZebraHandle zh);
-YAZ_EXPORT int zebra_clean(ZebraHandle zh);
+YAZ_EXPORT
+ZEBRA_RES zebra_end_transaction(ZebraHandle zh,
+ ZebraTransactionStatus *stat);
+
+YAZ_EXPORT
+ZEBRA_RES zebra_commit(ZebraHandle zh);
+
+YAZ_EXPORT
+ZEBRA_RES zebra_clean(ZebraHandle zh);
+
+YAZ_EXPORT
+ZEBRA_RES zebra_init(ZebraHandle zh);
-YAZ_EXPORT int zebra_init(ZebraHandle zh);
YAZ_EXPORT int zebra_compact(ZebraHandle zh);
YAZ_EXPORT int zebra_repository_update(ZebraHandle zh, const char *path);
YAZ_EXPORT int zebra_repository_delete(ZebraHandle zh, const char *path);
YAZ_EXPORT int zebra_add_record(ZebraHandle zh, const char *buf, int buf_size);
-YAZ_EXPORT int zebra_insert_record(ZebraHandle zh,
- const char *recordType,
- SYSNO *sysno, const char *match, const char *fname,
- const char *buf, int buf_size,
- int force_update);
-YAZ_EXPORT int zebra_update_record(ZebraHandle zh,
- const char *recordType,
- SYSNO *sysno, const char *match, const char *fname,
- const char *buf, int buf_size,
- int force_update);
-YAZ_EXPORT int zebra_delete_record(ZebraHandle zh,
- const char *recordType,
- SYSNO *sysno, const char *match, const char *fname,
- const char *buf, int buf_size,
- int force_update);
-
-YAZ_EXPORT int zebra_resultSetTerms(ZebraHandle zh, const char *setname,
- int no, zint *count,
- int *type, char *out, size_t *len);
-
-YAZ_EXPORT int zebra_sort(ZebraHandle zh, ODR stream,
- int num_input_setnames,
- const char **input_setnames,
- const char *output_setname,
- Z_SortKeySpecList *sort_sequence,
- int *sort_status);
-
+YAZ_EXPORT
+ZEBRA_RES zebra_insert_record(ZebraHandle zh,
+ const char *recordType,
+ SYSNO *sysno, const char *match,
+ const char *fname,
+ const char *buf, int buf_size,
+ int force_update);
YAZ_EXPORT
-int zebra_select_databases(ZebraHandle zh, int num_bases,
- const char **basenames);
+ZEBRA_RES zebra_update_record(ZebraHandle zh,
+ const char *recordType,
+ SYSNO *sysno, const char *match,
+ const char *fname,
+ const char *buf, int buf_size,
+ int force_update);
+YAZ_EXPORT
+ZEBRA_RES zebra_delete_record(ZebraHandle zh,
+ const char *recordType,
+ SYSNO *sysno, const char *match, const char *fname,
+ const char *buf, int buf_size,
+ int force_update);
+
+YAZ_EXPORT
+int zebra_resultSetTerms(ZebraHandle zh, const char *setname,
+ int no, zint *count,
+ int *type, char *out, size_t *len);
+
+YAZ_EXPORT
+ZEBRA_RES zebra_sort(ZebraHandle zh, ODR stream,
+ int num_input_setnames,
+ const char **input_setnames,
+ const char *output_setname,
+ Z_SortKeySpecList *sort_sequence,
+ int *sort_status);
YAZ_EXPORT
-int zebra_select_database(ZebraHandle zh, const char *basename);
+ZEBRA_RES zebra_select_databases(ZebraHandle zh, int num_bases,
+ const char **basenames);
YAZ_EXPORT
-int zebra_shadow_enable(ZebraHandle zh, int value);
+ZEBRA_RES zebra_select_database(ZebraHandle zh, const char *basename);
YAZ_EXPORT
-int zebra_register_statistics(ZebraHandle zh, int dumpdict);
+void zebra_shadow_enable(ZebraHandle zh, int value);
YAZ_EXPORT
-int zebra_record_encoding(ZebraHandle zh, const char *encoding);
+int zebra_register_statistics(ZebraHandle zh, int dumpdict);
YAZ_EXPORT
-int zebra_record_encoding(ZebraHandle zh, const char *encoding);
+ZEBRA_RES zebra_record_encoding(ZebraHandle zh, const char *encoding);
YAZ_EXPORT
-int zebra_octet_term_encoding(ZebraHandle zh, const char *encoding);
+ZEBRA_RES zebra_octet_term_encoding(ZebraHandle zh, const char *encoding);
/* Resources */
YAZ_EXPORT
-int zebra_set_resource(ZebraHandle zh, const char *name, const char *value);
+void zebra_set_resource(ZebraHandle zh, const char *name, const char *value);
YAZ_EXPORT
const char *zebra_get_resource(ZebraHandle zh,
- const char *name, const char *defaultvalue);
+ const char *name, const char *defaultvalue);
-YAZ_EXPORT void zebra_pidfname(ZebraService zs, char *path);
+YAZ_EXPORT
+void zebra_pidfname(ZebraService zs, char *path);
typedef struct {
char *term;
-/* $Id: isamc.h,v 1.3 2005-04-13 13:03:47 adam Exp $
+/* $Id: isamc.h,v 1.4 2005-04-15 10:47:48 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
void *clientData;
} ISAMC_I;
+YAZ_EXPORT
void isamc_getmethod (ISAMC_M *m);
+YAZ_EXPORT
ISAMC isamc_open (BFiles bfs, const char *name, int writeflag,
ISAMC_M *method);
+YAZ_EXPORT
int isamc_close (ISAMC is);
+
+YAZ_EXPORT
void isamc_merge (ISAMC is, ISAM_P *pos, ISAMC_I *data);
+YAZ_EXPORT
ISAMC_PP isamc_pp_open (ISAMC is, ISAM_P pos);
+
+YAZ_EXPORT
void isamc_pp_close (ISAMC_PP pp);
+
+YAZ_EXPORT
int isamc_read_item (ISAMC_PP pp, char **dst);
+
+YAZ_EXPORT
int isamc_pp_read (ISAMC_PP pp, void *buf);
+
+YAZ_EXPORT
zint isamc_pp_num (ISAMC_PP pp);
+YAZ_EXPORT
zint isamc_block_used (ISAMC is, int type);
+
+YAZ_EXPORT
int isamc_block_size (ISAMC is, int type);
#define isamc_type(x) ((x) & 7)
-/* $Id: util.h,v 1.1 2005-03-30 09:25:23 adam Exp $
+/* $Id: util.h,v 1.2 2005-04-15 10:47:48 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#ifndef ZEBRA_UTIL_H
#define ZEBRA_UTIL_H
-#include <yaz/yaz-util.h>
+#include <yaz/yconfig.h>
+#include <yaz/log.h>
#include <idzebra/version.h>
#endif
#endif
+typedef short ZEBRA_RES;
+#define ZEBRA_FAIL -1
+#define ZEBRA_OK 0
+
typedef zint SYSNO;
YAZ_EXPORT
-/* $Id: rset.h,v 1.48 2005-04-13 13:03:47 adam Exp $
+/* $Id: rset.h,v 1.49 2005-04-15 10:47:48 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#ifndef RSET_H
#define RSET_H
+#include <yaz/yaz-util.h>
/* unfortunately we need the isam includes here, for the arguments for */
/* rsisamX_create */
#include <idzebra/isamb.h>
-/* $Id: extract.c,v 1.177 2005-03-17 09:48:46 adam Exp $
+/* $Id: extract.c,v 1.178 2005-04-15 10:47:48 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
If not, and a record is provided, then sysno is got from there
*/
-int buffer_extract_record (ZebraHandle zh,
- const char *buf, size_t buf_size,
- int delete_flag,
- int test_mode,
- const char *recordType,
- SYSNO *sysno,
- const char *match_criteria,
- const char *fname,
- int force_update,
- int allow_update)
+ZEBRA_RES buffer_extract_record (ZebraHandle zh,
+ const char *buf, size_t buf_size,
+ int delete_flag,
+ int test_mode,
+ const char *recordType,
+ SYSNO *sysno,
+ const char *match_criteria,
+ const char *fname,
+ int force_update,
+ int allow_update)
{
RecordAttr *recordAttr;
struct recExtractCtrl extractCtrl;
{
if (zebraExplain_newDatabase (zh->reg->zei, zh->basenames[0],
zh->m_explain_database))
- return 0;
+ return ZEBRA_FAIL;
}
- if (recordType && *recordType) {
+ if (recordType && *recordType)
+ {
yaz_log (YLOG_DEBUG, "Record type explicitly specified: %s", recordType);
recType = recType_byName (zh->reg->recTypes, zh->res, recordType,
&clientData);
- } else {
- if (!(zh->m_record_type)) {
+ }
+ else
+ {
+ if (!(zh->m_record_type))
+ {
yaz_log (YLOG_WARN, "No such record type defined");
- return 0;
+ return ZEBRA_FAIL;
}
yaz_log (YLOG_DEBUG, "Get record type from rgroup: %s",zh->m_record_type);
recType = recType_byName (zh->reg->recTypes, zh->res,
recordType = zh->m_record_type;
}
- if (!recType) {
+ if (!recType)
+ {
yaz_log (YLOG_WARN, "No such record type: %s", zh->m_record_type);
- return 0;
+ return ZEBRA_FAIL;
}
extractCtrl.init = extract_init;
r = (*recType->extract)(clientData, &extractCtrl);
if (r == RECCTRL_EXTRACT_EOF)
- return 0;
+ return ZEBRA_FAIL;
else if (r == RECCTRL_EXTRACT_ERROR_GENERIC)
{
/* error occured during extraction ... */
yaz_log (YLOG_WARN, "extract error: generic");
- return 0;
+ return ZEBRA_FAIL;
}
else if (r == RECCTRL_EXTRACT_ERROR_NO_SUCH_FILTER)
{
/* error occured during extraction ... */
yaz_log (YLOG_WARN, "extract error: no such filter");
- return 0;
+ return ZEBRA_FAIL;
}
/* match criteria */
matchStr = NULL;
if (!matchStr)
{
yaz_log (YLOG_WARN, "Bad match criteria (recordID)");
- return 1;
+ return ZEBRA_FAIL;
}
}
}
/* the extraction process returned no information - the record
is probably empty - unless flagShowRecords is in use */
if (test_mode)
- return 1;
+ return ZEBRA_OK;
}
if (! *sysno)
yaz_log (YLOG_LOG, "delete %s %s %ld", recordType,
pr_fname, (long) recordOffset);
yaz_log (YLOG_WARN, "cannot delete record above (seems new)");
- return 1;
+ return ZEBRA_FAIL;
}
if (show_progress)
yaz_log (YLOG_LOG, "add %s %s %ld", recordType, pr_fname,
yaz_log (YLOG_LOG, "skipped %s %s %ld",
recordType, pr_fname, (long) recordOffset);
logRecord(zh);
- return -1;
+ return ZEBRA_FAIL;
}
rec = rec_get (zh->reg->records, *sysno);
extract_flushSortKeys (zh, *sysno, -1, &zh->reg->sortKeys);
rec_rm (&rec);
logRecord(zh);
- return -1;
+ return ZEBRA_FAIL;
}
}
}
rec_rm (&rec);
logRecord(zh);
- return 0;
+ return ZEBRA_OK;
}
else
{
/* commit this record */
rec_put (zh->reg->records, &rec);
logRecord(zh);
- return 0;
+ return ZEBRA_OK;
}
int explain_extract (void *handle, Record rec, data1_node *n)
-/* $Id: index.h,v 1.132 2005-04-13 13:03:47 adam Exp $
+/* $Id: index.h,v 1.133 2005-04-15 10:47:48 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
struct term_set_entry *last;
};
-RSET rpn_search (ZebraHandle zh, NMEM mem, NMEM rset_nmem,
- Z_RPNQuery *rpn, int num_bases, char **basenames,
- const char *setname, ZebraSet sset);
+RSET rpn_search_structure (ZebraHandle zh, Z_RPNStructure *zs,
+ oid_value attributeSet,
+ NMEM stream, NMEM rset_nmem,
+ Z_SortKeySpecList *sort_sequence,
+ int num_bases, char **basenames);
-
-void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
- oid_value attributeset,
- int num_bases, char **basenames,
- int *position, int *num_entries, ZebraScanEntry **list,
- int *is_partial, RSET limit_set, int return_zero);
+ZEBRA_RES rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
+ oid_value attributeset,
+ int num_bases, char **basenames,
+ int *position, int *num_entries, ZebraScanEntry **list,
+ int *is_partial, RSET limit_set, int return_zero);
RSET rset_trunc (ZebraHandle zh, ISAM_P *isam_p, int no,
const char *term, int length_term, const char *flags,
int use, const char *term);
ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov);
ZebraSet resultSetGet (ZebraHandle zh, const char *name);
-ZebraSet resultSetAddRPN (ZebraHandle zh, NMEM m, Z_RPNQuery *rpn,
- int num_bases, char **basenames,
- const char *setname);
+ZEBRA_RES resultSetAddRPN (ZebraHandle zh, NMEM m, Z_RPNQuery *rpn,
+ int num_bases, char **basenames,
+ const char *setname);
RSET resultSetRef (ZebraHandle zh, const char *resultSetId);
void resultSetDestroy (ZebraHandle zh, int num_names, char **names,
int *statuses);
void zebra_index_merge (ZebraHandle zh);
-int buffer_extract_record (ZebraHandle zh,
- const char *buf, size_t buf_size,
- int delete_flag,
- int test_mode,
- const char *recordType,
- SYSNO *sysno,
- const char *match_criteria,
- const char *fname,
- int force_update,
- int allow_update);
+ZEBRA_RES buffer_extract_record (ZebraHandle zh,
+ const char *buf, size_t buf_size,
+ int delete_flag,
+ int test_mode,
+ const char *recordType,
+ SYSNO *sysno,
+ const char *match_criteria,
+ const char *fname,
+ int force_update,
+ int allow_update);
#if 0
int extract_rec_in_mem (ZebraHandle zh, const char *recordType,
int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname,
int deleteFlag);
-int zebra_begin_read (ZebraHandle zh);
-int zebra_end_read (ZebraHandle zh);
+ZEBRA_RES zebra_begin_read (ZebraHandle zh);
+ZEBRA_RES zebra_end_read (ZebraHandle zh);
int zebra_file_stat (const char *file_name, struct stat *buf,
int follow_links);
-/* $Id: recindex.c,v 1.42 2005-01-16 23:14:57 adam Exp $
+/* $Id: recindex.c,v 1.43 2005-04-15 10:47:48 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <assert.h>
#include <string.h>
+#include <yaz/yaz-util.h>
#include "recindxp.h"
#if HAVE_BZLIB_H
-/* $Id: zebraapi.c,v 1.160 2005-04-14 12:02:08 adam Exp $
+/* $Id: zebraapi.c,v 1.161 2005-04-15 10:47:48 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
return reg;
}
-int zebra_admin_shutdown (ZebraHandle zh)
+ZEBRA_RES zebra_admin_shutdown (ZebraHandle zh)
{
ASSERTZH;
yaz_log(log_level, "zebra_admin_shutdown");
zebra_mutex_cond_lock (&zh->service->session_lock);
zh->service->stop_flag = 1;
zebra_mutex_cond_unlock (&zh->service->session_lock);
- return 0;
+ return ZEBRA_OK;
}
-int zebra_admin_start (ZebraHandle zh)
+ZEBRA_RES zebra_admin_start (ZebraHandle zh)
{
ZebraService zs;
ASSERTZH;
zs = zh->service;
zebra_mutex_cond_lock (&zs->session_lock);
zebra_mutex_cond_unlock (&zs->session_lock);
- return 0;
+ return ZEBRA_OK;
}
static void zebra_register_close (ZebraService zs, struct zebra_register *reg)
xfree(reg);
}
-int zebra_stop(ZebraService zs)
+ZEBRA_RES zebra_stop(ZebraService zs)
{
if (!zs)
- return 0;
+ return ZEBRA_OK;
yaz_log (log_level, "zebra_stop");
while (zs->sessions)
res_close (zs->global_res);
xfree(zs->configName);
xfree(zs);
- return 0;
+ return ZEBRA_OK;
}
-int zebra_close (ZebraHandle zh)
+ZEBRA_RES zebra_close (ZebraHandle zh)
{
ZebraService zs;
struct zebra_session **sp;
yaz_log(log_level, "zebra_close");
if (!zh)
- return 0;
+ return ZEBRA_OK;
ASSERTZH;
zh->errCode = 0;
zh->service = 0; /* more likely to trigger an assert */
xfree(zh->path_reg);
xfree(zh);
- return 0;
+ return ZEBRA_OK;
}
struct map_baseinfo {
zh->res = 0;
}
-static int zebra_select_register (ZebraHandle zh, const char *new_reg)
+static void 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;
+ return;
if (!zh->res)
{
assert (zh->reg == 0);
zebra_lock_create (res_get(zh->res, "lockDir"), fname, 0);
}
- return 1;
}
void map_basenames_func (void *vp, const char *name, const char *value)
yaz_log (YLOG_DEBUG, "base %s", (*basenames)[i]);
}
-int zebra_select_database (ZebraHandle zh, const char *basename)
+ZEBRA_RES zebra_select_database (ZebraHandle zh, const char *basename)
{
ASSERTZH;
yaz_log(log_level, "zebra_select_database %s",basename);
return zebra_select_databases (zh, 1, &basename);
}
-int zebra_select_databases (ZebraHandle zh, int num_bases,
- const char **basenames)
+ZEBRA_RES zebra_select_databases (ZebraHandle zh, int num_bases,
+ const char **basenames)
{
int i;
const char *cp;
if (num_bases < 1)
{
zh->errCode = 23;
- return -1;
+ return ZEBRA_FAIL;
}
for (i = 0; i < zh->num_basenames; i++)
xfree(zh->basenames[i]);
if (cp1)
{
zh->errCode = 23;
- return -1;
+ return ZEBRA_FAIL;
}
}
}
if (!zh->res)
{
zh->errCode = 109;
- return -1;
+ return ZEBRA_FAIL;
}
if (!zh->lock_normal || !zh->lock_shadow)
{
zh->errCode = 2;
- return -1;
+ return ZEBRA_FAIL;
}
- return 0;
+ return ZEBRA_OK;
}
-int zebra_search_RPN (ZebraHandle zh, ODR o,
- Z_RPNQuery *query, const char *setname, zint *hits)
+ZEBRA_RES zebra_search_RPN (ZebraHandle zh, ODR o, Z_RPNQuery *query,
+ const char *setname, zint *hits)
{
- const char *max;
- zint maxhits;
+ ZEBRA_RES r;
ASSERTZH;
assert(o);
assert(query);
zh->hits = 0;
*hits = 0;
- if (zebra_begin_read (zh))
- return 1;
+ if (zebra_begin_read(zh) == ZEBRA_FAIL)
+ return ZEBRA_FAIL;
- resultSetAddRPN (zh, odr_extract_mem(o), query,
- zh->num_basenames, zh->basenames, setname);
-
- zebra_end_read (zh);
- max = res_get (zh->res, "maxhits");
- if (max)
- maxhits = atoi(max);
- else {
- int i = 0;
- maxhits = INT_MAX; /* properly rounded, to make it look like a limit*/
- while (maxhits>100) { maxhits/=10; i++;}
- while (i--) maxhits *= 10;
- }
- if (zh->hits > maxhits) { /* too large for yaz to handle */
- yaz_log(YLOG_DEBUG, "limiting hits to "ZINT_FORMAT, maxhits);
- *hits = maxhits;
- }
- else
- *hits = zh->hits;
- return 0;
+ r = resultSetAddRPN(zh, odr_extract_mem(o), query,
+ zh->num_basenames, zh->basenames, setname);
+ zebra_end_read(zh);
+ *hits = zh->hits;
+ return r;
}
-int zebra_records_retrieve (ZebraHandle zh, ODR stream,
- const char *setname, Z_RecordComposition *comp,
- oid_value input_format, int num_recs,
- ZebraRetrievalRecord *recs)
+ZEBRA_RES zebra_records_retrieve (ZebraHandle zh, ODR stream,
+ const char *setname,
+ Z_RecordComposition *comp,
+ oid_value input_format, int num_recs,
+ ZebraRetrievalRecord *recs)
{
ZebraMetaRecord *poset;
- int i, ret = 0;
+ int i;
+ ZEBRA_RES ret = ZEBRA_OK;
zint *pos_array;
ASSERTZH;
assert(stream);
{
zh->errCode = 30;
zh->errString = odr_strdup(stream, setname);
- return -1;
+ return ZEBRA_FAIL;
}
zh->errCode = 0;
- if (zebra_begin_read (zh))
- return -1;
+ if (zebra_begin_read (zh) == ZEBRA_FAIL)
+ return ZEBRA_FAIL;
pos_array = (zint *) xmalloc(num_recs * sizeof(*pos_array));
for (i = 0; i<num_recs; i++)
yaz_log (YLOG_DEBUG, "zebraPosSetCreate error");
zh->errCode = 30;
zh->errString = nmem_strdup (stream->mem, setname);
- ret = -1;
+ ret = ZEBRA_FAIL;
}
else
{
sprintf (num_str, ZINT_FORMAT, pos_array[i]);
zh->errCode = 13;
zh->errString = odr_strdup (stream, num_str);
- ret = -1;
+ ret = ZEBRA_FAIL;
break;
}
}
return ret;
}
-int zebra_scan_PQF(ZebraHandle zh, ODR stream, const char *query,
- int *position, int *num_entries, ZebraScanEntry **entries,
- int *is_partial)
+ZEBRA_RES zebra_scan_PQF(ZebraHandle zh, ODR stream, const char *query,
+ int *position,
+ int *num_entries, ZebraScanEntry **entries,
+ int *is_partial)
{
YAZ_PQF_Parser pqf_parser = yaz_pqf_create ();
Z_AttributesPlusTerm *zapt;
if (!(zapt = yaz_pqf_scan(pqf_parser, stream, &attributeSet, query)))
{
yaz_pqf_destroy (pqf_parser);
- return -1;
+ return ZEBRA_FAIL;
}
yaz_pqf_destroy (pqf_parser);
return zebra_scan(zh, stream, zapt, VAL_BIB1,
position, num_entries, entries, is_partial);
}
-int zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
- oid_value attributeset,
- int *position, int *num_entries, ZebraScanEntry **entries,
- int *is_partial)
+ZEBRA_RES zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
+ oid_value attributeset,
+ int *position,
+ int *num_entries, ZebraScanEntry **entries,
+ int *is_partial)
{
+ ZEBRA_RES res;
ASSERTZH;
assert(stream);
assert(zapt);
assert(entries);
yaz_log(log_level, "zebra_scan");
zh->errCode = 0;
- if (zebra_begin_read (zh))
+ if (zebra_begin_read (zh) == ZEBRA_FAIL)
{
*entries = 0;
*num_entries = 0;
- return 1;
+ return ZEBRA_FAIL;
}
- rpn_scan (zh, stream, zapt, attributeset,
- zh->num_basenames, zh->basenames, position,
- num_entries, entries, is_partial, 0, 0);
+ res = rpn_scan (zh, stream, zapt, attributeset,
+ zh->num_basenames, zh->basenames, position,
+ num_entries, entries, is_partial, 0, 0);
zebra_end_read (zh);
- return 0;
+ return res;
}
-int zebra_sort (ZebraHandle zh, ODR stream,
- int num_input_setnames, const char **input_setnames,
- const char *output_setname, Z_SortKeySpecList *sort_sequence,
- int *sort_status)
+ZEBRA_RES zebra_sort (ZebraHandle zh, ODR stream,
+ int num_input_setnames, const char **input_setnames,
+ const char *output_setname,
+ Z_SortKeySpecList *sort_sequence,
+ int *sort_status)
{
ASSERTZH;
assert(stream);
assert(sort_status);
yaz_log(log_level, "zebra_sort");
zh->errCode = 0;
- if (zebra_begin_read (zh))
- return 1;
+ if (zebra_begin_read (zh) == ZEBRA_FAIL)
+ return ZEBRA_FAIL;
resultSetSort (zh, stream->mem, num_input_setnames, input_setnames,
output_setname, sort_sequence, sort_status);
- zebra_end_read(zh);
- return 0;
+ return zebra_end_read(zh);
}
int zebra_deleteResultSet(ZebraHandle zh, int function,
if (zh)
{
zh->errCode = 0;
- zh->errString="";
+ zh->errString = 0;
}
}
-int zebra_auth (ZebraHandle zh, const char *user, const char *pass)
+ZEBRA_RES zebra_auth (ZebraHandle zh, const char *user, const char *pass)
{
const char *p;
char u[40];
/* users that don't require a password .. */
if (zh->user_perm && strchr(zh->user_perm, 'a'))
- return 0;
+ return ZEBRA_OK;
if (!zs->passwd_db || !passwd_db_auth (zs->passwd_db, user, pass))
- return 0;
- return 1;
+ return ZEBRA_OK;
+ return ZEBRA_FAIL;
}
-int zebra_admin_import_begin (ZebraHandle zh, const char *database,
+ZEBRA_RES zebra_admin_import_begin (ZebraHandle zh, const char *database,
const char *record_type)
{
ASSERTZH;
yaz_log(log_level, "zebra_admin_import_begin db=%s rt=%s",
database, record_type);
zh->errCode = 0;
- if (zebra_select_database(zh, database))
- return 1;
- if (zebra_begin_trans (zh, 1))
- return 1;
- return 0;
+ if (zebra_select_database(zh, database) == ZEBRA_FAIL)
+ return ZEBRA_FAIL;
+ return zebra_begin_trans(zh, 1);
}
-int zebra_admin_import_end (ZebraHandle zh)
+ZEBRA_RES zebra_admin_import_end (ZebraHandle zh)
{
ASSERTZH;
yaz_log(log_level, "zebra_admin_import_end");
zh->errCode = 0;
- zebra_end_trans (zh);
- return 0;
+ return zebra_end_trans(zh);
}
-int zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment)
+ZEBRA_RES zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment)
{
+ ZEBRA_RES res = ZEBRA_OK;
SYSNO sysno;
int i;
ASSERTZH;
{
Z_NamePlusRecord *npr = segment->segmentRecords[i];
- printf ("--------------%d--------------------\n", i);
- /* FIXME - What! printing on stdout ??? */
if (npr->which == Z_NamePlusRecord_intermediateFragment)
{
Z_FragmentSyntax *fragment = npr->u.intermediateFragment;
if (fragment->which == Z_FragmentSyntax_notExternallyTagged)
{
Odr_oct *oct = fragment->u.notExternallyTagged;
- printf ("%.*s", (oct->len > 100 ? 100 : oct->len) ,
- oct->buf);
-
sysno = 0;
- zebra_update_record(zh,
- 0, /* record Type */
- &sysno,
- 0, /* match */
- 0, /* fname */
- oct->buf, oct->len,
- 0);
+ if ( zebra_update_record(zh,
+ 0, /* record Type */
+ &sysno,
+ 0, /* match */
+ 0, /* fname */
+ oct->buf, oct->len,
+ 0) == ZEBRA_FAIL)
+ res = ZEBRA_FAIL;
}
}
}
- return 0;
+ return res;
}
-int zebra_admin_exchange_record (ZebraHandle zh,
- const char *rec_buf,
- size_t rec_len,
- const char *recid_buf, size_t recid_len,
- int action)
+ZEBRA_RES zebra_admin_exchange_record (ZebraHandle zh,
+ const char *rec_buf,
+ size_t rec_len,
+ const char *recid_buf, size_t recid_len,
+ int action)
/* 1 = insert. Fail it already exists */
/* 2 = replace. Fail it does not exist */
/* 3 = delete. Fail if does not exist */
/* 4 = update. Insert/replace */
{
+ ZEBRA_RES res;
SYSNO sysno = 0;
char *rinfo = 0;
char recid_z[256];
zh->errCode = 0;
if (!recid_buf || recid_len <= 0 || recid_len >= sizeof(recid_z))
- return -1;
+ return ZEBRA_FAIL;
+
memcpy (recid_z, recid_buf, recid_len);
recid_z[recid_len] = 0;
- if (zebra_begin_trans(zh, 1))
- return -1;
+ if (zebra_begin_trans(zh, 1) == ZEBRA_FAIL)
+ return ZEBRA_FAIL;
rinfo = dict_lookup (zh->reg->matchDict, recid_z);
if (rinfo)
if (action == 1) /* fail if insert */
{
zebra_end_trans(zh);
- return -1;
+ return ZEBRA_FAIL;
}
memcpy (&sysno, rinfo+1, sizeof(sysno));
if (action == 2 || action == 3) /* fail if delete or update */
{
zebra_end_trans(zh);
- return -1;
+ return ZEBRA_FAIL;
}
action = 1; /* make it an insert (if it's an update).. */
}
- buffer_extract_record (zh, rec_buf, rec_len,
- action == 3 ? 1 : 0 /* delete flag */,
- 0, /* test mode */
- 0, /* recordType */
- &sysno,
- 0, /* match */
- 0, /* fname */
+ res = buffer_extract_record (zh, rec_buf, rec_len,
+ action == 3 ? 1 : 0 /* delete flag */,
+ 0, /* test mode */
+ 0, /* recordType */
+ &sysno,
+ 0, /* match */
+ 0, /* fname */
0, /* force update */
- 1 /* allow update */
+ 1 /* allow update */
);
if (action == 1)
{
dict_delete (zh->reg->matchDict, recid_z);
}
zebra_end_trans(zh);
- return 0;
+ return res;
}
int delete_w_handle(const char *info, void *handle)
return 0;
}
-int zebra_drop_database (ZebraHandle zh, const char *database)
+ZEBRA_RES zebra_drop_database (ZebraHandle zh, const char *database)
{
- int ret = 0;
+ ZEBRA_RES ret = ZEBRA_OK;
ASSERTZH;
yaz_log(log_level, "zebra_drop_database");
zh->errCode = 0;
- if (zebra_select_database (zh, database))
- return -1;
- if (zebra_begin_trans (zh, 1))
- return -1;
+ if (zebra_select_database (zh, database) == ZEBRA_FAIL)
+ return ZEBRA_FAIL;
+ if (zebra_begin_trans (zh, 1) == ZEBRA_FAIL)
+ return ZEBRA_FAIL;
if (zh->reg->isamb)
{
zebraExplain_curDatabase (zh->reg->zei, database);
else
{
yaz_log(YLOG_WARN, "drop database only supported for isam:b");
- ret = -1;
+ ret = ZEBRA_FAIL;
}
zebra_end_trans (zh);
return ret;
}
-int zebra_create_database (ZebraHandle zh, const char *database)
+ZEBRA_RES zebra_create_database (ZebraHandle zh, const char *database)
{
ASSERTZH;
- yaz_log(log_level, "zebra_create_database %s",database);
+ yaz_log(log_level, "zebra_create_database %s", database);
assert(database);
zh->errCode = 0;
- if (zebra_select_database (zh, database))
- return -1;
+ if (zebra_select_database (zh, database) == ZEBRA_FAIL)
+ return ZEBRA_FAIL;
if (zebra_begin_trans (zh, 1))
- return -1;
+ return ZEBRA_FAIL;
/* announce database */
if (zebraExplain_newDatabase (zh->reg->zei, database, 0
zebra_end_trans (zh);
zh->errCode = 224;
zh->errString = "database already exist";
- return -1;
+ return ZEBRA_FAIL;
}
- zebra_end_trans (zh);
- return 0;
+ return zebra_end_trans (zh);
}
int zebra_string_norm (ZebraHandle zh, unsigned reg_id,
return wrbuf_len(wrbuf);
}
-
-int zebra_set_state (ZebraHandle zh, int val, int seqno)
- /* FIXME - zint seqno ?? */
+static void zebra_set_state (ZebraHandle zh, int val, int seqno)
{
char state_fname[256];
char *fname;
fprintf (f, "%c %d %ld\n", val, seqno, p);
fclose (f);
xfree(fname);
- return 0;
}
-int zebra_get_state (ZebraHandle zh, char *val, int *seqno)
+static void zebra_get_state (ZebraHandle zh, char *val, int *seqno)
{
char state_fname[256];
char *fname;
fclose (f);
}
xfree(fname);
- return 0;
}
-int zebra_begin_read (ZebraHandle zh)
+ZEBRA_RES zebra_begin_read (ZebraHandle zh)
{
return zebra_begin_trans(zh, 0);
}
-int zebra_end_read (ZebraHandle zh)
+ZEBRA_RES zebra_end_read (ZebraHandle zh)
{
return zebra_end_trans(zh);
}
zh->m_file_verbose_limit = atoi(v);
}
-int zebra_begin_trans (ZebraHandle zh, int rw)
+ZEBRA_RES zebra_begin_trans(ZebraHandle zh, int rw)
{
ASSERTZH;
zebra_select_default_database(zh);
{
zh->errCode = 2;
zh->errString = "zebra_begin_trans: no database selected";
- return -1;
+ return ZEBRA_FAIL;
}
ASSERTZHRES;
yaz_log(log_level, "zebra_begin_trans rw=%d",rw);
{
zh->errCode = 223;
zh->errString = 0;
- return -1;
+ return ZEBRA_FAIL;
}
}
{
zh->errCode = 2;
zh->errString = "zebra_begin_trans: write trans not allowed within read trans";
- return -1;
+ return ZEBRA_FAIL;
}
if (zh->reg)
{
{
yaz_log (YLOG_FATAL, "zebra_begin_trans couldn't finish commit");
abort();
- return -1;
+ return ZEBRA_FAIL;
}
zebra_set_state (zh, 'd', seqno);
zh->errCode = 2;
zh->errString = "zebra_begin_trans: cannot open register";
yaz_log(YLOG_FATAL, zh->errString);
- return -1;
+ return ZEBRA_FAIL;
}
}
else
if (zh->trans_no != 1)
{
zebra_flush_reg (zh);
- return 0;
+ return ZEBRA_OK;
}
zh->errCode = 0;
#if HAVE_SYS_TIMES_H
{
(zh->trans_no)--;
zh->errCode = 109;
- return -1;
+ return ZEBRA_FAIL;
}
if (!zh->lock_normal || !zh->lock_shadow)
{
(zh->trans_no)--;
zh->errCode = 2;
- return -1;
+ return ZEBRA_FAIL;
}
zebra_get_state (zh, &val, &seqno);
if (val == 'd')
dirty = 1;
}
if (!dirty)
- return 0;
+ return ZEBRA_OK;
if (val == 'c')
zebra_lock_r (zh->lock_shadow);
zebra_unlock (zh->lock_shadow);
zh->trans_no--;
zh->errCode = 109;
- return -1;
+ return ZEBRA_FAIL;
}
zh->reg->last_val = val;
zh->reg->seqno = seqno;
}
read_res_for_transaction(zh);
- return 0;
+ return ZEBRA_OK;
}
-int zebra_end_trans (ZebraHandle zh)
+ZEBRA_RES zebra_end_trans (ZebraHandle zh)
{
ZebraTransactionStatus dummy;
ASSERTZH;
return zebra_end_transaction(zh, &dummy);
}
-int zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status)
+ZEBRA_RES zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status)
{
char val;
int seqno;
{
zh->errCode = 2;
zh->errString = "zebra_end_trans: no open transaction";
- return -1;
+ return ZEBRA_FAIL;
}
if (zh->trans_no != zh->trans_w_no)
{
zh->trans_no--;
if (zh->trans_no != 0)
- return 0;
+ return ZEBRA_OK;
/* release read lock */
status->utime = (long) (zh->tms2.tms_utime - zh->tms1.tms_utime);
status->stime = (long) (zh->tms2.tms_stime - zh->tms1.tms_stime);
#endif
- return 0;
+ return ZEBRA_OK;
}
int zebra_repository_update (ZebraHandle zh, const char *path)
return 0;
}
-int zebra_clean (ZebraHandle zh)
+ZEBRA_RES zebra_clean (ZebraHandle zh)
{
ASSERTZH;
yaz_log(log_level, "zebra_clean");
return zebra_commit_ex(zh, 1);
}
-int zebra_commit (ZebraHandle zh)
+ZEBRA_RES zebra_commit (ZebraHandle zh)
{
ASSERTZH;
yaz_log(log_level, "zebra_commit");
return zebra_commit_ex(zh, 0);
}
-int zebra_init (ZebraHandle zh)
+ZEBRA_RES zebra_init (ZebraHandle zh)
{
const char *rval;
BFiles bfs = 0;
if (!zh->res)
{
zh->errCode = 109;
- return -1;
+ return ZEBRA_FAIL;
}
rval = res_get (zh->res, "shadow");
bfs = bfs_create (res_get (zh->res, "register"), zh->path_reg);
if (!bfs)
- return -1;
+ return ZEBRA_FAIL;
if (rval && *rval)
bf_cache (bfs, rval);
bf_reset (bfs);
bfs_destroy (bfs);
zebra_set_state (zh, 'o', 0);
- return 0;
+ return ZEBRA_OK;
}
int zebra_compact (ZebraHandle zh)
return 0;
}
-int zebra_shadow_enable (ZebraHandle zh, int value)
+void zebra_shadow_enable (ZebraHandle zh, int value)
{
ASSERTZH;
yaz_log(log_level, "zebra_shadow_enable");
zh->errCode = 0;
zh->shadow_enable = value;
- return 0;
}
-int zebra_octet_term_encoding(ZebraHandle zh, const char *encoding)
+ZEBRA_RES zebra_octet_term_encoding(ZebraHandle zh, const char *encoding)
{
ASSERTZH;
assert(encoding);
if (zh->iconv_to_utf8 == 0)
yaz_log (YLOG_WARN, "iconv: UTF-8 to %s unsupported", encoding);
- return 0;
+ return ZEBRA_OK;
}
-int zebra_record_encoding (ZebraHandle zh, const char *encoding)
+ZEBRA_RES zebra_record_encoding (ZebraHandle zh, const char *encoding)
{
ASSERTZH;
yaz_log(log_level, "zebra_record_encoding");
zh->record_encoding = 0;
if (encoding)
zh->record_encoding = xstrdup (encoding);
- return 0;
+ return ZEBRA_OK;
}
-int zebra_set_resource(ZebraHandle zh, const char *name, const char *value)
+void zebra_set_resource(ZebraHandle zh, const char *name, const char *value)
{
ASSERTZH;
assert(name);
yaz_log(log_level, "zebra_set_resource %s:%s",name,value);
zh->errCode = 0;
res_set(zh->res, name, value);
- return 0;
}
const char *zebra_get_resource(ZebraHandle zh,
return (zh->shadow_enable);
}
-int zebra_set_shadow_enable (ZebraHandle zh, int value)
+void zebra_set_shadow_enable (ZebraHandle zh, int value)
{
ASSERTZH;
yaz_log(log_level, "zebra_set_shadow_enable %d",value);
zh->shadow_enable = value;
- return 0;
}
/* Used by Perl API.. Added the record buffer dup to zebra_records_retrieve
return zebra_update_record(zh, 0, &sysno, 0, 0, buf, buf_size, 0);
}
-int zebra_insert_record (ZebraHandle zh,
- const char *recordType,
- SYSNO *sysno, const char *match, const char *fname,
- const char *buf, int buf_size, int force_update)
+ZEBRA_RES zebra_insert_record (ZebraHandle zh,
+ const char *recordType,
+ SYSNO *sysno, const char *match,
+ const char *fname,
+ const char *buf, int buf_size, int force_update)
{
- int res;
+ ZEBRA_RES res;
ASSERTZH;
assert(sysno);
assert(buf);
if (buf_size < 1)
buf_size = strlen(buf);
- if (zebra_begin_trans(zh, 1))
- return 1;
+ if (zebra_begin_trans(zh, 1) == ZEBRA_FAIL)
+ return ZEBRA_FAIL;
res = buffer_extract_record (zh, buf, buf_size,
0, /* delete_flag */
0, /* test_mode */
return res;
}
-int zebra_update_record (ZebraHandle zh,
- const char *recordType,
- SYSNO* sysno, const char *match, const char *fname,
- const char *buf, int buf_size,
- int force_update)
+ZEBRA_RES zebra_update_record (ZebraHandle zh,
+ const char *recordType,
+ SYSNO* sysno, const char *match,
+ const char *fname,
+ const char *buf, int buf_size,
+ int force_update)
{
- int res;
+ ZEBRA_RES res;
ASSERTZH;
assert(sysno);
assert(buf);
if (buf_size < 1) buf_size = strlen(buf);
- if (zebra_begin_trans(zh, 1))
- return 1;
+ if (zebra_begin_trans(zh, 1) == ZEBRA_FAIL)
+ return ZEBRA_FAIL;
res = buffer_extract_record (zh, buf, buf_size,
0, /* delete_flag */
0, /* test_mode */
return res;
}
-int zebra_delete_record (ZebraHandle zh,
- const char *recordType,
- SYSNO *sysno, const char *match, const char *fname,
- const char *buf, int buf_size,
- int force_update)
+ZEBRA_RES zebra_delete_record (ZebraHandle zh,
+ const char *recordType,
+ SYSNO *sysno, const char *match,
+ const char *fname,
+ const char *buf, int buf_size,
+ int force_update)
{
- int res;
+ ZEBRA_RES res;
ASSERTZH;
assert(sysno);
assert(buf);
if (buf_size < 1) buf_size = strlen(buf);
- if (zebra_begin_trans(zh, 1))
- return 1;
+ if (zebra_begin_trans(zh, 1) == ZEBRA_FAIL)
+ return ZEBRA_FAIL;
res = buffer_extract_record (zh, buf, buf_size,
1, /* delete_flag */
0, /* test_mode */
force_update,
1); /* allow_update */
zebra_end_trans(zh);
- return res;
+ return res;
}
/* ---------------------------------------------------------------------------
Searching
*/
-int zebra_search_PQF (ZebraHandle zh, const char *pqf_query,
- const char *setname, zint *numhits)
+ZEBRA_RES zebra_search_PQF (ZebraHandle zh, const char *pqf_query,
+ const char *setname, zint *numhits)
{
zint hits = 0;
- int res = -1;
+ ZEBRA_RES res = ZEBRA_OK;
Z_RPNQuery *query;
ODR odr = odr_createmem(ODR_ENCODE);
ASSERTZH;
query = p_query_rpn (odr, PROTO_Z3950, pqf_query);
if (!query)
+ {
yaz_log (YLOG_WARN, "bad query %s\n", pqf_query);
+ res = ZEBRA_FAIL;
+ }
else
res = zebra_search_RPN (zh, odr, query, setname, &hits);
-/* $Id: zrpn.c,v 1.174 2005-04-14 09:03:24 adam Exp $
+/* $Id: zrpn.c,v 1.175 2005-04-15 10:47:48 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
* ([^a-].*|a[^b-].*|ab[^c-].*|abc)
*/
static int string_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
- const char **term_sub, char *term_dict,
- oid_value attributeSet,
- int reg_type, int space_split, char *term_dst)
+ const char **term_sub, char *term_dict,
+ oid_value attributeSet,
+ int reg_type, int space_split, char *term_dst,
+ int *error_code)
{
AttrType relation;
int relation_value;
attr_init(&relation, zapt, 2);
relation_value = attr_find(&relation, NULL);
+ *error_code = 0;
yaz_log(YLOG_DEBUG, "string relation value=%d", relation_value);
switch (relation_value)
{
*term_tmp = '\0';
break;
case 3:
- default:
+ case 102:
+ case -1:
yaz_log(log_level_rpn, "Relation =");
if (!term_100 (zh->reg->zebra_maps, reg_type, term_sub,
term_component, space_split, term_dst))
strcat(term_tmp, "(");
strcat(term_tmp, term_component);
strcat(term_tmp, ")");
+ break;
+ default:
+ *error_code = 117;
+ return 0;
}
return 1;
}
-static int string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
- const char **term_sub,
- oid_value attributeSet, NMEM stream,
- struct grep_info *grep_info,
- int reg_type, int complete_flag,
- int num_bases, char **basenames,
- char *term_dst, int xpath_use);
+static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
+ const char **term_sub,
+ oid_value attributeSet, NMEM stream,
+ struct grep_info *grep_info,
+ int reg_type, int complete_flag,
+ int num_bases, char **basenames,
+ char *term_dst, int xpath_use);
static RSET term_trunc(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
- const char **term_sub,
- oid_value attributeSet, NMEM stream,
- struct grep_info *grep_info,
- int reg_type, int complete_flag,
- int num_bases, char **basenames,
- char *term_dst,
- const char *rank_type, int xpath_use,
- NMEM rset_nmem)
+ const char **term_sub,
+ oid_value attributeSet, NMEM stream,
+ struct grep_info *grep_info,
+ int reg_type, int complete_flag,
+ int num_bases, char **basenames,
+ char *term_dst,
+ const char *rank_type, int xpath_use,
+ NMEM rset_nmem)
{
- int r;
+ ZEBRA_RES res;
grep_info->isam_p_indx = 0;
- r = string_term(zh, zapt, term_sub, attributeSet, stream, grep_info,
- reg_type, complete_flag, num_bases, basenames,
- term_dst, xpath_use);
- if (r < 1)
+ res = string_term(zh, zapt, term_sub, attributeSet, stream, grep_info,
+ reg_type, complete_flag, num_bases, basenames,
+ term_dst, xpath_use);
+ if (res != ZEBRA_OK)
return 0;
+ if (!*term_sub) /* no more terms ? */
+ return 0;
yaz_log(log_level_rpn, "term: %s", term_dst);
return rset_trunc(zh, grep_info->isam_p_buf,
- grep_info->isam_p_indx, term_dst,
- strlen(term_dst), rank_type, 1 /* preserve pos */,
- zapt->term->which, rset_nmem,
- key_it_ctrl,key_it_ctrl->scope);
+ grep_info->isam_p_indx, term_dst,
+ strlen(term_dst), rank_type, 1 /* preserve pos */,
+ zapt->term->which, rset_nmem,
+ key_it_ctrl, key_it_ctrl->scope);
}
static char *nmem_strdup_i(NMEM nmem, int v)
{
return nmem_strdup(nmem, val_str);
}
-static int string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
- const char **term_sub,
- oid_value attributeSet, NMEM stream,
- struct grep_info *grep_info,
- int reg_type, int complete_flag,
- int num_bases, char **basenames,
- char *term_dst, int xpath_use)
+static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
+ const char **term_sub,
+ oid_value attributeSet, NMEM stream,
+ struct grep_info *grep_info,
+ int reg_type, int complete_flag,
+ int num_bases, char **basenames,
+ char *term_dst, int xpath_use)
{
char term_dict[2*IT_MAX_WORD+4000];
int j, r, base_no;
data1_local_attribute id_xpath_attr;
data1_local_attribute *local_attr;
int max_pos, prefix_len = 0;
+ int relation_error;
termp = *term_sub;
{
zh->errCode = 109; /* Database unavailable */
zh->errString = basenames[base_no];
- return -1;
+ return ZEBRA_FAIL;
}
if (xpath_use > 0 && use_value == -2)
{
term_dict[prefix_len++] = ord_buf[i];
}
}
- if (!prefix_len)
- {
-#if 1
- bases_ok++;
-#else
- errCode = 114;
- errString = nmem_strdup_i(stream, use_value);
- continue;
-#endif
- }
- else
- {
- bases_ok++; /* this has OK attributes */
+ bases_ok++;
+ if (prefix_len)
attr_ok = 1;
- }
term_dict[prefix_len++] = ')';
term_dict[prefix_len++] = 1;
case 100: /* do not truncate */
if (!string_relation (zh, zapt, &termp, term_dict,
attributeSet,
- reg_type, space_split, term_dst))
- return 0;
+ reg_type, space_split, term_dst,
+ &relation_error))
+ {
+ if (relation_error)
+ {
+ zh->errCode = relation_error;
+ return ZEBRA_FAIL;
+ }
+ *term_sub = 0;
+ return ZEBRA_OK;
+ }
break;
case 1: /* right truncation */
term_dict[j++] = '(';
if (!term_100(zh->reg->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst))
- return 0;
+ {
+ *term_sub = 0;
+ return ZEBRA_OK;
+ }
strcat(term_dict, ".*)");
break;
case 2: /* keft truncation */
term_dict[j++] = '('; term_dict[j++] = '.'; term_dict[j++] = '*';
if (!term_100(zh->reg->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst))
- return 0;
+ {
+ *term_sub = 0;
+ return ZEBRA_OK;
+ }
strcat(term_dict, ")");
break;
case 3: /* left&right truncation */
term_dict[j++] = '('; term_dict[j++] = '.'; term_dict[j++] = '*';
if (!term_100(zh->reg->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst))
- return 0;
+ {
+ *term_sub = 0;
+ return ZEBRA_OK;
+ }
strcat(term_dict, ".*)");
break;
case 101: /* process # in term */
term_dict[j++] = '(';
if (!term_101(zh->reg->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst))
- return 0;
+ {
+ *term_sub = 0;
+ return ZEBRA_OK;
+ }
strcat(term_dict, ")");
break;
case 102: /* Regexp-1 */
term_dict[j++] = '(';
if (!term_102(zh->reg->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst))
- return 0;
+ {
+ *term_sub = 0;
+ return ZEBRA_OK;
+ }
strcat(term_dict, ")");
break;
case 103: /* Regexp-2 */
if (!term_103 (zh->reg->zebra_maps, reg_type,
&termp, term_dict + j, ®ex_range,
space_split, term_dst))
- return 0;
+ {
+ *term_sub = 0;
+ return ZEBRA_OK;
+ }
strcat(term_dict, ")");
case 104: /* process # and ! in term */
term_dict[j++] = '(';
if (!term_104 (zh->reg->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst))
- return 0;
+ {
+ *term_sub = 0;
+ return ZEBRA_OK;
+ }
strcat(term_dict, ")");
break;
case 105: /* process * and ! in term */
term_dict[j++] = '(';
if (!term_105 (zh->reg->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst, 1))
- return 0;
+ {
+ *term_sub = 0;
+ return ZEBRA_OK;
+ }
strcat(term_dict, ")");
break;
case 106: /* process * and ! in term */
term_dict[j++] = '(';
if (!term_105 (zh->reg->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst, 0))
- return 0;
+ {
+ *term_sub = 0;
+ return ZEBRA_OK;
+ }
strcat(term_dict, ")");
break;
default:
zh->errCode = 120;
zh->errString = nmem_strdup_i(stream, truncation_value);
- return -1;
+ return ZEBRA_FAIL;
}
if (attr_ok)
{
{
zh->errCode = errCode;
zh->errString = errString;
- return -1;
+ return ZEBRA_FAIL;
}
*term_sub = termp;
yaz_log(YLOG_DEBUG, "%d positions", grep_info->isam_p_indx);
- return 1;
+ return ZEBRA_OK;
}
}
-static RSET rpn_search_APT_phrase (ZebraHandle zh,
- Z_AttributesPlusTerm *zapt,
- const char *termz_org,
- oid_value attributeSet,
- NMEM stream,
- int reg_type, int complete_flag,
- const char *rank_type, int xpath_use,
- int num_bases, char **basenames,
- NMEM rset_nmem)
+static RSET rpn_search_APT_phrase(ZebraHandle zh,
+ Z_AttributesPlusTerm *zapt,
+ const char *termz_org,
+ oid_value attributeSet,
+ NMEM stream,
+ int reg_type, int complete_flag,
+ const char *rank_type, int xpath_use,
+ int num_bases, char **basenames,
+ NMEM rset_nmem)
{
char term_dst[IT_MAX_WORD+1];
RSET rset[TERM_LIST_LENGTH_MAX], result;
{
yaz_log(log_level_rpn, "APT_phrase termp=%s", termp);
rset[rset_no] = term_trunc(zh, zapt, &termp, attributeSet,
- stream, &grep_info,
- reg_type, complete_flag,
- num_bases, basenames,
- term_dst, rank_type,
- xpath_use,rset_nmem);
- if (!rset[rset_no])
- break;
+ stream, &grep_info,
+ reg_type, complete_flag,
+ num_bases, basenames,
+ term_dst, rank_type,
+ xpath_use, rset_nmem);
+ if (!rset[rset_no]) /* error or no more terms */
+ break;
}
grep_info_delete (&grep_info);
+ if (termp)
+ {
+ int i;
+ for (i = 0; i<rset_no; i++)
+ rset_delete(rset[i]);
+ return 0;
+ }
if (rset_no == 0)
return rsnull_create (rset_nmem,key_it_ctrl);
else if (rset_no == 1)
return result;
}
-static RSET rpn_search_APT_or_list (ZebraHandle zh,
- Z_AttributesPlusTerm *zapt,
- const char *termz_org,
- oid_value attributeSet,
- NMEM stream,
- int reg_type, int complete_flag,
- const char *rank_type,
- int xpath_use,
- int num_bases, char **basenames,
- NMEM rset_nmem)
+static RSET rpn_search_APT_or_list(ZebraHandle zh,
+ Z_AttributesPlusTerm *zapt,
+ const char *termz_org,
+ oid_value attributeSet,
+ NMEM stream,
+ int reg_type, int complete_flag,
+ const char *rank_type,
+ int xpath_use,
+ int num_bases, char **basenames,
+ NMEM rset_nmem)
{
char term_dst[IT_MAX_WORD+1];
RSET rset[TERM_LIST_LENGTH_MAX];
char *termz = normalize_term(zh, zapt, termz_org, stream, reg_type);
const char *termp = termz;
- if (grep_info_prepare (zh, zapt, &grep_info, reg_type, stream))
+ if (grep_info_prepare(zh, zapt, &grep_info, reg_type, stream))
return 0;
for (; rset_no < sizeof(rset)/sizeof(*rset); rset_no++)
{
yaz_log(log_level_rpn, "APT_or_list termp=%s", termp);
rset[rset_no] = term_trunc(zh, zapt, &termp, attributeSet,
- stream, &grep_info,
- reg_type, complete_flag,
- num_bases, basenames,
- term_dst, rank_type,
- xpath_use,rset_nmem);
- if (!rset[rset_no])
- break;
+ stream, &grep_info,
+ reg_type, complete_flag,
+ num_bases, basenames,
+ term_dst, rank_type,
+ xpath_use, rset_nmem);
+ if (!rset[rset_no]) /* error or no more terms */
+ break;
}
grep_info_delete (&grep_info);
+ if (termp)
+ {
+ int i;
+ for (i = 0; i<rset_no; i++)
+ rset_delete(rset[i]);
+ return 0;
+ }
if (rset_no == 0)
return rsnull_create (rset_nmem,key_it_ctrl);
- return rsmulti_or_create(rset_nmem, key_it_ctrl,key_it_ctrl->scope,
+ return rsmulti_or_create(rset_nmem, key_it_ctrl, key_it_ctrl->scope,
rset_no, rset);
}
-static RSET rpn_search_APT_and_list (ZebraHandle zh,
- Z_AttributesPlusTerm *zapt,
- const char *termz_org,
- oid_value attributeSet,
- NMEM stream,
- int reg_type, int complete_flag,
- const char *rank_type,
- int xpath_use,
- int num_bases, char **basenames,
- NMEM rset_nmem)
+static RSET rpn_search_APT_and_list(ZebraHandle zh,
+ Z_AttributesPlusTerm *zapt,
+ const char *termz_org,
+ oid_value attributeSet,
+ NMEM stream,
+ int reg_type, int complete_flag,
+ const char *rank_type,
+ int xpath_use,
+ int num_bases, char **basenames,
+ NMEM rset_nmem)
{
char term_dst[IT_MAX_WORD+1];
RSET rset[TERM_LIST_LENGTH_MAX];
char *termz = normalize_term(zh, zapt, termz_org, stream, reg_type);
const char *termp = termz;
- if (grep_info_prepare (zh, zapt, &grep_info, reg_type, stream))
+ if (grep_info_prepare(zh, zapt, &grep_info, reg_type, stream))
return 0;
for (; rset_no < sizeof(rset)/sizeof(*rset); rset_no++)
{
yaz_log(log_level_rpn, "APT_and_list termp=%s", termp);
rset[rset_no] = term_trunc(zh, zapt, &termp, attributeSet,
- stream, &grep_info,
- reg_type, complete_flag,
- num_bases, basenames,
- term_dst, rank_type,
- xpath_use, rset_nmem);
- if (!rset[rset_no])
- break;
+ stream, &grep_info,
+ reg_type, complete_flag,
+ num_bases, basenames,
+ term_dst, rank_type,
+ xpath_use, rset_nmem);
+ if (!rset[rset_no]) /* error or no more terms */
+ break;
}
grep_info_delete (&grep_info);
+ if (termp)
+ {
+ int i;
+ for (i = 0; i<rset_no; i++)
+ rset_delete(rset[i]);
+ return 0;
+ }
if (rset_no == 0)
- return rsnull_create(rset_nmem,key_it_ctrl);
+ return rsnull_create(rset_nmem, key_it_ctrl);
return rsmulti_and_create(rset_nmem, key_it_ctrl, key_it_ctrl->scope,
rset_no, rset);
}
-static int numeric_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
- const char **term_sub,
- char *term_dict,
- oid_value attributeSet,
- struct grep_info *grep_info,
- int *max_pos,
- int reg_type,
- char *term_dst)
+static int numeric_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
+ const char **term_sub,
+ char *term_dict,
+ oid_value attributeSet,
+ struct grep_info *grep_info,
+ int *max_pos,
+ int reg_type,
+ char *term_dst,
+ int *error_code)
{
AttrType relation;
int relation_value;
int r;
char *term_tmp = term_dict + strlen(term_dict);
+ *error_code = 0;
attr_init (&relation, zapt, 2);
relation_value = attr_find (&relation, NULL);
yaz_log(log_level_rpn, "numeric relation value=%d", relation_value);
- if (!term_100 (zh->reg->zebra_maps, reg_type, term_sub, term_tmp, 1,
- term_dst))
+ if (!term_100(zh->reg->zebra_maps, reg_type, term_sub, term_tmp, 1,
+ term_dst))
return 0;
term_value = atoi (term_tmp);
switch (relation_value)
{
case 1:
yaz_log(log_level_rpn, "Relation <");
- gen_regular_rel (term_tmp, term_value-1, 1);
+ gen_regular_rel(term_tmp, term_value-1, 1);
break;
case 2:
yaz_log(log_level_rpn, "Relation <=");
- gen_regular_rel (term_tmp, term_value, 1);
+ gen_regular_rel(term_tmp, term_value, 1);
break;
case 4:
yaz_log(log_level_rpn, "Relation >=");
- gen_regular_rel (term_tmp, term_value, 0);
+ gen_regular_rel(term_tmp, term_value, 0);
break;
case 5:
yaz_log(log_level_rpn, "Relation >");
- gen_regular_rel (term_tmp, term_value+1, 0);
+ gen_regular_rel(term_tmp, term_value+1, 0);
break;
+ case -1:
case 3:
- default:
yaz_log(log_level_rpn, "Relation =");
- sprintf (term_tmp, "(0*%d)", term_value);
+ sprintf(term_tmp, "(0*%d)", term_value);
+ break;
+ default:
+ *error_code = 117;
+ return 0;
}
yaz_log(log_level_rpn, "dict_lookup_grep: %s", term_tmp);
r = dict_lookup_grep(zh->reg->dict, term_dict, 0, grep_info, max_pos,
return 1;
}
-static int numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
- const char **term_sub,
- oid_value attributeSet, struct grep_info *grep_info,
- int reg_type, int complete_flag,
- int num_bases, char **basenames,
- char *term_dst, int xpath_use, NMEM stream)
+static ZEBRA_RES numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
+ const char **term_sub,
+ oid_value attributeSet,
+ struct grep_info *grep_info,
+ int reg_type, int complete_flag,
+ int num_bases, char **basenames,
+ char *term_dst, int xpath_use, NMEM stream)
{
char term_dict[2*IT_MAX_WORD+2];
int r, base_no;
data1_local_attribute id_xpath_attr;
data1_local_attribute *local_attr;
int max_pos, prefix_len = 0;
+ int relation_error = 0;
termp = *term_sub;
if (use_value == -2) /* string attribute (assume IDXPATH/any) */
term_dict[prefix_len++] = reg_type;
yaz_log(YLOG_DEBUG, "reg_type = %d", term_dict[prefix_len-1]);
term_dict[prefix_len] = '\0';
- if (!numeric_relation (zh, zapt, &termp, term_dict,
- attributeSet, grep_info, &max_pos, reg_type,
- term_dst))
- return 0;
+ if (!numeric_relation(zh, zapt, &termp, term_dict,
+ attributeSet, grep_info, &max_pos, reg_type,
+ term_dst, &relation_error))
+ {
+ if (relation_error)
+ {
+ zh->errCode = relation_error;
+ zh->errString = 0;
+ return ZEBRA_FAIL;
+ }
+ *term_sub = 0;
+ return ZEBRA_OK;
+ }
}
if (!bases_ok)
{
zh->errCode = errCode;
zh->errString = errString;
- return -1;
+ return ZEBRA_FAIL;
}
*term_sub = termp;
yaz_log(YLOG_DEBUG, "%d positions", grep_info->isam_p_indx);
- return 1;
+ return ZEBRA_OK;
}
-static RSET rpn_search_APT_numeric (ZebraHandle zh,
- Z_AttributesPlusTerm *zapt,
- const char *termz,
- oid_value attributeSet,
- NMEM stream,
- int reg_type, int complete_flag,
- const char *rank_type, int xpath_use,
- int num_bases, char **basenames,
- NMEM rset_nmem)
+static RSET rpn_search_APT_numeric(ZebraHandle zh,
+ Z_AttributesPlusTerm *zapt,
+ const char *termz,
+ oid_value attributeSet,
+ NMEM stream,
+ int reg_type, int complete_flag,
+ const char *rank_type, int xpath_use,
+ int num_bases, char **basenames,
+ NMEM rset_nmem)
{
char term_dst[IT_MAX_WORD+1];
const char *termp = termz;
RSET rset[TERM_LIST_LENGTH_MAX];
- int r;
+ ZEBRA_RES r;
size_t rset_no = 0;
struct grep_info grep_info;
yaz_log(YLOG_DEBUG, "APT_numeric termp=%s", termp);
grep_info.isam_p_indx = 0;
r = numeric_term(zh, zapt, &termp, attributeSet, &grep_info,
- reg_type, complete_flag, num_bases, basenames,
- term_dst, xpath_use,
- stream);
- if (r < 1)
- break;
+ reg_type, complete_flag, num_bases, basenames,
+ term_dst, xpath_use,
+ stream);
+ if (r == ZEBRA_FAIL || termp == 0)
+ break;
yaz_log(YLOG_DEBUG, "term: %s", term_dst);
rset[rset_no] = rset_trunc(zh, grep_info.isam_p_buf,
grep_info.isam_p_indx, term_dst,
break;
}
grep_info_delete (&grep_info);
+ if (termp)
+ {
+ int i;
+ for (i = 0; i<rset_no; i++)
+ rset_delete(rset[i]);
+ return 0;
+ }
if (rset_no == 0)
return rsnull_create(rset_nmem,key_it_ctrl);
if (rset_no == 1)
-static RSET rpn_search_APT (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
- oid_value attributeSet, NMEM stream,
- Z_SortKeySpecList *sort_sequence,
- int num_bases, char **basenames,
- NMEM rset_nmem)
+static RSET rpn_search_APT(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
+ oid_value attributeSet, NMEM stream,
+ Z_SortKeySpecList *sort_sequence,
+ int num_bases, char **basenames,
+ NMEM rset_nmem)
{
unsigned reg_id;
char *search_type = NULL;
log_level_rpn = yaz_log_module_level("rpn");
log_level_set = 1;
}
- zebra_maps_attr (zh->reg->zebra_maps, zapt, ®_id, &search_type,
- rank_type, &complete_flag, &sort_flag);
+ zebra_maps_attr(zh->reg->zebra_maps, zapt, ®_id, &search_type,
+ rank_type, &complete_flag, &sort_flag);
yaz_log(YLOG_DEBUG, "reg_id=%c", reg_id);
yaz_log(YLOG_DEBUG, "complete_flag=%d", complete_flag);
return 0;
if (sort_flag)
- return rpn_sort_spec (zh, zapt, attributeSet, stream, sort_sequence,
- rank_type);
+ return rpn_sort_spec(zh, zapt, attributeSet, stream, sort_sequence,
+ rank_type);
xpath_len = parse_xpath(zh, zapt, attributeSet, xpath, 10, stream);
if (xpath_len >= 0)
{
if (!strcmp (search_type, "phrase"))
{
- rset = rpn_search_APT_phrase (zh, zapt, termz, attributeSet, stream,
- reg_id, complete_flag, rank_type,
- xpath_use,
- num_bases, basenames, rset_nmem);
+ rset = rpn_search_APT_phrase(zh, zapt, termz, attributeSet, stream,
+ reg_id, complete_flag, rank_type,
+ xpath_use,
+ num_bases, basenames, rset_nmem);
}
else if (!strcmp (search_type, "and-list"))
{
- rset = rpn_search_APT_and_list (zh, zapt, termz, attributeSet, stream,
- reg_id, complete_flag, rank_type,
- xpath_use,
- num_bases, basenames, rset_nmem);
+ rset = rpn_search_APT_and_list(zh, zapt, termz, attributeSet, stream,
+ reg_id, complete_flag, rank_type,
+ xpath_use,
+ num_bases, basenames, rset_nmem);
}
else if (!strcmp (search_type, "or-list"))
{
- rset = rpn_search_APT_or_list (zh, zapt, termz, attributeSet, stream,
- reg_id, complete_flag, rank_type,
- xpath_use,
- num_bases, basenames, rset_nmem);
+ rset = rpn_search_APT_or_list(zh, zapt, termz, attributeSet, stream,
+ reg_id, complete_flag, rank_type,
+ xpath_use,
+ num_bases, basenames, rset_nmem);
}
else if (!strcmp (search_type, "local"))
{
- rset = rpn_search_APT_local (zh, zapt, termz, attributeSet, stream,
- rank_type, rset_nmem);
+ rset = rpn_search_APT_local(zh, zapt, termz, attributeSet, stream,
+ rank_type, rset_nmem);
}
else if (!strcmp (search_type, "numeric"))
{
- rset = rpn_search_APT_numeric (zh, zapt, termz, attributeSet, stream,
- reg_id, complete_flag, rank_type,
- xpath_use,
- num_bases, basenames, rset_nmem);
+ rset = rpn_search_APT_numeric(zh, zapt, termz, attributeSet, stream,
+ reg_id, complete_flag, rank_type,
+ xpath_use,
+ num_bases, basenames, rset_nmem);
}
else if (!strcmp (search_type, "always"))
{
rset = 0;
}
else
+ {
zh->errCode = 118;
+ return 0;
+ }
return rpn_search_xpath (zh, attributeSet, num_bases, basenames,
stream, rank_type, rset,
xpath_len, xpath, rset_nmem);
}
-static RSET rpn_search_structure (ZebraHandle zh, Z_RPNStructure *zs,
- oid_value attributeSet,
- NMEM stream, NMEM rset_nmem,
- Z_SortKeySpecList *sort_sequence,
- int num_bases, char **basenames)
+RSET rpn_search_structure(ZebraHandle zh, Z_RPNStructure *zs,
+ oid_value attributeSet,
+ NMEM stream, NMEM rset_nmem,
+ Z_SortKeySpecList *sort_sequence,
+ int num_bases, char **basenames)
{
RSET r = NULL;
if (zs->which == Z_RPNStructure_complex)
Z_Operator *zop = zs->u.complex->roperator;
RSET rsets[2]; /* l and r argument */
- rsets[0]=rpn_search_structure (zh, zs->u.complex->s1,
- attributeSet, stream, rset_nmem,
- sort_sequence,
- num_bases, basenames);
+ rsets[0] = rpn_search_structure(zh, zs->u.complex->s1,
+ attributeSet, stream, rset_nmem,
+ sort_sequence,
+ num_bases, basenames);
if (rsets[0] == NULL)
return NULL;
- rsets[1]=rpn_search_structure (zh, zs->u.complex->s2,
- attributeSet, stream, rset_nmem,
- sort_sequence,
- num_bases, basenames);
+ rsets[1] = rpn_search_structure(zh, zs->u.complex->s2,
+ attributeSet, stream, rset_nmem,
+ sort_sequence,
+ num_bases, basenames);
if (rsets[1] == NULL)
{
- rset_delete (rsets[0]);
+ rset_delete(rsets[0]);
return NULL;
}
break;
case Z_Operator_and_not:
r = rsbool_create_not(rset_nmem,key_it_ctrl, key_it_ctrl->scope,
- rsets[0],rsets[1]);
+ rsets[0], rsets[1]);
break;
case Z_Operator_prox:
if (zop->u.prox->which != Z_ProximityOperator_known)
if (zs->u.simple->which == Z_Operand_APT)
{
yaz_log(YLOG_DEBUG, "rpn_search_APT");
- r = rpn_search_APT (zh, zs->u.simple->u.attributesPlusTerm,
- attributeSet, stream, sort_sequence,
- num_bases, basenames,rset_nmem);
+ r = rpn_search_APT(zh, zs->u.simple->u.attributesPlusTerm,
+ attributeSet, stream, sort_sequence,
+ num_bases, basenames,rset_nmem);
}
else if (zs->u.simple->which == Z_Operand_resultSetId)
{
r = resultSetRef (zh, zs->u.simple->u.resultSetId);
if (!r)
{
- r = rsnull_create (rset_nmem,key_it_ctrl);
zh->errCode = 30;
zh->errString =
nmem_strdup (stream, zs->u.simple->u.resultSetId);
return 0;
}
- else
- rset_dup(r);
+ rset_dup(r);
}
else
{
return r;
}
-
-RSET rpn_search(ZebraHandle zh, NMEM nmem, NMEM rset_nmem,
- Z_RPNQuery *rpn, int num_bases, char **basenames,
- const char *setname,
- ZebraSet sset)
-{
- RSET rset;
- oident *attrset;
- oid_value attributeSet;
- Z_SortKeySpecList *sort_sequence;
- int sort_status, i;
-
- zh->errCode = 0;
- zh->errString = NULL;
- zh->hits = 0;
-
- sort_sequence = (Z_SortKeySpecList *)
- nmem_malloc(nmem, sizeof(*sort_sequence));
- sort_sequence->num_specs = 10; /* FIXME - Hard-coded number */
- sort_sequence->specs = (Z_SortKeySpec **)
- nmem_malloc(nmem, sort_sequence->num_specs *
- sizeof(*sort_sequence->specs));
- for (i = 0; i<sort_sequence->num_specs; i++)
- sort_sequence->specs[i] = 0;
-
- attrset = oid_getentbyoid (rpn->attributeSetId);
- attributeSet = attrset->value;
- rset = rpn_search_structure (zh, rpn->RPNStructure, attributeSet,
- nmem, rset_nmem,
- sort_sequence, num_bases, basenames);
- if (!rset)
- return 0;
-
- if (zh->errCode)
- yaz_log(YLOG_DEBUG, "search error: %d", zh->errCode);
-
- for (i = 0; sort_sequence->specs[i]; i++)
- ;
- sort_sequence->num_specs = i;
- if (!i)
- resultSetRank (zh, sset, rset, rset_nmem);
- else
- {
- yaz_log(YLOG_DEBUG, "resultSetSortSingle in rpn_search");
- resultSetSortSingle (zh, nmem, sset, rset,
- sort_sequence, &sort_status);
- if (zh->errCode)
- {
- yaz_log(YLOG_DEBUG, "resultSetSortSingle status = %d", zh->errCode);
- }
- }
- return rset;
-}
-
struct scan_info_entry {
char *term;
ISAM_P isam_p;
yaz_log(YLOG_DEBUG, "%d keys, %d records", kno, *count);
}
-void rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
- oid_value attributeset,
- int num_bases, char **basenames,
- int *position, int *num_entries, ZebraScanEntry **list,
- int *is_partial, RSET limit_set, int return_zero)
+ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
+ oid_value attributeset,
+ int num_bases, char **basenames,
+ int *position, int *num_entries, ZebraScanEntry **list,
+ int *is_partial, RSET limit_set, int return_zero)
{
int i;
int pos = *position;
{
*num_entries = 0;
zh->errCode = 113;
- return ;
+ return ZEBRA_FAIL;
}
yaz_log (YLOG_DEBUG, "use_value = %d", use_value);
zh->errString = basenames[base_no];
zh->errCode = 109; /* Database unavailable */
*num_entries = 0;
- return;
+ return ZEBRA_FAIL;
}
if (use_string &&
zh->errCode = errCode;
zh->errString = errString;
*num_entries = 0;
- return;
+ return ZEBRA_FAIL;
}
if (ord_no == 0)
{
*num_entries = 0;
- return;
+ return ZEBRA_OK;
}
/* prepare dictionary scanning */
before = pos-1;
strcpy(scan_info->prefix, termz);
if (trans_scan_term(zh, zapt, termz+prefix_len, reg_id))
- return ;
+ return ZEBRA_FAIL;
dict_scan(zh->reg->dict, termz, &before_tmp, &after_tmp,
scan_info, scan_handle);
yaz_log(YLOG_DEBUG, "position = %d, num_entries = %d",
*position, *num_entries);
- if (zh->errCode)
- yaz_log(YLOG_DEBUG, "scan error: %d", zh->errCode);
+ return ZEBRA_OK;
}
-/* $Id: zserver.c,v 1.130 2005-03-08 14:02:12 adam Exp $
+/* $Id: zserver.c,v 1.131 2005-04-15 10:47:49 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
{
ZebraHandle zh = (ZebraHandle) handle;
zint zhits = 0;
+ ZEBRA_RES res;
r->hits = 0;
r->errcode = 0;
switch (r->query->which)
{
case Z_Query_type_1: case Z_Query_type_101:
- zebra_search_RPN (zh, r->stream, r->query->u.type_1,
- r->setname, &zhits);
- if (zhits > 2147483646)
- r->hits = 2147483647;
- else
+ res = zebra_search_RPN (zh, r->stream, r->query->u.type_1,
+ r->setname, &zhits);
+ if (zebra_errCode(zh) == 0)
+ {
+ if (zhits > 2147483646)
+ r->hits = 2147483647;
+ else
r->hits = (int) zhits;
- zebra_result (zh, &r->errcode, &r->errstring);
- if (!r->errcode)
search_terms (zh, r);
+ }
+ else
+ zebra_result (zh, &r->errcode, &r->errstring);
break;
case Z_Query_type_2:
r->errcode = 107;
}
else
{
- int r = -1;
+ ZEBRA_RES r = ZEBRA_FAIL;
switch(action) {
case 1:
r = zebra_insert_record(
rec->u.octet_aligned->buf,
rec->u.octet_aligned->len,
0);
- if (r)
+ if (r == ZEBRA_FAIL)
{
rr->errcode = 224;
rr->errstring = "insert_record failed";
rec->u.octet_aligned->buf,
rec->u.octet_aligned->len,
1);
- if (r)
+ if (r == ZEBRA_FAIL)
{
rr->errcode = 224;
rr->errstring = "update_record failed";
rec->u.octet_aligned->buf,
rec->u.octet_aligned->len,
0);
- if (r)
+ if (r == ZEBRA_FAIL)
{
rr->errcode = 224;
rr->errstring = "delete_record failed";
-/* $Id: zsets.c,v 1.79 2005-04-14 12:01:22 adam Exp $
+/* $Id: zsets.c,v 1.80 2005-04-15 10:47:49 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
log_level_searchhits = yaz_log_module_level("searchhits");
log_level_searchterms = yaz_log_module_level("searchterms");
log_level_resultsets = yaz_log_module_level("resultsets");
- log_level_set=1;
+ log_level_set = 1;
}
-ZebraSet resultSetAddRPN (ZebraHandle zh, NMEM m,
- Z_RPNQuery *rpn, int num_bases,
- char **basenames,
- const char *setname)
+ZEBRA_RES resultSetSearch(ZebraHandle zh, NMEM nmem, NMEM rset_nmem,
+ Z_RPNQuery *rpn, ZebraSet sset)
+{
+ RSET rset;
+ oident *attrset;
+ Z_SortKeySpecList *sort_sequence;
+ int sort_status, i;
+
+ zh->errCode = 0;
+ zh->errString = NULL;
+ zh->hits = 0;
+
+ sort_sequence = (Z_SortKeySpecList *)
+ nmem_malloc(nmem, sizeof(*sort_sequence));
+ sort_sequence->num_specs = 10; /* FIXME - Hard-coded number */
+ sort_sequence->specs = (Z_SortKeySpec **)
+ nmem_malloc(nmem, sort_sequence->num_specs *
+ sizeof(*sort_sequence->specs));
+ for (i = 0; i<sort_sequence->num_specs; i++)
+ sort_sequence->specs[i] = 0;
+
+ attrset = oid_getentbyoid (rpn->attributeSetId);
+ rset = rpn_search_structure (zh, rpn->RPNStructure, attrset->value,
+ nmem, rset_nmem,
+ sort_sequence,
+ sset->num_bases, sset->basenames);
+ if (!rset)
+ {
+ sset->rset = 0;
+ return ZEBRA_FAIL;
+ }
+
+ if (zh->errCode)
+ yaz_log(YLOG_DEBUG, "search error: %d", zh->errCode);
+
+ for (i = 0; sort_sequence->specs[i]; i++)
+ ;
+ sort_sequence->num_specs = i;
+ if (!i)
+ resultSetRank (zh, sset, rset, rset_nmem);
+ else
+ {
+ yaz_log(YLOG_DEBUG, "resultSetSortSingle in rpn_search");
+ resultSetSortSingle (zh, nmem, sset, rset,
+ sort_sequence, &sort_status);
+ if (zh->errCode)
+ {
+ yaz_log(YLOG_DEBUG, "resultSetSortSingle status = %d", zh->errCode);
+ }
+ }
+ sset->rset = rset;
+ return ZEBRA_OK;
+}
+
+
+ZEBRA_RES resultSetAddRPN (ZebraHandle zh, NMEM m, Z_RPNQuery *rpn,
+ int num_bases, char **basenames,
+ const char *setname)
{
ZebraSet zebraSet;
int i;
+ ZEBRA_RES res;
zh->errCode = 0;
zh->errString = NULL;
zebraSet = resultSetAdd (zh, setname, 1);
if (!zebraSet)
- return 0;
+ return ZEBRA_FAIL;
zebraSet->locked = 1;
zebraSet->rpn = 0;
zebraSet->nmem = m;
- zebraSet->rset_nmem=nmem_create();
+ zebraSet->rset_nmem = nmem_create();
zebraSet->num_bases = num_bases;
zebraSet->basenames =
for (i = 0; i<num_bases; i++)
zebraSet->basenames[i] = nmem_strdup (zebraSet->nmem, basenames[i]);
-
- zebraSet->rset = rpn_search (zh, zebraSet->nmem, zebraSet->rset_nmem,
- rpn, zebraSet->num_bases,
- zebraSet->basenames, zebraSet->name,
- zebraSet);
+ res = resultSetSearch(zh, zebraSet->nmem, zebraSet->rset_nmem,
+ rpn, zebraSet);
zh->hits = zebraSet->hits;
if (zebraSet->rset)
zebraSet->rpn = rpn;
zebraSet->locked = 0;
- return zebraSet;
+ if (!zebraSet->rset)
+ return ZEBRA_FAIL;
+ return res;
}
void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type,
s->term_entries = 0;
s->hits = 0;
s->rset = 0;
- s->rset_nmem=0;
+ s->rset_nmem = 0;
s->nmem = 0;
s->rpn = 0;
s->cache_position = 0;
yaz_log(log_level_resultsets, "research %s", name);
if (!s->rset_nmem)
s->rset_nmem=nmem_create();
- s->rset =
- rpn_search (zh, nmem, s->rset_nmem, s->rpn, s->num_bases,
- s->basenames, s->name, s);
+ resultSetSearch(zh, nmem, s->rset_nmem, s->rpn, s);
nmem_destroy (nmem);
}
return s;
-/* $Id: isamb.c,v 1.76 2005-04-13 13:03:47 adam Exp $
+/* $Id: isamb.c,v 1.77 2005-04-15 10:47:49 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
isamb->skipped_numbers = 0;
isamb->returned_numbers = 0;
for (i = 0; i<ISAMB_MAX_LEVEL; i++)
- isamb->skipped_nodes[i] = isamb->accessed_nodes[i] = 0;
+ isamb->skipped_nodes[i] = isamb->accessed_nodes[i] = 0;
assert(cache == 0);
isamb->file = xmalloc(sizeof(*isamb->file) * isamb->no_cat);
-/* $Id: t3.c,v 1.16 2005-03-09 12:14:42 adam Exp $
+/* $Id: t3.c,v 1.17 2005-04-15 10:47:49 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
for (i = 0; i<4; i++)
{
-#if 0
- ZebraRetrievalRecord retrievalRecord;
-#endif
char setname[20];
char *setnamep = setname;
int status;
zebra_end_trans (zh);
zebra_end_trans (zh);
yaz_pqf_destroy(parser);
-#if 0
- /*FIXME Why is this disabled ??? */
- zebra_records_retrieve(zh, odr_output, setname, 0,
- VAL_TEXT_XML, 1, &retrievalRecord);
-#endif
-#if 1
zebra_deleteResultSet(zh, Z_DeleteRequest_list,
1, &setnamep, &status);
-#endif
odr_destroy(odr_input);
odr_destroy(odr_output);
}
-/* $Id: t5.c,v 1.11 2005-01-15 19:38:35 adam Exp $
+/* $Id: t5.c,v 1.12 2005-04-15 10:47:49 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
init_data(zh, myrec);
- do_query(__LINE__,zh, "@attr 1=4 my", 3);
- do_query(__LINE__,zh, "@attr 1=4 {my x}", 1);
- do_query(__LINE__,zh, "@attr 1=4 {my x}", 1);
- do_query(__LINE__,zh, "@attr 1=4 {x my}", 0);
- do_query(__LINE__,zh, "@attr 1=4 {my x title}", 1);
- do_query(__LINE__,zh, "@attr 1=4 {my title}", 2);
- do_query(__LINE__,zh, "@attr 1=4 @and x title", 2);
+ /* phrase searches */
+ do_query(__LINE__, zh, "@attr 1=4 my", 3);
+ do_query(__LINE__, zh, "@attr 1=4 {my x}", 1);
+ do_query(__LINE__, zh, "@attr 1=4 @attr 4=1 {my x}", 1);
+ do_query(__LINE__, zh, "@attr 1=4 {my x}", 1);
+ do_query(__LINE__, zh, "@attr 1=4 {x my}", 0);
+ do_query(__LINE__, zh, "@attr 1=4 {my x title}", 1);
+ do_query(__LINE__, zh, "@attr 1=4 {my title}", 2);
+
+ /* and-list searches */
+ do_query(__LINE__, zh, "@attr 1=4 @attr 4=6 {x my}", 2);
+ do_query(__LINE__, zh, "@attr 1=4 @attr 4=6 {my x}", 2);
+ do_query(__LINE__, zh, "@attr 1=4 @attr 4=6 {my my}", 3);
+ do_query(__LINE__, zh, "@attr 1=4 @attr 4=6 {e x}", 0);
+
+ /* or-list searches */
+ do_query(__LINE__, zh, "@attr 1=4 @attr 4=105 {x my}", 3);
+ do_query(__LINE__, zh, "@attr 1=4 @attr 4=105 {my x}", 3);
+ do_query(__LINE__, zh, "@attr 1=4 @attr 4=105 {my my}", 3);
+ do_query(__LINE__, zh, "@attr 1=4 @attr 4=105 {e x}", 2);
+ do_query(__LINE__, zh, "@attr 1=4 @attr 4=106 {e x}", 2);
+
+ do_query(__LINE__, zh, "@attr 1=4 @and x title", 2);
/* exl=0 distance=2 order=1 relation=2 (<=), known, unit=word */
- do_query(__LINE__,zh, "@prox 0 2 1 2 k 2 my x", 2);
+ do_query(__LINE__, zh, "@prox 0 2 1 2 k 2 my x", 2);
/* exl=0 distance=2 order=1 relation=2 (<=), known, unit=word */
- do_query(__LINE__,zh, "@prox 0 2 1 2 k 2 x my", 0);
+ do_query(__LINE__, zh, "@prox 0 2 1 2 k 2 x my", 0);
/* exl=0 distance=2 order=0 relation=2 (<=), known, unit=word */
- do_query(__LINE__,zh, "@prox 0 2 0 2 k 2 x my", 2);
+ do_query(__LINE__, zh, "@prox 0 2 0 2 k 2 x my", 2);
/* exl=0 distance=2 order=0 relation=3 (=), known, unit=word */
- do_query(__LINE__,zh, "@prox 0 2 1 3 k 2 my x", 1);
+ do_query(__LINE__, zh, "@prox 0 2 1 3 k 2 my x", 1);
/* exl=1 distance=2 order=0 relation=3 (=), known, unit=word */
- do_query(__LINE__,zh, "@prox 1 2 1 3 k 2 my x", 1);
+ do_query(__LINE__, zh, "@prox 1 2 1 3 k 2 my x", 1);
+
+ /* provoke unsupported use attribute */
+ do_query_x(__LINE__, zh, "@attr 1=999 @attr 4=1 x", 0, 114);
+ do_query_x(__LINE__, zh, "@attr 1=999 @attr 4=6 x", 0, 114);
+ do_query_x(__LINE__, zh, "@attr 1=999 @attr 4=105 x", 0, 114);
+ do_query_x(__LINE__, zh, "@attr 1=999 @attr 4=109 123", 0, 114);
+ do_query_x(__LINE__, zh, "@attrset 1.2.840.10003.3.1 @attr 1=999 x",
+ 0, 114);
+ /* provoke unsupported attribute set */
+ do_query_x(__LINE__, zh, "@attrset 1.2.8 @attr 1=999 @attr 4=1 x", 0, 121);
+ do_query_x(__LINE__, zh, "@attrset 1.2.8 @attr 1=999 @attr 4=6 x", 0,
+ 121);
+ do_query_x(__LINE__, zh, "@attrset 1.2.8 @attr 1=999 @attr 4=105 x", 0,
+ 121);
+ do_query_x(__LINE__, zh, "@attrset 1.2.8 @attr 1=999 @attr 4=109 123",
+ 0, 121);
+ /* provoke unsupported relation */
+ do_query_x(__LINE__, zh, "@attr 1=1016 @attr 2=6 x", 0, 117);
+ do_query_x(__LINE__, zh, "@attr 1=1016 @attr 2=6 @attr 4=109 x", 0, 117);
+
return close_down(zh, zs, 0);
}
-/* $Id: testlib.c,v 1.12 2005-03-09 12:14:42 adam Exp $
+/* $Id: testlib.c,v 1.13 2005-04-15 10:47:49 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
zebra_select_database(zh, "Default");
yaz_log(log_level, "going to call init");
i = zebra_init(zh);
- yaz_log(log_level, "init returned %d",i);
+ yaz_log(log_level, "init returned %d", i);
if (i)
{
printf("init failed with %d\n",i);
zebra_result(zh, &i, &addinfo);
- printf(" Error %d %s\n",i,addinfo);
+ printf(" Error %d %s\n", i, addinfo);
exit(1);
}
if (recs)
{
zebra_begin_trans (zh, 1);
for (i = 0; recs[i]; i++)
- zebra_add_record (zh, recs[i], strlen(recs[i]));
- zebra_end_trans (zh);
- zebra_commit (zh);
+ zebra_add_record(zh, recs[i], strlen(recs[i]));
+ zebra_end_trans(zh);
+ zebra_commit(zh);
}
}
-int do_query(int lineno, ZebraHandle zh, char *query, int exphits)
+int do_query_x(int lineno, ZebraHandle zh, char *query, int exphits,
+ int experror)
{
ODR odr;
YAZ_PQF_Parser parser;
Z_RPNQuery *rpn;
const char *setname="rsetname";
zint hits;
- int rc;
-
+ ZEBRA_RES rc;
- yaz_log(log_level,"======================================");
- yaz_log(log_level,"qry[%d]: %s", lineno, query);
- odr=odr_createmem (ODR_DECODE);
+ yaz_log(log_level, "======================================");
+ yaz_log(log_level, "qry[%d]: %s", lineno, query);
+ odr = odr_createmem (ODR_DECODE);
parser = yaz_pqf_create();
rpn = yaz_pqf_parse(parser, odr, query);
printf("Error: Parse failed \n%s\n",query);
exit(1);
}
- rc = zebra_search_RPN (zh, odr, rpn, setname, &hits);
- if (rc) {
- printf("Error: search returned %d \n%s\n",rc,query);
- exit (1);
+ rc = zebra_search_RPN(zh, odr, rpn, setname, &hits);
+ if (experror)
+ {
+ if (rc != ZEBRA_FAIL)
+ {
+ printf("Error: search returned %d (OK), but error was expected\n"
+ "%s\n", rc, query);
+ exit(1);
+ }
+ int code = zebra_errCode(zh);
+ if (code != experror)
+ {
+ printf("Error: search returned error code %d, but error %d was "
+ "expected\n%s\n",
+ code, experror, query);
+ exit(1);
+ }
}
-
- if (hits != exphits) {
- printf("Error: search returned " ZINT_FORMAT " hits instead of %d\n",
- hits, exphits);
- exit (1);
+ else
+ {
+ if (rc == ZEBRA_FAIL) {
+ printf("Error: search returned %d\n%s\n", rc, query);
+ exit (1);
+ }
+ if (hits != exphits) {
+ printf("Error: search returned " ZINT_FORMAT
+ " hits instead of %d\n%s\n",
+ hits, exphits, query);
+ exit (1);
+ }
}
yaz_pqf_destroy(parser);
odr_destroy (odr);
}
+int do_query(int lineno, ZebraHandle zh, char *query, int exphits)
+{
+ return do_query_x(lineno, zh, query, exphits, 0);
+}
+
+
/**
* makes a query, checks number of hits, and for the first hit, that
* it contains the given string, and that it gets the right score
*/
void ranking_query(int lineno, ZebraHandle zh, char *query,
- int exphits, char *firstrec, int firstscore )
+ int exphits, char *firstrec, int firstscore)
{
ZebraRetrievalRecord retrievalRecord[10];
ODR odr_output = odr_createmem (ODR_ENCODE);
if (!strstr(retrievalRecord[0].buf, firstrec))
{
printf("Error: Got the wrong record first\n");
- printf("Expected '%s' but got \n",firstrec);
- printf("%.*s\n",retrievalRecord[0].len,retrievalRecord[0].buf);
+ printf("Expected '%s' but got \n", firstrec);
+ printf("%.*s\n", retrievalRecord[0].len, retrievalRecord[0].buf);
exit(1);
}
-/* $Id: testlib.h,v 1.10 2005-01-15 19:38:35 adam Exp $
+/* $Id: testlib.h,v 1.11 2005-04-15 10:47:49 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
int do_query(int lineno, ZebraHandle zh, char *query, int exphits);
+/**
+ * do_query does a simple query, and checks that error is what is expected
+ */
+int do_query_x(int lineno, ZebraHandle zh, char *query, int exphits,
+ int experror);
+
/**
* ranking_query makes a query, checks number of hits, and for
* the first hit, that it contains the given string, and that it
-/* $Id: res.c,v 1.40 2005-03-30 09:25:25 adam Exp $
+/* $Id: res.c,v 1.41 2005-04-15 10:47:49 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <unistd.h>
#endif
+#include <yaz/yaz-util.h>
#include <idzebra/res.h>
struct res_entry {