Windows NT port.
[idzebra-moved-to-github.git] / index / zsets.c
index 75d5c6c..b43ea18 100644 (file)
@@ -4,7 +4,27 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: zsets.c,v $
- * Revision 1.6  1995-09-28 09:19:49  adam
+ * Revision 1.12  1997-09-25 14:57:36  adam
+ * Windows NT port.
+ *
+ * Revision 1.11  1996/12/23 15:30:46  adam
+ * Work on truncation.
+ * Bug fix: result sets weren't deleted after server shut down.
+ *
+ * Revision 1.10  1995/10/30 15:08:08  adam
+ * Bug fixes.
+ *
+ * Revision 1.9  1995/10/17  18:02:14  adam
+ * New feature: databases. Implemented as prefix to words in dictionary.
+ *
+ * Revision 1.8  1995/10/10  13:59:25  adam
+ * Function rset_open changed its wflag parameter to general flags.
+ *
+ * Revision 1.7  1995/10/06  14:38:01  adam
+ * New result set method: r_score.
+ * Local no (sysno) and score is transferred to retrieveCtrl.
+ *
+ * Revision 1.6  1995/09/28  09:19:49  adam
  * xfree/xmalloc used everywhere.
  * Extract/retrieve method seems to work for text records.
  *
  */
 #include <stdio.h>
 #include <assert.h>
+#ifdef WINDOWS
+#include <io.h>
+#else
 #include <unistd.h>
+#endif
 
 #include "zserver.h"
 #include <rstemp.h>
@@ -66,8 +90,22 @@ ZServerSet *resultSetGet (ZServerInfo *zi, const char *name)
     return NULL;
 }
 
-ZServerSetSysno *resultSetSysnoGet  (ZServerInfo *zi, const char *name, 
-                                     int num, int *positions)
+void resultSetDestroy (ZServerInfo *zi)
+{
+    ZServerSet *s, *s1;
+
+    for (s = zi->sets; s; s = s1)
+    {
+        s1 = s->next;
+        rset_delete (s->rset);
+        xfree (s->name);
+        xfree (s);
+    }
+    zi->sets = NULL;
+}
+
+ZServerSetSysno *resultSetSysnoGet (ZServerInfo *zi, const char *name, 
+                                    int num, int *positions)
 {
     ZServerSet *sset;
     ZServerSetSysno *sr;
@@ -84,17 +122,18 @@ ZServerSetSysno *resultSetSysnoGet  (ZServerInfo *zi, const char *name,
         return NULL;
     logf (LOG_DEBUG, "resultSetRecordGet");
     sr = xmalloc (sizeof(*sr) * num);
-    rfd = rset_open (rset, 0);
+    rfd = rset_open (rset, RSETF_READ|RSETF_SORT_RANK);
     while (rset_read (rset, rfd, &key))
     {
         if (key.sysno != psysno)
         {
             psysno = key.sysno;
             position++;
+            assert (num_i < num);
             if (position == positions[num_i])
             {
                 sr[num_i].sysno = psysno;
-                num_i++;
+                rset_score (rset, rfd, &sr[num_i].score);
                 if (++num_i == num)
                     break;
             }
@@ -109,93 +148,7 @@ ZServerSetSysno *resultSetSysnoGet  (ZServerInfo *zi, const char *name,
     return sr;
 }
 
-void resultSetRecordDel (ZServerInfo *zi, ZServerRecord *records, int num)
+void resultSetSysnoDel (ZServerInfo *zi, ZServerSetSysno *records, int num)
 {
-    int i;
-
-    for (i = 0; i<num; i++)
-        xfree (records[i].buf);
     xfree (records);
 }
-
-
-#if 0
-ZServerSetSysno *resultSetSysno  (ZServerInfo *zi, const char *name, 
-                                  int num, int *positions)
-{
-    ZServerSet *sset;
-    ZServerRecord *sr;
-    RSET rset;
-    int num_i = 0;
-    int position = 0;
-    int psysno = 0;
-    struct it_key key;
-    RSFD rfd;
-
-    if (!(sset = resultSetGet (zi, name)))
-        return NULL;
-    if (!(rset = sset->rset))
-        return NULL;
-    logf (LOG_DEBUG, "resultSetRecordGet");
-    sr = xmalloc (sizeof(*sr) * num);
-    rfd = rset_open (rset, 0);
-    while (rset_read (rset, rfd, &key))
-    {
-        if (key.sysno != psysno)
-        {
-            psysno = key.sysno;
-            position++;
-            if (position == positions[num_i])
-            {
-                FILE *inf;
-                char fname[SYS_IDX_ENTRY_LEN];
-
-                sr[num_i].buf = NULL;
-                if (lseek (zi->sys_idx_fd, psysno * SYS_IDX_ENTRY_LEN,
-                           SEEK_SET) == -1)
-                {
-                    logf (LOG_FATAL|LOG_ERRNO, "lseek of sys_idx");
-                    exit (1);
-                }
-                if (read (zi->sys_idx_fd, fname, SYS_IDX_ENTRY_LEN) == -1)
-                {
-                    logf (LOG_FATAL|LOG_ERRNO, "read of sys_idx");
-                    exit (1);
-                }
-                if (!(inf = fopen (fname, "r")))
-                    logf (LOG_WARN, "fopen: %s", fname);
-                else
-                {
-                    long size;
-
-                    fseek (inf, 0L, SEEK_END);
-                    size = ftell (inf);
-                    fseek (inf, 0L, SEEK_SET);
-                    logf (LOG_DEBUG, "get sysno=%d, fname=%s, size=%ld",
-                          psysno, fname, (long) size);
-                    sr[num_i].buf = xmalloc (size+1);
-                    sr[num_i].size = size;
-                    sr[num_i].buf[size] = '\0';
-                    if (fread (sr[num_i].buf, size, 1, inf) != 1)
-                    {
-                        logf (LOG_FATAL|LOG_ERRNO, "fread %s", fname);
-                        exit (1);
-                    }
-                    fclose (inf);
-                }
-                num_i++;
-                if (num_i == num)
-                    break;
-            }
-        }
-    }
-    rset_close (rset, rfd);
-    while (num_i < num)
-    {
-        sr[num_i].buf = NULL;
-        sr[num_i].size = 0;
-        num_i++;
-    }
-    return sr;
-}
-#endif