Bug fix: Leading and trailing white space weren't removed in scan tokens.
[idzebra-moved-to-github.git] / index / zserver.c
index faae520..acaf62c 100644 (file)
@@ -4,7 +4,26 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: zserver.c,v $
- * Revision 1.40  1996-06-04 10:19:02  adam
+ * Revision 1.45  1996-12-23 15:30:45  adam
+ * Work on truncation.
+ * Bug fix: result sets weren't deleted after server shut down.
+ *
+ * Revision 1.44  1996/12/11 12:08:01  adam
+ * Added better compression.
+ *
+ * Revision 1.43  1996/11/15 15:03:58  adam
+ * Logging of execution speed by using the times(2) call.
+ *
+ * Revision 1.42  1996/11/08  11:10:36  adam
+ * Buffers used during file match got bigger.
+ * Compressed ISAM support everywhere.
+ * Bug fixes regarding masking characters in queries.
+ * Redesigned Regexp-2 queries.
+ *
+ * Revision 1.41  1996/10/29 14:09:56  adam
+ * Use of cisam system - enabled if setting isamc is 1.
+ *
+ * Revision 1.40  1996/06/04 10:19:02  adam
  * Minor changes - removed include of ctype.h.
  *
  * Revision 1.39  1996/05/31  09:07:05  quinn
 #include <data1.h>
 #include <recctrl.h>
 #include <dmalloc.h>
+
+#define USE_TIMES 1
+#ifdef __linux__
+#define USE_TIMES 1
+#endif
+
+#if USE_TIMES
+#include <sys/times.h>
+#endif
 #include "zserver.h"
 
 ZServerInfo server_info;
 
+#if USE_TIMES
+static struct tms tms1;
+static struct tms tms2;
+#endif
+
 static int register_lock (ZServerInfo *zi)
 {
     time_t lastChange;
@@ -173,6 +206,9 @@ static int register_lock (ZServerInfo *zi)
         state = 0;
     }
     zebraServerLock (state);
+#if USE_TIMES
+    times (&tms1);
+#endif
     if (zi->registerState == state)
     {
         if (zi->registerChange >= lastChange)
@@ -189,18 +225,32 @@ static int register_lock (ZServerInfo *zi)
     if (zi->records)
     {
         zebTargetInfo_close (zi->zti, 0);
-        dict_close (zi->wordDict);
-        is_close (zi->wordIsam);
+        dict_close (zi->dict);
+        if (zi->isam)
+            is_close (zi->isam);
+        if (zi->isamc)
+            isc_close (zi->isamc);
         rec_close (&zi->records);
     }
     bf_cache (state);
     zi->registerState = state;
     zi->records = rec_open (0);
-    if (!(zi->wordDict = dict_open (FNAME_WORD_DICT, 40, 0)))
+    if (!(zi->dict = dict_open (FNAME_DICT, 40, 0)))
         return -1;
-    if (!(zi->wordIsam = is_open (FNAME_WORD_ISAM, key_compare, 0,
+    zi->isam = NULL;
+    zi->isamc = NULL;
+    if (res_get_match (common_resource, "isam", "c", NULL))
+    {
+        if (!(zi->isamc = isc_open (FNAME_ISAMC, 0, key_isamc_m())))
+            return -1;
+
+    }
+    else
+    {
+        if (!(zi->isam = is_open (FNAME_ISAM, key_compare, 0,
                                   sizeof (struct it_key))))
-        return -1;
+            return -1;
+    }
     zi->zti = zebTargetInfo_open (zi->records, 0);
     init_charmap ();
     return 0;
@@ -210,6 +260,12 @@ static void register_unlock (ZServerInfo *zi)
 {
     static int waitSec = -1;
 
+#if USE_TIMES
+    times (&tms2);
+    logf (LOG_LOG, "user/system: %ld/%ld",
+                       (long) (tms2.tms_utime - tms1.tms_utime),
+                       (long) (tms2.tms_stime - tms1.tms_stime));
+#endif
     if (waitSec == -1)
     {
         char *s = res_get (common_resource, "debugRequestWait");
@@ -246,16 +302,14 @@ bend_initresult *bend_init (bend_initrequest *q)
             logf (LOG_FATAL, "Cannot open resource `%s'", sob->configname);
             exit (1);
         }
-        bf_lockDir (res_get (common_resource, "lockPath"));
-        data1_tabpath = res_get(common_resource, "profilePath");
+        bf_lockDir (res_get (common_resource, "lockDir"));
+        data1_set_tabpath (res_get(common_resource, "profilePath"));
     }
     server_info.sets = NULL;
     server_info.registerState = -1;  /* trigger open of registers! */
     server_info.registerChange = 0;
 
     server_info.records = NULL;
-    server_info.wordDict = NULL;
-    server_info.wordIsam = NULL;
     server_info.odr = odr_createmem (ODR_ENCODE);
     return &r;
 }
@@ -324,10 +378,10 @@ static int record_int_read (void *fh, char *buf, size_t count)
 static int record_fetch (ZServerInfo *zi, int sysno, int score, ODR stream,
                           oid_value input_format, Z_RecordComposition *comp,
                          oid_value *output_format, char **rec_bufp,
-                         int *rec_lenp)
+                         int *rec_lenp, char **basenamep)
 {
     Record rec;
-    char *fname, *file_type;
+    char *fname, *file_type, *basename;
     RecType rt;
     int fd = -1;
     struct recRetrieveCtrl retrieveCtrl;
@@ -345,6 +399,9 @@ static int record_fetch (ZServerInfo *zi, int sysno, int score, ODR stream,
     }
     file_type = rec->info[recInfo_fileType];
     fname = rec->info[recInfo_filename];
+    basename = rec->info[recInfo_databaseName];
+    *basenamep = odr_malloc (stream, strlen(basename)+1);
+    strcpy (*basenamep, basename);
 
     if (!(rt = recType_byName (file_type, subType)))
     {
@@ -435,7 +492,8 @@ bend_fetchresult *bend_fetch (void *handle, bend_fetchrequest *q, int *num)
     }
     r.errcode = record_fetch (&server_info, records[0].sysno,
                               records[0].score, q->stream, q->format,
-                              q->comp, &r.format, &r.record, &r.len);
+                              q->comp, &r.format, &r.record, &r.len,
+                              &r.basename);
     resultSetSysnoDel (&server_info, records, 1);
     register_unlock (&server_info);
     return &r;
@@ -475,8 +533,12 @@ void bend_close (void *handle)
 {
     if (server_info.records)
     {
-        dict_close (server_info.wordDict);
-        is_close (server_info.wordIsam);
+        resultSetDestroy (&server_info);
+        dict_close (server_info.dict);
+        if (server_info.isam)
+            is_close (server_info.isam);
+        if (server_info.isamc)
+            isc_close (server_info.isamc);
         rec_close (&server_info.records);
         register_unlock (&server_info);
     }