Fixed bug #445: zebra.cfg does not check for valid directives.
[idzebra-moved-to-github.git] / index / zebraapi.c
index 0ff27a1..7b14661 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zebraapi.c,v 1.231 2006-11-14 08:12:08 adam Exp $
+/* $Id: zebraapi.c,v 1.237 2006-12-05 14:06:29 adam Exp $
    Copyright (C) 1995-2006
    Index Data ApS
 
@@ -84,9 +84,10 @@ static ZEBRA_RES zebra_flush_reg (ZebraHandle zh)
     ZEBRA_CHECK_HANDLE(zh);
     yaz_log(log_level, "zebra_flush_reg");
     zebraExplain_flush (zh->reg->zei, zh);
-    
-    extract_flushWriteKeys (zh, 1 /* final */);
-    zebra_index_merge (zh );
+
+    key_block_flush(zh->reg->key_block, 1);
+
+    zebra_index_merge(zh);
     return ZEBRA_OK;
 }
 
@@ -173,12 +174,12 @@ ZebraHandle zebra_open(ZebraService zs, Res res)
     return zh;
 }
 
-ZebraService zebra_start (const char *configName)
+ZebraService zebra_start(const char *configName)
 {
     return zebra_start_res(configName, 0, 0);
 }
 
-ZebraService zebra_start_res (const char *configName, Res def_res, Res over_res)
+ZebraService zebra_start_res(const char *configName, Res def_res, Res over_res)
 {
     Res res;
 
@@ -208,7 +209,18 @@ ZebraService zebra_start_res (const char *configName, Res def_res, Res over_res)
                res_close(res);
                return 0;
            }
+            if (zebra_check_res(res))
+            {
+                yaz_log(YLOG_FATAL, "Configuration error(s) for %s",
+                        configName);
+                return 0;
+            }
        }
+        else
+        {
+            zebra_check_res(res);
+        }
+
        zh = xmalloc(sizeof(*zh));
         zh->global_res = res;
         zh->sessions = 0;
@@ -347,8 +359,7 @@ 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(YLOG_DEBUG, "profilePath=%s cwd=%s", profilePath, cwd);
+    profilePath = res_get_def(res, "profilePath", 0);
 
     data1_set_tabpath (reg->dh, profilePath);
     data1_set_tabroot (reg->dh, reg_path);
@@ -367,8 +378,7 @@ struct zebra_register *zebra_register_open(ZebraService zs, const char *name,
     }
     reg->rank_classes = NULL;
 
-    reg->key_buf = 0;
-
+    reg->key_block = 0;
     reg->keys = zebra_rec_keys_open();
 
     reg->sortKeys = zebra_rec_keys_open();
@@ -381,8 +391,6 @@ struct zebra_register *zebra_register_open(ZebraService zs, const char *name,
     reg->isamc = 0;
     reg->isamb = 0;
     reg->zei = 0;
-    reg->key_file_no = 0;
-    reg->ptr_i = 0;
     
     /* installing rank classes */
     zebraRankInstall (reg, rank_1_class);
@@ -550,7 +558,7 @@ static void zebra_register_close(ZebraService zs, struct zebra_register *reg)
     zebra_rec_keys_close(reg->keys);
     zebra_rec_keys_close(reg->sortKeys);
 
-    xfree(reg->key_buf);
+    key_block_destroy(&reg->key_block);
     xfree(reg->name);
     xfree(reg);
 }
@@ -1065,12 +1073,15 @@ ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream,
            else if (poset[i].sysno)
            {
                char *buf;
-               int len;
+               int len = 0;
                zebra_snippets *hit_snippet = zebra_snippets_create();
 
+                /* we disable hit snippets for now. It does not work well
+                 and it slows retrieval down a lot */
+#if 0
                zebra_snippets_hit_vector(zh, setname, poset[i].sysno, 
                                          hit_snippet);
-
+#endif
                recs[i].errCode =
                    zebra_record_fetch(zh, poset[i].sysno, poset[i].score,
                                       hit_snippet,
@@ -1318,7 +1329,7 @@ ZEBRA_RES zebra_admin_import_end (ZebraHandle zh)
 ZEBRA_RES zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment)
 {
     ZEBRA_RES res = ZEBRA_OK;
-    SYSNO sysno;
+    zint sysno;
     int i;
     ZEBRA_CHECK_HANDLE(zh);
     yaz_log(log_level, "zebra_admin_import_segment");
@@ -1360,7 +1371,7 @@ ZEBRA_RES zebra_admin_exchange_record(ZebraHandle zh,
     /* 4 = update. Insert/replace */
 {
     ZEBRA_RES res;
-    SYSNO sysno = 0;
+    zint sysno = 0;
     char *rinfo = 0;
     char recid_z[256];
     int db_ord;
@@ -2238,7 +2249,7 @@ ZEBRA_RES zebra_add_record(ZebraHandle zh,
 
 ZEBRA_RES zebra_insert_record(ZebraHandle zh, 
                              const char *recordType,
-                             SYSNO *sysno, const char *match,
+                             zint *sysno, const char *match,
                              const char *fname,
                              const char *buf, int buf_size, int force_update)
 {
@@ -2269,12 +2280,12 @@ ZEBRA_RES zebra_insert_record(ZebraHandle 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 zebra_update_record(ZebraHandle zh, 
+                              const char *recordType,
+                              zint *sysno, const char *match,
+                              const char *fname,
+                              const char *buf, int buf_size,
+                              int force_update)
 {
     ZEBRA_RES res;
 
@@ -2306,12 +2317,12 @@ ZEBRA_RES zebra_update_record (ZebraHandle 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 zebra_delete_record(ZebraHandle zh, 
+                              const char *recordType,
+                              zint *sysno, const char *match,
+                              const char *fname,
+                              const char *buf, int buf_size,
+                              int force_update) 
 {
     ZEBRA_RES res;
 
@@ -2468,11 +2479,11 @@ void zebra_setError_zint(ZebraHandle zh, int code, zint i)
     zh->errString = nmem_strdup(zh->nmem_error, vstr);
 }
 
-void zebra_lock_prefix (Res res, char *path)
+void zebra_lock_prefix(Res res, char *path)
 {
     const char *lock_dir = res_get_def (res, "lockDir", "");
-
-    strcpy (path, lock_dir);
+    
+    strcpy(path, lock_dir);
     if (*path && path[strlen(path)-1] != '/')
         strcat (path, "/");
 }