Re-estabslished rank-1. Gets same order of results, but slightly different
[idzebra-moved-to-github.git] / index / zebraapi.c
index 054bc0b..e97e27c 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zebraapi.c,v 1.124 2004-08-10 08:19:15 heikki Exp $
+/* $Id: zebraapi.c,v 1.137 2004-10-26 15:32:11 heikki Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
    Index Data Aps
 
@@ -22,6 +22,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 
 #include <assert.h>
 #include <stdio.h>
+#include <limits.h>
 #ifdef WIN32
 #include <io.h>
 #include <process.h>
@@ -35,20 +36,14 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <yaz/sortspec.h>
 #include "index.h"
 #include <charmap.h>
-#include "zebraapi.h"
+#include <idzebra/api.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)
 
-/* A simple log macro */
-/* don't break with older yazen that lack log_app2 */
-#ifdef LOG_APP2
 #define LOG_API LOG_APP2
-#else
-#define LOG_API LOG_DEBUG
-#endif
 
 static Res zebra_open_res (ZebraHandle zh);
 static void zebra_close_res (ZebraHandle zh);
@@ -92,7 +87,6 @@ ZebraHandle zebra_open (ZebraService zs)
 {
     ZebraHandle zh;
     const char *default_encoding;
-    ASSERTZS;
     yaz_log(LOG_API,"zebra_open");
 
     if (!zs)
@@ -156,7 +150,8 @@ ZebraService zebra_start_res (const char *configName, Res def_res, Res over_res)
 {
     Res res;
 
-    yaz_log(LOG_API|LOG_LOG,"zebra_start %s",configName);
+    yaz_log(LOG_API,"zebra_start %s",configName);
+    assert(configName);
 
     if ((res = res_open (configName, def_res, over_res)))
     {
@@ -183,18 +178,49 @@ ZebraService zebra_start_res (const char *configName, Res def_res, Res over_res)
                                 res_get (zh->global_res, "passwd"));
         }
         zh->path_root = res_get (zh->global_res, "root");
+       zh->nmem = nmem_create();
+       zh->record_classes = recTypeClass_create (zh->global_res, zh->nmem);
         return zh;
     }
     return 0;
 }
 
+void zebra_filter_info(ZebraService zs, void *cd,
+                       void (*cb)(void *cd, const char *name))
+{
+    ASSERTZS;
+    assert(cb);
+    recTypeClass_info(zs->record_classes, cd, cb);
+}
 
 void zebra_pidfname(ZebraService zs, char *path)
 {
+    ASSERTZS;
     zebra_lock_prefix (zs->global_res, path);
     strcat(path, "zebrasrv.pid");
 }
 
