+/* Used by Perl API.. Added the record buffer dup to zebra_records_retrieve
+ so that it's identicical to the original api_records_retrieve */
+void api_records_retrieve (ZebraHandle zh, ODR stream,
+ const char *setname, Z_RecordComposition *comp,
+ oid_value input_format, int num_recs,
+ ZebraRetrievalRecord *recs)
+{
+ zebra_records_retrieve(zh, stream, setname, comp, input_format,
+ num_recs, recs);
+}
+
+/* ---------------------------------------------------------------------------
+ Record insert(=update), delete
+
+ If sysno is provided, then it's used to identify the record.
+ If not, and match_criteria is provided, then sysno is guessed
+ If not, and a record is provided, then sysno is got from there
+NOTE: Now returns 0 at success and updates sysno, which is an int*
+ 20-jun-2003 Heikki
+*/
+
+int zebra_add_record(ZebraHandle zh,
+ const char *buf, int buf_size)
+{
+ SYSNO sysno = 0;
+ return zebra_update_record(zh, 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 = buffer_extract_record (zh, buf, buf_size,
+ 0, /* delete_flag */
+ 0, /* test_mode */
+ recordType,
+ sysno,
+ match, fname,
+ 0,
+ 0); /* allow_update */
+ zebra_end_trans(zh);
+ 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;
+ ASSERTZH;
+ assert(sysno);
+ assert(buf);
+
+ yaz_log(log_level, "zebra_update_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 = buffer_extract_record (zh, buf, buf_size,
+ 0, /* delete_flag */
+ 0, /* test_mode */
+ recordType,
+ sysno,
+ match, fname,
+ force_update,
+ 1); /* allow_update */
+ zebra_end_trans(zh);
+ 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;
+ ASSERTZH;
+ assert(sysno);
+ assert(buf);
+ yaz_log(log_level, "zebra_delete_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 = buffer_extract_record (zh, buf, buf_size,
+ 1, /* delete_flag */
+ 0, /* test_mode */
+ recordType,
+ sysno,
+ match,fname,
+ force_update,
+ 1); /* allow_update */
+ zebra_end_trans(zh);
+ return res;
+}
+
+/* ---------------------------------------------------------------------------
+ Searching
+*/
+
+ZEBRA_RES zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
+ const char *setname, zint *numhits)
+{
+ zint hits = 0;
+ ZEBRA_RES res = ZEBRA_OK;
+ Z_RPNQuery *query;
+ ODR odr = odr_createmem(ODR_ENCODE);
+ ASSERTZH;
+ 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, &hits);
+
+ odr_destroy(odr);
+
+ yaz_log(log_level, "Hits: " ZINT_FORMAT, hits);
+
+ if (numhits)
+ *numhits = hits;
+
+ 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)