+ZEBRA_RES zebra_add_record(ZebraHandle zh,
+ const char *buf, int buf_size)
+{
+ return zebra_update_record(zh, 0, 0 /* sysno */, 0, 0, buf, buf_size, 0);
+}
+
+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)
+{
+ ZEBRA_RES res;
+ ASSERTZH;
+ assert(sysno);
+ assert(buf);
+ yaz_log(log_level, "zebra_insert_record sysno=" ZINT_FORMAT, *sysno);
+
+ if (buf_size < 1)
+ buf_size = strlen(buf);
+
+ if (zebra_begin_trans(zh, 1) == ZEBRA_FAIL)
+ return ZEBRA_FAIL;
+ res = zebra_buffer_extract_record(zh, buf, buf_size,
+ 0, /* delete_flag */
+ 0, /* test_mode */
+ recordType,
+ sysno,
+ match, fname,
+ 0,
+ 0); /* allow_update */
+ if (zebra_end_trans(zh) != ZEBRA_OK)
+ {
+ yaz_log(YLOG_WARN, "zebra_end_trans failed");
+ res = ZEBRA_FAIL;
+ }
+ return res;
+}
+
+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)
+{
+ ZEBRA_RES res;
+
+ ZEBRA_CHECK_HANDLE(zh);
+
+ assert(buf);
+
+ yaz_log(log_level, "zebra_update_record");
+ if (sysno)
+ yaz_log(log_level, " sysno=" ZINT_FORMAT, *sysno);
+
+ if (buf_size < 1) buf_size = strlen(buf);
+
+ if (zebra_begin_trans(zh, 1) == ZEBRA_FAIL)
+ return ZEBRA_FAIL;
+ res = zebra_buffer_extract_record(zh, buf, buf_size,
+ 0, /* delete_flag */
+ 0, /* test_mode */
+ recordType,
+ sysno,
+ match, fname,
+ force_update,
+ 1); /* allow_update */
+ if (zebra_end_trans(zh) != ZEBRA_OK)
+ {
+ yaz_log(YLOG_WARN, "zebra_end_trans failed");
+ res = ZEBRA_FAIL;
+ }
+ return res;
+}
+
+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)
+{
+ ZEBRA_RES res;
+
+ ZEBRA_CHECK_HANDLE(zh);
+
+ assert(buf);
+ yaz_log(log_level, "zebra_delete_record");
+ if (sysno)
+ yaz_log(log_level, " sysno=" ZINT_FORMAT, *sysno);
+
+ if (buf_size < 1) buf_size = strlen(buf);
+
+ if (zebra_begin_trans(zh, 1) == ZEBRA_FAIL)
+ return ZEBRA_FAIL;
+ res = zebra_buffer_extract_record(zh, buf, buf_size,
+ 1, /* delete_flag */
+ 0, /* test_mode */
+ recordType,
+ sysno,
+ match,fname,
+ force_update,
+ 1); /* allow_update */
+ if (zebra_end_trans(zh) != ZEBRA_OK)
+ {
+ yaz_log(YLOG_WARN, "zebra_end_trans failed");
+ res = ZEBRA_FAIL;
+ }
+ return res;
+}
+
+/* ---------------------------------------------------------------------------
+ Searching
+*/
+
+ZEBRA_RES zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
+ const char *setname, zint *hits)
+{
+ zint lhits = 0;
+ ZEBRA_RES res = ZEBRA_OK;
+ Z_RPNQuery *query;
+ ODR odr;
+
+ ZEBRA_CHECK_HANDLE(zh);
+
+ odr = odr_createmem(ODR_ENCODE);
+
+ assert(pqf_query);
+ assert(setname);
+
+ yaz_log(log_level, "zebra_search_PQF s=%s q=%s", setname, pqf_query);
+
+ query = p_query_rpn (odr, PROTO_Z3950, pqf_query);
+
+ if (!query)
+ {
+ yaz_log (YLOG_WARN, "bad query %s\n", pqf_query);
+ zh->errCode = YAZ_BIB1_MALFORMED_QUERY;
+ res = ZEBRA_FAIL;
+ }
+ else
+ res = zebra_search_RPN(zh, odr, query, setname, &lhits);
+
+ odr_destroy(odr);
+
+ yaz_log(log_level, "Hits: " ZINT_FORMAT, lhits);
+
+ if (hits)
+ *hits = lhits;
+
+ return res;
+}
+
+/* ---------------------------------------------------------------------------
+ Sort - a simplified interface, with optional read locks.
+*/
+int zebra_sort_by_specstr (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;
+
+ ZEBRA_CHECK_HANDLE(zh);
+ assert(stream);
+ assert(sort_spec);
+ assert(output_setname);
+ assert(input_setnames);
+ sort_sequence = yaz_sort_spec (stream, sort_spec);
+ yaz_log(log_level, "sort (FIXME) ");
+ if (!sort_sequence)
+ {
+ yaz_log(YLOG_WARN, "invalid sort specs '%s'", sort_spec);
+ zh->errCode = YAZ_BIB1_CANNOT_SORT_ACCORDING_TO_SEQUENCE;
+ 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 -1;
+
+ resultSetSort (zh, stream->mem, num_input_setnames, input_setnames,
+ output_setname, sort_sequence, &sort_status);
+
+ zebra_end_read(zh);
+ return sort_status;
+}
+
+/* ---------------------------------------------------------------------------
+ Get BFS for Zebra system (to make alternative storage methods)
+*/
+struct BFiles_struct *zebra_get_bfs(ZebraHandle zh)
+{
+ if (zh && zh->reg)
+ return zh->reg->bfs;
+ return 0;
+}
+
+
+/* ---------------------------------------------------------------------------
+ Set limit for search/scan
+*/
+ZEBRA_RES zebra_set_limit(ZebraHandle zh, int complement_flag, zint *ids)
+{
+ ZEBRA_CHECK_HANDLE(zh);
+ zebra_limit_destroy(zh->m_limit);
+ zh->m_limit = zebra_limit_create(complement_flag, ids);
+ return ZEBRA_OK;
+}
+
+/*
+ Set Error code + addinfo
+*/
+void zebra_setError(ZebraHandle zh, int code, const char *addinfo)
+{
+ if (!zh)
+ return;
+ zh->errCode = code;
+ nmem_reset(zh->nmem_error);
+ zh->errString = addinfo ? nmem_strdup(zh->nmem_error, addinfo) : 0;
+}
+
+void zebra_setError_zint(ZebraHandle zh, int code, zint i)
+{
+ char vstr[60];
+ sprintf(vstr, ZINT_FORMAT, i);
+
+ zh->errCode = code;
+ nmem_reset(zh->nmem_error);
+ zh->errString = nmem_strdup(zh->nmem_error, vstr);
+}
+
+void zebra_lock_prefix (Res res, char *path)
+{
+ const char *lock_dir = res_get_def (res, "lockDir", "");
+
+ strcpy (path, lock_dir);
+ if (*path && path[strlen(path)-1] != '/')
+ strcat (path, "/");
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+