+Dict dict_open_res (BFiles bfs, const char *name, int cache, int rw,
+                   int compact_flag, Res res)
+{
+    int page_size = 4096;
+    char resource_str[200];
+    const char *v;
+    sprintf (resource_str, "dict.%.100s.pagesize", name);
+    assert(bfs);
+    assert(name);
+
+    v = res_get(res, resource_str);
+    if (v)
+    {
+       page_size = atoi(v);
+       yaz_log(LOG_LOG, "Using custom dictionary page size %d for %s",
+               page_size, name);
+    }
+    return dict_open(bfs, name, cache, rw, compact_flag, page_size);
+}
+
+
 static
 struct zebra_register *zebra_register_open (ZebraService zs, const char *name,
                                             int rw, int useshadow, Res res,
@@ -218,7 +244,7 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name,
 
     assert (res);
 
-    yaz_log (LOG_LOG|LOG_API, "zebra_register_open rw = %d useshadow=%d p=%p,n=%s,rp=%s",
+    yaz_log (LOG_DEBUG, "zebra_register_open rw=%d useshadow=%d p=%p n=%s rp=%s",
              rw, useshadow, reg, name, reg_path ? reg_path : "(none)");
     
     reg->dh = data1_createx (DATA1_FLAG_XML);
@@ -235,12 +261,11 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name,
 
     getcwd(cwd, sizeof(cwd)-1);
     profilePath = res_get_def(res, "profilePath", DEFAULT_PROFILE_PATH);
-    yaz_log(LOG_LOG, "profilePath=%s cwd=%s", profilePath, cwd);
+    yaz_log(LOG_DEBUG, "profilePath=%s cwd=%s", profilePath, cwd);
 
     data1_set_tabpath (reg->dh, profilePath);
     data1_set_tabroot (reg->dh, reg_path);
-    reg->recTypes = recTypes_init (reg->dh);
-    recTypes_default_handlers (reg->recTypes);
+    reg->recTypes = recTypes_init (zs->record_classes, reg->dh);
 
     reg->zebra_maps = zebra_maps_open (res, reg_path);
     reg->rank_classes = NULL;
@@ -249,9 +274,7 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name,
 
     reg->keys.buf_max = 0;
     reg->keys.buf = 0;
-#if IT_KEY_NEW
     reg->keys.codec_handle = iscz1_start();
-#endif
 
     reg->sortKeys.buf = 0;
     reg->sortKeys.buf_max = 0;
@@ -269,8 +292,10 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name,
     reg->ptr_i=0;
     
     zebraRankInstall (reg, rank1_class);
+#ifdef SKIPTHIS /* FIXME - those ranks not yet converted to new interface */
     zebraRankInstall (reg, rankzv_class);
     zebraRankInstall (reg, rankliv_class);
+#endif
 
     recordCompression = res_get_def (res, "recordCompression", "none");
     if (!strcmp (recordCompression, "none"))
@@ -285,9 +310,9 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name,
     }
     if (rw)
     {
-        reg->matchDict = dict_open (reg->bfs, GMATCH_DICT, 20, 1, 0);
+        reg->matchDict = dict_open_res (reg->bfs, GMATCH_DICT, 20, 1, 0, res);
     }
-    if (!(reg->dict = dict_open (reg->bfs, FNAME_DICT, 40, rw, 0)))
+    if (!(reg->dict = dict_open_res (reg->bfs, FNAME_DICT, 40, rw, 0, res)))
     {
        logf (LOG_WARN, "dict_open");
        return 0;
@@ -390,7 +415,8 @@ int zebra_admin_start (ZebraHandle zh)
 static void zebra_register_close (ZebraService zs, struct zebra_register *reg)
 {
     ASSERTZS;
-    yaz_log(LOG_LOG|LOG_API, "zebra_register_close p=%p", reg);
+    assert(reg);
+    yaz_log(LOG_DEBUG, "zebra_register_close p=%p", reg);
     reg->stop_flag = 0;
     zebra_chdir (zs);
     if (reg->records)
@@ -417,11 +443,8 @@ static void zebra_register_close (ZebraService zs, struct zebra_register *reg)
 
     xfree (reg->sortKeys.buf);
     xfree (reg->keys.buf);
-#if IT_KEY_NEW
     if (reg->keys.codec_handle)
        iscz1_stop(reg->keys.codec_handle);
-#endif
-
     xfree (reg->key_buf);
     xfree (reg->name);
     xfree (reg);
@@ -431,7 +454,7 @@ int zebra_stop(ZebraService zs)
 {
     if (!zs)
         return 0;
-    yaz_log (LOG_LOG|LOG_API, "zebra_stop");
+    yaz_log (LOG_API, "zebra_stop");
 
     while (zs->sessions)
     {
@@ -443,6 +466,8 @@ int zebra_stop(ZebraService zs)
     if (zs->passwd_db)
        passwd_db_close (zs->passwd_db);
 
+    recTypeClass_destroy(zs->record_classes);
+    nmem_destroy(zs->nmem);
     res_close (zs->global_res);
     xfree (zs->configName);
     xfree (zs);
@@ -619,6 +644,10 @@ void map_basenames_func (void *vp, const char *name, const char *value)
     struct map_baseinfo *p = (struct map_baseinfo *) vp;
     int i, no;
     char fromdb[128], todb[8][128];
+
+    assert(value);
+    assert(name);
+    assert(vp);
     
     no =
        sscanf (value, "%127s %127s %127s %127s %127s %127s %127s %127s %127s",
@@ -650,6 +679,8 @@ void map_basenames (ZebraHandle zh, ODR stream,
     int i;
     ASSERTZH;
     yaz_log(LOG_API,"map_basenames ");
+    assert(stream);
+
     zh->errCode=0;
 
     info.zh = zh;
@@ -672,13 +703,14 @@ void map_basenames (ZebraHandle zh, ODR stream,
     *num_bases = info.new_num_bases;
     *basenames = info.new_basenames;
     for (i = 0; i<*num_bases; i++)
-       logf (LOG_LOG, "base %s", (*basenames)[i]);
+       logf (LOG_DEBUG, "base %s", (*basenames)[i]);
 }
 
 int zebra_select_database (ZebraHandle zh, const char *basename)
 {
     ASSERTZH;
     yaz_log(LOG_API,"zebra_select_database %s",basename);
+    assert(basename);
     zh->errCode=0;
     return zebra_select_databases (zh, 1, &basename);
 }
@@ -691,6 +723,8 @@ int zebra_select_databases (ZebraHandle zh, int num_bases,
     int len = 0;
     char *new_reg = 0;
     ASSERTZH;
+    assert(basenames);
+
     yaz_log(LOG_API,"zebra_select_databases n=%d [0]=%s",
                    num_bases,basenames[0]);
     zh->errCode=0;
@@ -765,7 +799,13 @@ int zebra_select_databases (ZebraHandle zh, int num_bases,
 int zebra_search_RPN (ZebraHandle zh, ODR o,
                       Z_RPNQuery *query, const char *setname, int *hits)
 {
+    const char *max;
+    zint maxhits;
     ASSERTZH;
+    assert(o);
+    assert(query);
+    assert(hits);
+    assert(setname);
     yaz_log(LOG_API,"zebra_search_rpn");
     zh->errCode=0;
     zh->hits = 0;
@@ -774,14 +814,29 @@ int zebra_search_RPN (ZebraHandle zh, ODR o,
     if (zebra_begin_read (zh))
        return 1;
 
+#ifdef SKIPTHIS /* FIXME - livcode rank not yet available */
     zebra_livcode_transform(zh, query);
+#endif
 
     resultSetAddRPN (zh, odr_extract_mem(o), query, 
                      zh->num_basenames, zh->basenames, setname);
 
     zebra_end_read (zh);
-
-    *hits = zh->hits;
+    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 */
+        logf(LOG_DEBUG,"limiting hits to "ZINT_FORMAT, maxhits);
+       *hits=maxhits;  
+    }
+    else
+        *hits = zh->hits;
     return 0;
 }
 
@@ -793,6 +848,11 @@ int zebra_records_retrieve (ZebraHandle zh, ODR stream,
     ZebraPosSet poset;
     int i, *pos_array, ret = 0;
     ASSERTZH;
+    assert(stream);
+    assert(setname);
+    assert(recs);
+    assert(num_recs>0);
+
     yaz_log(LOG_API,"zebra_records_retrieve n=%d",num_recs);
     zh->errCode=0;
 
@@ -865,6 +925,12 @@ int zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
                 int *is_partial)
 {
     ASSERTZH;
+    assert(stream);
+    assert(zapt);
+    assert(position);
+    assert(num_entries);
+    assert(is_partial);
+    assert(entries);
     yaz_log(LOG_API,"zebra_scan");
     zh->errCode=0;
     if (zebra_begin_read (zh))
@@ -886,6 +952,11 @@ int zebra_sort (ZebraHandle zh, ODR stream,
                 int *sort_status)
 {
     ASSERTZH;
+    assert(stream);
+    assert(num_input_setnames>0);
+    assert(input_setnames);
+    assert(sort_sequence);
+    assert(sort_status);
     yaz_log(LOG_API,"zebra_sort");
     zh->errCode=0;
     if (zebra_begin_read (zh))
@@ -902,6 +973,9 @@ int zebra_deleleResultSet(ZebraHandle zh, int function,
 {
     int i, status;
     ASSERTZH;
+    assert(num_setnames>0);
+    assert(setnames);
+    assert(statuses);
     yaz_log(LOG_API,"zebra_deleleResultSet n=%d",num_setnames);
     zh->errCode=0;
     if (zebra_begin_read(zh))
@@ -1020,6 +1094,7 @@ int zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment)
        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;
@@ -1058,6 +1133,9 @@ int zebra_admin_exchange_record (ZebraHandle zh,
     char *rinfo = 0;
     char recid_z[256];
     ASSERTZH;
+    assert(action>0 && action <=4);
+    assert(rec_buf);
+
     yaz_log(LOG_API,"zebra_admin_exchange_record ac=%d", action);
     zh->errCode=0;
 
@@ -1115,6 +1193,7 @@ int delete_w_handle(const char *info, void *handle)
 {
     ZebraHandle zh = (ZebraHandle) handle;
     ISAMC_P pos;
+    ASSERTZH;
 
     if (*info == sizeof(pos))
     {
@@ -1169,7 +1248,8 @@ int zebra_drop_database  (ZebraHandle zh, const char *database)
 int zebra_create_database (ZebraHandle zh, const char *database)
 {
     ASSERTZH;
-    yaz_log(LOG_API,"zebra_create_database");
+    yaz_log(LOG_API,"zebra_create_database %s",database);
+    assert(database);
     zh->errCode=0;
 
     if (zebra_select_database (zh, database))
@@ -1196,6 +1276,8 @@ int zebra_string_norm (ZebraHandle zh, unsigned reg_id,
 {
     WRBUF wrbuf;
     ASSERTZH;
+    assert(input_str);
+    assert(output_str);
     yaz_log(LOG_API,"zebra_string_norm ");
     zh->errCode=0;
     if (!zh->reg->zebra_maps)
@@ -1214,6 +1296,7 @@ int zebra_string_norm (ZebraHandle zh, unsigned reg_id,
 
 
 int zebra_set_state (ZebraHandle zh, int val, int seqno)
+    /* FIXME - zint seqno ?? */
 {
     char state_fname[256];
     char *fname;
@@ -1227,7 +1310,7 @@ int zebra_set_state (ZebraHandle zh, int val, int seqno)
     fname = zebra_mk_fname (res_get(zh->res, "lockDir"), state_fname);
     f = fopen (fname, "w");
 
-    yaz_log (LOG_DEBUG, "%c %d %ld", val, seqno, p);
+    yaz_log (LOG_DEBUG, "zebra_set_state: %c %d %ld", val, seqno, p);
     fprintf (f, "%c %d %ld\n", val, seqno, p);
     fclose (f);
     xfree (fname);
@@ -1272,6 +1355,7 @@ static void read_res_for_transaction(ZebraHandle zh)
 {
     const char *group = res_get(zh->res, "group");
     const char *v;
+    /* FIXME - do we still use groups ?? */
     
     zh->m_group = group;
     v = res_get_prefix(zh->res, "followLinks", group, "1");
@@ -1298,6 +1382,7 @@ static void read_res_for_transaction(ZebraHandle zh)
 
 int zebra_begin_trans (ZebraHandle zh, int rw)
 {
+    ASSERTZH;
     if (!zh->res)
     {
         zh->errCode = 2;
@@ -1374,7 +1459,7 @@ int zebra_begin_trans (ZebraHandle zh, int rw)
             zebra_get_state (zh, &val, &seqno);
             if (val == 'c')
             {
-                yaz_log (LOG_LOG, "previous transaction didn't finish commit");
+                yaz_log (LOG_WARN, "previous transaction didn't finish commit");
                 zebra_unlock (zh->lock_shadow);
                 zebra_unlock (zh->lock_normal);
                 zebra_commit (zh);
@@ -1386,7 +1471,7 @@ int zebra_begin_trans (ZebraHandle zh, int rw)
                 {
                     BFiles bfs = bfs_create (res_get (zh->res, "shadow"),
                                              zh->path_reg);
-                    yaz_log (LOG_LOG, "previous transaction didn't reach commit");
+                    yaz_log (LOG_WARN, "previous transaction didn't reach commit");
                     bf_commitClean (bfs, rval);
                     bfs_destroy (bfs);
             }
@@ -1463,13 +1548,13 @@ int zebra_begin_trans (ZebraHandle zh, int rw)
             dirty = 1;
         else if (seqno != zh->reg->seqno)
         {
-            yaz_log (LOG_LOG, "reopen seqno cur/old %d/%d",
+            yaz_log (LOG_DEBUG, "reopen seqno cur/old %d/%d",
                      seqno, zh->reg->seqno);
             dirty = 1;
         }
         else if (zh->reg->last_val != val)
         {
-            yaz_log (LOG_LOG, "reopen last cur/old %d/%d",
+            yaz_log (LOG_DEBUG, "reopen last cur/old %d/%d",
                      val, zh->reg->last_val);
             dirty = 1;
         }
@@ -1506,6 +1591,7 @@ int zebra_begin_trans (ZebraHandle zh, int rw)
 
 int zebra_end_trans (ZebraHandle zh)
 {
+    ASSERTZH;
     ZebraTransactionStatus dummy;
     yaz_log(LOG_API,"zebra_end_trans");
     return zebra_end_transaction(zh, &dummy);
@@ -1518,6 +1604,7 @@ int zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status)
     const char *rval;
 
     ASSERTZH;
+    assert(status);
     yaz_log(LOG_API,"zebra_end_transaction");
 
     status->processed = 0;
@@ -1549,7 +1636,7 @@ int zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status)
         zh->trans_no--;
         zh->trans_w_no = 0;
         
-        yaz_log (LOG_LOG, "zebra_end_trans");
+        yaz_log (LOG_DEBUG, "zebra_end_trans");
         rval = res_get (zh->res, "shadow");
         
         zebraExplain_runNumberIncrement (zh->reg->zei, 1);
@@ -1575,7 +1662,7 @@ int zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status)
         if (val != 'd')
         {
             BFiles bfs = bfs_create (rval, zh->path_reg);
-            yaz_log (LOG_LOG, "deleting shadow stuff val=%c", val);
+            yaz_log (LOG_DEBUG, "deleting shadow val=%c", val);
             bf_commitClean (bfs, rval);
             bfs_destroy (bfs);
         }
@@ -1602,8 +1689,9 @@ int zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status)
 int zebra_repository_update (ZebraHandle zh, const char *path)
 {
     ASSERTZH;
+    assert(path);
     zh->errCode=0;
-    logf (LOG_LOG|LOG_API, "updating %s", path);
+    logf (LOG_API, "updating %s", path);
     repositoryUpdate (zh, path);
     return zh->errCode;
 }
@@ -1611,8 +1699,9 @@ int zebra_repository_update (ZebraHandle zh, const char *path)
 int zebra_repository_delete (ZebraHandle zh, const char *path)
 {
     ASSERTZH;
+    assert(path);
     zh->errCode=0;
-    logf (LOG_LOG|LOG_API, "deleting %s", path);
+    logf (LOG_API, "deleting %s", path);
     repositoryDelete (zh, path);
     return zh->errCode;
 }
@@ -1620,6 +1709,7 @@ int zebra_repository_delete (ZebraHandle zh, const char *path)
 int zebra_repository_show (ZebraHandle zh, const char *path)
 {
     ASSERTZH;
+    assert(path);
     yaz_log(LOG_API,"zebra_repository_show");
     zh->errCode=0;
     repositoryShow (zh, path);
@@ -1665,13 +1755,13 @@ static int zebra_commit_ex (ZebraHandle zh, int clean_only)
         {
             zebra_set_state (zh, 'c', seqno);
             
-            logf (LOG_LOG, "commit start");
+            logf (LOG_DEBUG, "commit start");
             bf_commitExec (bfs);
 #ifndef WIN32
             sync ();
 #endif
         }
-        logf (LOG_LOG, "commit clean");
+        logf (LOG_DEBUG, "commit clean");
         bf_commitClean (bfs, rval);
         seqno++;
         zebra_set_state (zh, 'o', seqno);
@@ -1689,12 +1779,14 @@ static int zebra_commit_ex (ZebraHandle zh, int clean_only)
 
 int zebra_clean (ZebraHandle zh)
 {
+    ASSERTZH;
     yaz_log(LOG_API,"zebra_clean");
     return zebra_commit_ex(zh, 1);
 }
 
 int zebra_commit (ZebraHandle zh)
 {
+    ASSERTZH;
     yaz_log(LOG_API,"zebra_commit");
     return zebra_commit_ex(zh, 0);
 }
@@ -1716,6 +1808,8 @@ int zebra_init (ZebraHandle zh)
 
     bfs = bfs_create (res_get (zh->service->global_res, "register"),
                       zh->path_reg);
+    if (!bfs)
+       return -1;
     if (rval && *rval)
         bf_cache (bfs, rval);
     
@@ -1763,6 +1857,7 @@ int zebra_shadow_enable (ZebraHandle zh, int value)
 int zebra_record_encoding (ZebraHandle zh, const char *encoding)
 {
     ASSERTZH;
+    assert(encoding);
     yaz_log(LOG_API,"zebra_record_encoding");
     zh->errCode=0;
     xfree (zh->record_encoding);
@@ -1796,6 +1891,8 @@ int zebra_record_encoding (ZebraHandle zh, const char *encoding)
 int zebra_set_resource(ZebraHandle zh, const char *name, const char *value)
 {
     ASSERTZH;
+    assert(name);
+    assert(value);
     yaz_log(LOG_API,"zebra_set_resource %s:%s",name,value);
     zh->errCode=0;
     res_set(zh->res, name, value);
@@ -1807,6 +1904,8 @@ const char *zebra_get_resource(ZebraHandle zh,
 {
     const char *v;
     ASSERTZH;
+    assert(name);
+    assert(defaultvalue);
     v= res_get_def( zh->res, name, (char *)defaultvalue);
     zh->errCode=0;
     yaz_log(LOG_API,"zebra_get_resource %s:%s",name,v);
@@ -1825,12 +1924,14 @@ int zebra_trans_no (ZebraHandle zh)
 
 int zebra_get_shadow_enable (ZebraHandle zh)
 {
+    ASSERTZH;
     yaz_log(LOG_API,"zebra_get_shadow_enable");
     return (zh->shadow_enable);
 }
 
 int zebra_set_shadow_enable (ZebraHandle zh, int value)
 {
+    ASSERTZH;
     yaz_log(LOG_API,"zebra_set_shadow_enable %d",value);
     zh->shadow_enable = value;
     return 0;
@@ -1845,6 +1946,12 @@ void api_records_retrieve (ZebraHandle zh, ODR stream,
 {
     ZebraPosSet poset;
     int i, *pos_array;
+    ASSERTZH;
+    assert(stream);
+    assert(setname);
+    assert(comp);
+    assert(recs);
+    assert(num_recs>0);
     yaz_log(LOG_API,"api_records_retrieve s=%s n=%d",setname,num_recs);
 
     if (!zh->res)
@@ -1941,7 +2048,10 @@ int zebra_insert_record (ZebraHandle zh,
                         const char *buf, int buf_size, int force_update)
 {
     int res;
-    yaz_log(LOG_API,"zebra_insert_record sysno=" ZINT_FORMAT, *sysno);
+    ASSERTZH;
+    assert(sysno);
+    assert(buf);
+    yaz_log(LOG_API, "zebra_insert_record sysno=" ZINT_FORMAT, *sysno);
 
     if (buf_size < 1) buf_size = strlen(buf);
 
@@ -1966,8 +2076,11 @@ int zebra_update_record (ZebraHandle zh,
                         int force_update)
 {
     int res;
+    ASSERTZH;
+    assert(sysno);
+    assert(buf);
 
-    yaz_log(LOG_API,"zebra_update_record sysno=" ZINT_FORMAT, *sysno);
+    yaz_log(LOG_API, "zebra_update_record sysno=" ZINT_FORMAT, *sysno);
 
     if (buf_size < 1) buf_size = strlen(buf);
 
@@ -1992,7 +2105,10 @@ int zebra_delete_record (ZebraHandle zh,
                         int force_update) 
 {
     int res;
-    yaz_log(LOG_API,"zebra_delete_record sysno=" ZINT_FORMAT, *sysno);
+    ASSERTZH;
+    assert(sysno);
+    assert(buf);
+    yaz_log(LOG_API, "zebra_delete_record sysno=" ZINT_FORMAT, *sysno);
 
     if (buf_size < 1) buf_size = strlen(buf);
 
@@ -2021,6 +2137,9 @@ int zebra_search_PQF (ZebraHandle zh, const char *pqf_query,
     int res=-1;
     Z_RPNQuery *query;
     ODR odr = odr_createmem(ODR_ENCODE);
+    ASSERTZH;
+    assert(pqf_query);
+    assert(setname);
 
     yaz_log(LOG_API,"zebra_search_PQF s=%s q=%s",setname, pqf_query);
     
@@ -2043,7 +2162,6 @@ int zebra_search_PQF (ZebraHandle zh, const char *pqf_query,
 
 /* ---------------------------------------------------------------------------
   Sort - a simplified interface, with optional read locks.
-  FIXME - This is a horrible name, will conflict with half the applications
 */
 int zebra_sort_by_specstr (ZebraHandle zh, 
                           ODR stream,
@@ -2053,7 +2171,13 @@ int zebra_sort_by_specstr (ZebraHandle zh,
 {
     int num_input_setnames = 0;
     int sort_status = 0;
-    Z_SortKeySpecList *sort_sequence = yaz_sort_spec (stream, sort_spec);
+    Z_SortKeySpecList *sort_sequence;
+    ASSERTZH;
+    assert(stream);
+    assert(sort_spec);
+    assert(output_setname);
+    assert(input_setnames);
+    sort_sequence = yaz_sort_spec (stream, sort_spec);
     yaz_log(LOG_API,"sort (FIXME) ");
     if (!sort_sequence)
     {