Using oid_ent_to_oid used instead of the non thread-safe oid_getoidbyent.
[idzebra-moved-to-github.git] / index / trunc.c
index 9ef5ed8..5acc72d 100644 (file)
@@ -1,10 +1,27 @@
 /*
- * Copyright (C) 1994-1996, Index Data I/S 
+ * Copyright (C) 1994-1997, Index Data I/S 
  * All rights reserved.
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: trunc.c,v $
- * Revision 1.2  1996-11-08 11:10:28  adam
+ * Revision 1.7  1997-09-29 09:07:29  adam
+ * Minor change.
+ *
+ * Revision 1.6  1997/09/22 12:39:06  adam
+ * Added get_pos method for the ranked result sets.
+ *
+ * Revision 1.5  1997/09/17 12:19:17  adam
+ * Zebra version corresponds to YAZ version 1.4.
+ * Changed Zebra server so that it doesn't depend on global common_resource.
+ *
+ * Revision 1.4  1996/12/23 15:30:44  adam
+ * Work on truncation.
+ * Bug fix: result sets weren't deleted after server shut down.
+ *
+ * Revision 1.3  1996/12/20 11:07:14  adam
+ * Multi-or result set.
+ *
+ * Revision 1.2  1996/11/08 11:10:28  adam
  * Buffers used during file match got bigger.
  * Compressed ISAM support everywhere.
  * Bug fixes regarding masking characters in queries.
 #include <rsisamc.h>
 #include <rsnull.h>
 
+#define NEW_TRUNC 1
+
+#if NEW_TRUNC
+#include <rsm_or.h>
+#endif
+
 struct trunc_info {
     int  *ptr;
     int  *indx;
@@ -83,9 +106,9 @@ static void heap_insert (struct trunc_info *ti, const char *buf, int indx)
     }
 }
 
-static
-struct trunc_info *heap_init (int size, int key_size,
-                              int (*cmp)(const void *p1, const void *p2))
+static struct trunc_info *heap_init (int size, int key_size,
+                                    int (*cmp)(const void *p1,
+                                               const void *p2))
 {
     struct trunc_info *ti = xmalloc (sizeof(*ti));
     int i;
@@ -126,6 +149,7 @@ static RSET rset_trunc_r (ZServerInfo *zi, ISAM_P *isam_p, int from, int to,
     rset_temp_parms parms;
 
     parms.key_size = sizeof(struct it_key);
+    parms.temp_path = res_get (zi->res, "setTmpDir");
     result = rset_create (rset_kind_temp, &parms);
     result_rsfd = rset_open (result, RSETF_WRITE|RSETF_SORT_SYSNO);
 
@@ -151,7 +175,7 @@ static RSET rset_trunc_r (ZServerInfo *zi, ISAM_P *isam_p, int from, int to,
                                             merge_chunk);
             rscur++;
         }
-        ti = heap_init (rscur, sizeof(struct it_key), key_compare);
+        ti = heap_init (rscur, sizeof(struct it_key), key_compare_it);
         for (i = rscur; --i >= 0; )
         {
             rsfd[i] = rset_open (rset[i], RSETF_READ|RSETF_SORT_SYSNO);
@@ -199,7 +223,7 @@ static RSET rset_trunc_r (ZServerInfo *zi, ISAM_P *isam_p, int from, int to,
         ispt = xmalloc (sizeof(*ispt) * (to-from));
 
         ti = heap_init (to-from, sizeof(struct it_key),
-                        key_compare);
+                        key_compare_it);
         for (i = to-from; --i >= 0; )
         {
             ispt[i] = is_position (zi->isam, isam_p[from+i]);
@@ -251,7 +275,7 @@ static RSET rset_trunc_r (ZServerInfo *zi, ISAM_P *isam_p, int from, int to,
         ispt = xmalloc (sizeof(*ispt) * (to-from));
 
         ti = heap_init (to-from, sizeof(struct it_key),
-                        key_compare);
+                        key_compare_it);
         for (i = to-from; --i >= 0; )
         {
             ispt[i] = isc_pp_open (zi->isamc, isam_p[from+i]);
@@ -324,6 +348,7 @@ static int isamc_trunc_cmp (const void *p1, const void *p2)
 
 RSET rset_trunc (ZServerInfo *zi, ISAM_P *isam_p, int no)
 {
+    logf (LOG_DEBUG, "rset_trunc no=%d", no);
     if (zi->isam)
     {
         if (no < 1)
@@ -350,6 +375,21 @@ RSET rset_trunc (ZServerInfo *zi, ISAM_P *isam_p, int no)
             parms.is = zi->isamc;
             return rset_create (rset_kind_isamc, &parms);
         }
+#if NEW_TRUNC
+        else if (no < 200)
+        {
+            rset_m_or_parms parms;
+
+            logf (LOG_LOG, "new_trunc");
+            parms.key_size = sizeof(struct it_key);
+            parms.cmp = key_compare_it;
+            parms.isc = zi->isamc;
+            parms.isam_positions = isam_p;
+            parms.no_isam_positions = no;
+            parms.no_save_positions = 100;
+            return rset_create (rset_kind_m_or, &parms);
+        }
+#endif
         qsort (isam_p, no, sizeof(*isam_p), isamc_trunc_cmp);
     }
     else