No more experiments with combined sh libs
[idzebra-moved-to-github.git] / index / zinfo.c
index 7a7e097..2235089 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zinfo.c,v 1.56 2006-03-26 14:17:01 adam Exp $
+/* $Id: zinfo.c,v 1.59 2006-05-10 09:08:55 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -1421,29 +1421,52 @@ int zebraExplain_lookup_attr_su_any_index(ZebraExplainInfo zei,
 int zebraExplain_lookup_attr_su(ZebraExplainInfo zei, int index_type,
                                int set, int use)
 {
-    struct zebSUInfoB *zsui;
+    struct zebSUInfoB **zsui;
 
+#if 0
+    yaz_log(YLOG_LOG, "lookup_attr_su index_type=%d set=%d use=%d",
+            index_type, set, use);
+#endif
     assert (zei->curDatabaseInfo);
-    for (zsui = zei->curDatabaseInfo->attributeDetails->SUInfo;
-        zsui; zsui=zsui->next)
-        if (zsui->info.index_type == index_type &&
-           zsui->info.which == ZEB_SU_SET_USE &&
-           zsui->info.u.su.use == use && zsui->info.u.su.set == set)
-            return zsui->info.ordinal;
+    for (zsui = &zei->curDatabaseInfo->attributeDetails->SUInfo;
+        *zsui; zsui = &(*zsui)->next)
+        if ((*zsui)->info.index_type == index_type &&
+           (*zsui)->info.which == ZEB_SU_SET_USE &&
+           (*zsui)->info.u.su.use == use && (*zsui)->info.u.su.set == set)
+        {
+            struct zebSUInfoB *zsui_this = *zsui;
+
+            /* take it out of the list and move to front */
+            *zsui = (*zsui)->next;
+            zsui_this->next = zei->curDatabaseInfo->attributeDetails->SUInfo;
+            zei->curDatabaseInfo->attributeDetails->SUInfo = zsui_this;
+
+            return zsui_this->info.ordinal;
+        }
     return -1;
 }
 
 int zebraExplain_lookup_attr_str(ZebraExplainInfo zei, int index_type,
                                 const char *str)
 {
-    struct zebSUInfoB *zsui;
+    struct zebSUInfoB **zsui;
 
     assert (zei->curDatabaseInfo);
-    for (zsui = zei->curDatabaseInfo->attributeDetails->SUInfo;
-        zsui; zsui=zsui->next)
-        if (zsui->info.index_type == index_type &&
-           zsui->info.which == ZEB_SU_STR && !strcmp(zsui->info.u.str, str))
-            return zsui->info.ordinal;
+    for (zsui = &zei->curDatabaseInfo->attributeDetails->SUInfo;
+        *zsui; zsui = &(*zsui)->next)
+        if ((*zsui)->info.index_type == index_type
+            && (*zsui)->info.which == ZEB_SU_STR 
+            && !strcmp((*zsui)->info.u.str, str))
+        {
+            struct zebSUInfoB *zsui_this = *zsui;
+
+            /* take it out of the list and move to front */
+            *zsui = (*zsui)->next;
+            zsui_this->next = zei->curDatabaseInfo->attributeDetails->SUInfo;
+            zei->curDatabaseInfo->attributeDetails->SUInfo = zsui_this;
+
+            return zsui_this->info.ordinal;
+        }
     return -1;
 }
 
@@ -1463,9 +1486,20 @@ int zebraExplain_trav_ord(ZebraExplainInfo zei, void *handle,
 int zebraExplain_lookup_ord (ZebraExplainInfo zei, int ord,
                             int *index_type, 
                             const char **db,
-                            int *set, int *use)
+                            int *set, int *use,
+                            const char **string_index)
 {
     struct zebDatabaseInfoB *zdb;
+
+    if (set)
+       *set = -1;
+    if (use)
+       *use = -1;
+    if (index_type)
+       *index_type = 0;
+    if (string_index)
+       *string_index = 0;
+
     for (zdb = zei->databaseInfo; zdb; zdb = zdb->next)
     {
        struct zebSUInfoB *zsui;
@@ -1485,6 +1519,11 @@ int zebraExplain_lookup_ord (ZebraExplainInfo zei, int ord,
                    if (use)
                        *use = zsui->info.u.su.use;
                }
+
+               if (zsui->info.which == ZEB_SU_STR)
+                   if (string_index)
+                       *string_index = zsui->info.u.str;
+
                if (index_type)
                    *index_type = zsui->info.index_type;
                return 0;
@@ -1651,3 +1690,11 @@ void zebraExplain_loadAttsets (data1_handle dh, Res res)
      If the database doesn't exist globally (in TargetInfo) an 
      AttributeSetInfo must be added (globally).
  */
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+