Furhter code reductions because of string attributes
[idzebra-moved-to-github.git] / index / zsets.c
index 2c543df..5dd1eef 100644 (file)
@@ -1,5 +1,5 @@
-/* $Id: zsets.c,v 1.98 2006-01-19 13:31:08 adam Exp $
-   Copyright (C) 1995-2005
+/* $Id: zsets.c,v 1.104 2006-05-19 23:20:24 adam Exp $
+   Copyright (C) 1995-2006
    Index Data ApS
 
 This file is part of the Zebra server.
@@ -30,6 +30,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #endif
 
 #include "index.h"
+#include "rank.h"
 #include <yaz/diagbib1.h>
 #include <rset.h>
 
@@ -39,8 +40,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 struct zebra_set_term_entry {
     int reg_type;
     char *db;
-    int set;
-    int use;
+    char *index_name;
     char *term;
 };
 
@@ -180,9 +180,9 @@ ZEBRA_RES resultSetAddRPN (ZebraHandle zh, NMEM m, Z_RPNQuery *rpn,
     return res;
 }
 
-void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type,
-                       const char *db, int set,
-                       int use, const char *term)
+void resultSetAddTerm(ZebraHandle zh, ZebraSet s, int reg_type,
+                      const char *db, const char *index_name, 
+                      const char *term)
 {
     assert(zh); /* compiler shut up */
     if (!s->nmem)
@@ -201,9 +201,8 @@ void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type,
     {
         s->term_entries[s->hits].reg_type = reg_type;
         s->term_entries[s->hits].db = nmem_strdup (s->nmem, db);
-        s->term_entries[s->hits].set = set;
-        s->term_entries[s->hits].use = use;
-        s->term_entries[s->hits].term = nmem_strdup (s->nmem, term);
+        s->term_entries[s->hits].index_name = nmem_strdup(s->nmem, index_name);
+        s->term_entries[s->hits].term = nmem_strdup(s->nmem, term);
     }
     (s->hits)++;
 }
@@ -268,6 +267,7 @@ ZebraSet resultSetAdd(ZebraHandle zh, const char *name, int ov)
     s->rset_nmem = 0;
     s->nmem = 0;
     s->rpn = 0;
+    s->sortSpec = 0;
     s->cache_position = 0;
     s->cache_rfd = 0;
     s->approx_limit = zh->approx_limit;
@@ -536,7 +536,11 @@ void zebra_meta_records_destroy (ZebraHandle zh, ZebraMetaRecord *records,
 
 struct sortKeyInfo {
     int relation;
+#if 0
     int attrUse;
+#else
+    int ord;
+#endif
     int numerical;
 };
 
@@ -552,7 +556,7 @@ void resultSetInsertSort (ZebraHandle zh, ZebraSet sset,
     sortIdx_sysno (zh->reg->sortIdx, sysno);
     for (i = 0; i<num_criteria; i++)
     {
-        sortIdx_type (zh->reg->sortIdx, criteria[i].attrUse);
+        sortIdx_type (zh->reg->sortIdx, criteria[i].ord);
         sortIdx_read (zh->reg->sortIdx, this_entry.buf[i]);
     }
     i = sort_info->num_entries;
@@ -796,7 +800,6 @@ ZEBRA_RES resultSetSortSingle(ZebraHandle zh, NMEM nmem,
     if (zh->m_staticrank)
        sysno_mem_index = 1;
 
-
     assert(nmem); /* compiler shut up about unused param */
     sset->sort_info->num_entries = 0;
 
@@ -838,8 +841,17 @@ ZEBRA_RES resultSetSortSingle(ZebraHandle zh, NMEM nmem,
         case Z_SortKey_sortField:
             yaz_log(log_level_sort, "key %d is of type sortField",
                    i+1);
-            zebra_setError(zh, YAZ_BIB1_CANNOT_SORT_ACCORDING_TO_SEQUENCE, 0);
-            return ZEBRA_FAIL;
+            sort_criteria[i].numerical = 0;
+            sort_criteria[i].ord = 
+                zebraExplain_lookup_attr_str(zh->reg->zei, 's',
+                                             sk->u.sortField);
+            if (sort_criteria[i].ord == -1)
+            {
+                zebra_setError(zh,
+                               YAZ_BIB1_CANNOT_SORT_ACCORDING_TO_SEQUENCE, 0);
+                return ZEBRA_FAIL;
+            }
+            break;
         case Z_SortKey_elementSpec:
             yaz_log(log_level_sort, "key %d is of type elementSpec",
                    i+1);
@@ -847,23 +859,11 @@ ZEBRA_RES resultSetSortSingle(ZebraHandle zh, NMEM nmem,
             return ZEBRA_FAIL;
         case Z_SortKey_sortAttributes:
             yaz_log(log_level_sort, "key %d is of type sortAttributes", i+1);
-            sort_criteria[i].attrUse =
-                zebra_maps_sort (zh->reg->zebra_maps,
-                                 sk->u.sortAttributes,
-                                 &sort_criteria[i].numerical);
-            yaz_log(log_level_sort, "use value = %d", sort_criteria[i].attrUse);
-            if (sort_criteria[i].attrUse == -1)
-            {
-               zebra_setError(
-                   zh, YAZ_BIB1_USE_ATTRIBUTE_REQUIRED_BUT_NOT_SUPPLIED, 0); 
-                return ZEBRA_FAIL;
-            }
-            if (sortIdx_type (zh->reg->sortIdx, sort_criteria[i].attrUse))
-            {
-               zebra_setError(
-                   zh, YAZ_BIB1_CANNOT_SORT_ACCORDING_TO_SEQUENCE, 0);
+            if (zebra_sort_get_ord(zh, sk->u.sortAttributes,
+                                   &sort_criteria[i].ord,
+                                   &sort_criteria[i].numerical)
+                != ZEBRA_OK)
                 return ZEBRA_FAIL;
-            }
             break;
         }
     }
@@ -1200,3 +1200,11 @@ ZEBRA_RES zebra_snippets_hit_vector(ZebraHandle zh, const char *setname,
     return ZEBRA_OK;
 }
 
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+