The zebramaps implements index_types functionality.
[idzebra-moved-to-github.git] / index / zebraapi.c
index a1bb61d..676846f 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zebraapi.c,v 1.252 2007-03-19 21:50:39 adam Exp $
+/* $Id: zebraapi.c,v 1.264 2007-11-06 10:29:59 adam Exp $
    Copyright (C) 1995-2007
    Index Data ApS
 
@@ -40,6 +40,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include "orddict.h"
 #include <charmap.h>
 #include <idzebra/api.h>
+#include <yaz/oid_db.h>
 
 #define DEFAULT_APPROX_LIMIT 2000000000
 
@@ -98,6 +99,12 @@ static struct zebra_register *zebra_register_open(ZebraService zs,
                                                  const char *reg_path);
 static void zebra_register_close(ZebraService zs, struct zebra_register *reg);
 
+const char *zebra_get_encoding(ZebraHandle zh)
+{
+    assert(zh && zh->session_res);
+    return res_get_def(zh->session_res, "encoding", "ISO-8859-1");
+}
+
 ZebraHandle zebra_open(ZebraService zs, Res res)
 {
     ZebraHandle zh;
@@ -146,7 +153,7 @@ ZebraHandle zebra_open(ZebraService zs, Res res)
     zh->break_handler_func = 0;
     zh->break_handler_data = 0;
 
-    default_encoding = res_get_def(zh->session_res, "encoding", "ISO-8859-1");
+    default_encoding = zebra_get_encoding(zh);
 
     zh->iconv_to_utf8 =
         yaz_iconv_open ("UTF-8", default_encoding);
@@ -185,6 +192,8 @@ ZebraService zebra_start(const char *configName)
 ZebraService zebra_start_res(const char *configName, Res def_res, Res over_res)
 {
     Res res;
+    char version_str[16];
+    char system_str[80];
 
     zebra_flock_init();
 
@@ -194,7 +203,9 @@ ZebraService zebra_start_res(const char *configName, Res def_res, Res over_res)
         log_level_initialized = 1;
     }
     
-    yaz_log(YLOG_LOG, "zebra_start %s %s", ZEBRAVER,
+    zebra_get_version(version_str, system_str);
+
+    yaz_log(YLOG_LOG, "zebra_start %s %s", version_str,
            configName ? configName : "");
 
     if ((res = res_open(def_res, over_res)))
@@ -408,7 +419,6 @@ struct zebra_register *zebra_register_open(ZebraService zs, const char *name,
     if (!strcmp (recordCompression, "bzip2"))
        record_compression = REC_COMPRESS_BZIP2;
 
-    if (1)
     {
        const char *index_fname = res_get_def(res, "index", "default.idx");
        if (index_fname && *index_fname)
@@ -1075,7 +1085,7 @@ ZEBRA_RES zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
 ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream,
                                 const char *setname,
                                 Z_RecordComposition *comp,
-                                oid_value input_format, int num_recs,
+                                const Odr_oid *input_format, int num_recs,
                                 ZebraRetrievalRecord *recs)
 {
     ZebraMetaRecord *poset;
@@ -1119,7 +1129,7 @@ ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream,
            if (poset[i].term)
            {
                recs[i].errCode = 0;
-               recs[i].format = VAL_SUTRS;
+               recs[i].format = yaz_oid_recsyn_sutrs;
                recs[i].len = strlen(poset[i].term);
                recs[i].buf = poset[i].term;
                recs[i].base = poset[i].db;
@@ -1137,7 +1147,8 @@ ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream,
                                          hit_snippet);
 #endif
                recs[i].errCode =
-                   zebra_record_fetch(zh, poset[i].sysno, poset[i].score,
+                   zebra_record_fetch(zh, setname,
+                                       poset[i].sysno, poset[i].score,
                                       hit_snippet,
                                       stream, input_format, comp,
                                       &recs[i].format, &buf, &len,
@@ -1169,7 +1180,7 @@ ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream,
                recs[i].buf = 0;  /* no record and no error issued */
                recs[i].len = 0;
                recs[i].errCode = 0;
-               recs[i].format = VAL_NONE;
+               recs[i].format = 0;
                recs[i].sysno = 0;
            }
        }
@@ -1188,7 +1199,7 @@ ZEBRA_RES zebra_scan_PQF(ZebraHandle zh, ODR stream, const char *query,
 {
     YAZ_PQF_Parser pqf_parser = yaz_pqf_create ();
     Z_AttributesPlusTerm *zapt;
-    int *attributeSet;
+    Odr_oid *attributeSet;
     ZEBRA_RES res;
     
     if (!(zapt = yaz_pqf_scan(pqf_parser, stream, &attributeSet, query)))
@@ -1197,22 +1208,23 @@ ZEBRA_RES zebra_scan_PQF(ZebraHandle zh, ODR stream, const char *query,
        zh->errCode = YAZ_BIB1_SCAN_MALFORMED_SCAN;
     }
     else
-       res = zebra_scan(zh, stream, zapt, VAL_BIB1,
+    {
+       res = zebra_scan(zh, stream, zapt, yaz_oid_attset_bib_1,
                         position, num_entries, entries, is_partial,
                         setname);
+    }
     yaz_pqf_destroy (pqf_parser);
     return res;
 }
 
 ZEBRA_RES zebra_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
-                    oid_value attributeset,
+                    const Odr_oid *attributeset,
                     int *position,
                     int *num_entries, ZebraScanEntry **entries,
                     int *is_partial,
                     const char *setname)
 {
     ZEBRA_RES res;
-    RSET limit_rset = 0;
 
     ZEBRA_CHECK_HANDLE(zh);
 
@@ -1230,21 +1242,10 @@ ZEBRA_RES zebra_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
        *num_entries = 0;
        return ZEBRA_FAIL;
     }
-    if (setname)
-    {
-       limit_rset = resultSetRef(zh, setname);
-       if (!limit_rset)
-       {
-           zebra_setError(zh, 
-                          YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
-                          setname);
-           zebra_end_read (zh);
-           return ZEBRA_FAIL;
-       }
-    }
+
     res = rpn_scan(zh, stream, zapt, attributeset,
                    zh->num_basenames, zh->basenames, position,
-                   num_entries, entries, is_partial, limit_rset);
+                   num_entries, entries, is_partial, setname);
     zebra_end_read(zh);
     return res;
 }
@@ -1278,8 +1279,7 @@ int zebra_deleteResultSet(ZebraHandle zh, int function,
 {
     int i, status;
     ASSERTZH;
-    assert(statuses);
-    yaz_log(log_level, "zebra_deleteResultSet n=%d",num_setnames);
+    yaz_log(log_level, "zebra_deleteResultSet n=%d", num_setnames);
 
     if (zebra_begin_read(zh))
        return Z_DeleteStatus_systemProblemAtTarget;
@@ -1513,11 +1513,12 @@ ZEBRA_RES zebra_create_database (ZebraHandle zh, const char *db)
     return zebra_end_trans (zh);
 }
 
-int zebra_string_norm(ZebraHandle zh, unsigned reg_id,
+int zebra_string_norm(ZebraHandle zh, const char *index_type,
                      const char *input_str, int input_len,
                      char *output_str, int output_len)
 {
     WRBUF wrbuf;
+    zebra_map_t zm = zebra_map_get(zh->reg->zebra_maps, index_type);
     ASSERTZH;
     assert(input_str);
     assert(output_str);
@@ -1525,8 +1526,7 @@ int zebra_string_norm(ZebraHandle zh, unsigned reg_id,
 
     if (!zh->reg->zebra_maps)
        return -1;
-    wrbuf = zebra_replace(zh->reg->zebra_maps, reg_id, "",
-                         input_str, input_len);
+    wrbuf = zebra_replace(zm, "", input_str, input_len);
     if (!wrbuf)
        return -2;
     if (wrbuf_len(wrbuf) >= output_len)
@@ -2280,7 +2280,7 @@ ZEBRA_RES zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
 
     yaz_log(log_level, "zebra_search_PQF s=%s q=%s", setname, pqf_query);
     
-    query = p_query_rpn (odr, PROTO_Z3950, pqf_query);
+    query = p_query_rpn(odr, pqf_query);
     
     if (!query)
     {