* Sebastian Hammer, Adam Dickmeiss
*
* $Log: extract.c,v $
- * Revision 1.19 1995-10-04 12:55:16 adam
+ * Revision 1.25 1995-11-16 15:34:54 adam
+ * Uses new record management system in both indexer and server.
+ *
+ * Revision 1.24 1995/11/15 19:13:08 adam
+ * Work on record management.
+ *
+ * Revision 1.23 1995/10/27 14:00:10 adam
+ * Implemented detection of database availability.
+ *
+ * Revision 1.22 1995/10/17 18:02:07 adam
+ * New feature: databases. Implemented as prefix to words in dictionary.
+ *
+ * Revision 1.21 1995/10/10 12:24:38 adam
+ * Temporary sort files are compressed.
+ *
+ * Revision 1.20 1995/10/06 13:52:05 adam
+ * Bug fixes. Handler may abort further scanning.
+ *
+ * Revision 1.19 1995/10/04 12:55:16 adam
* Bug fix in ranked search. Use=Any keys inserted.
*
* Revision 1.18 1995/10/04 09:37:08 quinn
#include <recctrl.h>
#include "index.h"
+#if RECORD_BASE
+#include "recindex.h"
+#endif
+
static Dict file_idx;
-static SYSNO sysno_next;
+
+
+#if RECORD_BASE
+static Records records = NULL;
+#else
static int sys_idx_fd = -1;
+static SYSNO sysno_next;
+#endif
static int key_cmd;
static int key_sysno;
+static char *key_databaseName;
static char **key_buf;
static size_t ptr_top;
static size_t ptr_i;
void key_open (int mem)
{
+#if !RECORD_BASE
void *file_key;
-
+#endif
if (mem < 50000)
mem = 50000;
key_buf = xmalloc (mem);
logf (LOG_FATAL, "dict_open fail of %s", "fileidx");
exit (1);
}
+#if RECORD_BASE
+ assert (!records);
+ records = rec_open (1);
+#else
file_key = dict_lookup (file_idx, ".");
if (file_key)
memcpy (&sysno_next, (char*)file_key+1, sizeof(sysno_next));
logf (LOG_FATAL|LOG_ERRNO, "open %s", FNAME_SYS_IDX);
exit (1);
}
+#endif
}
-
+
+struct encode_info {
+ int sysno;
+ int seqno;
+ char buf[512];
+};
+
+void encode_key_init (struct encode_info *i)
+{
+ i->sysno = 0;
+ i->seqno = 0;
+}
+
+char *encode_key_int (int d, char *bp)
+{
+ if (d <= 63)
+ *bp++ = d;
+ else if (d <= 16383)
+ {
+ *bp++ = 64 + (d>>8);
+ *bp++ = d & 255;
+ }
+ else if (d <= 4194303)
+ {
+ *bp++ = 128 + (d>>16);
+ *bp++ = (d>>8) & 255;
+ *bp++ = d & 255;
+ }
+ else
+ {
+ *bp++ = 192 + (d>>24);
+ *bp++ = (d>>16) & 255;
+ *bp++ = (d>>8) & 255;
+ *bp++ = d & 255;
+ }
+ return bp;
+}
+
+void encode_key_write (char *k, struct encode_info *i, FILE *outf)
+{
+ struct it_key key;
+ char *bp = i->buf;
+
+ while ((*bp++ = *k++))
+ ;
+ memcpy (&key, k+1, sizeof(struct it_key));
+ bp = encode_key_int ( (key.sysno - i->sysno) * 2 + *k, bp);
+ if (i->sysno != key.sysno)
+ {
+ i->sysno = key.sysno;
+ i->seqno = 0;
+ }
+ bp = encode_key_int (key.seqno - i->seqno, bp);
+ i->seqno = key.seqno;
+ if (fwrite (i->buf, bp - i->buf, 1, outf) != 1)
+ {
+ logf (LOG_FATAL|LOG_ERRNO, "fwrite");
+ exit (1);
+ }
+}
+
void key_flush (void)
{
FILE *outf;
char out_fname[200];
char *prevcp, *cp;
+ struct encode_info encode_info;
if (ptr_i <= 0)
return;
logf (LOG_LOG, "writing section %d", key_file_no);
prevcp = cp = key_buf[ptr_top-ptr_i];
- if (fwrite (cp, strlen (cp)+2+sizeof(struct it_key), 1, outf) != 1)
- {
- logf (LOG_FATAL|LOG_ERRNO, "fwrite %s", out_fname);
- exit (1);
- }
+ encode_key_init (&encode_info);
+ encode_key_write (cp, &encode_info, outf);
while (--ptr_i > 0)
{
cp = key_buf[ptr_top-ptr_i];
if (strcmp (cp, prevcp))
{
- if (fwrite (cp, strlen (cp)+2+sizeof(struct it_key), 1,
- outf) != 1)
- {
- logf (LOG_FATAL|LOG_ERRNO, "fwrite %s", out_fname);
- exit (1);
- }
+ encode_key_init (&encode_info);
+ encode_key_write (cp, &encode_info, outf);
prevcp = cp;
}
else
- {
- cp = strlen (cp) + cp;
- if (fwrite (cp, 2+sizeof(struct it_key), 1, outf) != 1)
- {
- logf (LOG_FATAL|LOG_ERRNO, "fwrite %s", out_fname);
- exit (1);
- }
- }
+ encode_key_write (cp + strlen(cp), &encode_info, outf);
}
if (fclose (outf))
{
{
key_flush ();
xfree (key_buf);
+#if RECORD_BASE
+ rec_close (&records);
+#else
close (sys_idx_fd);
dict_insert (file_idx, ".", sizeof(sysno_next), &sysno_next);
+#endif
dict_close (file_idx);
return key_file_no;
}
++ptr_i;
key_buf[ptr_top-ptr_i] = (char*)key_buf + kused;
kused += index_word_prefix ((char*)key_buf + kused,
- p->attrSet, p->attrUse);
+ p->attrSet, p->attrUse,
+ key_databaseName);
switch (p->which)
{
case Word_String:
static void wordAddAny (const RecWord *p)
{
- if (p->attrSet != 1 && p->attrUse != 1016)
+ if (p->attrSet != 1 || p->attrUse != 1016)
{
RecWord w;
return read (fd, buf, count);
}
#endif
-void file_extract (int cmd, const char *fname, const char *kname)
+void file_extract (int cmd, const char *fname, const char *kname,
+ char *databaseName)
{
int i, r;
char ext[128];
struct recExtractCtrl extractCtrl;
RecType rt;
+ key_databaseName = databaseName;
for (i = strlen(fname); --i >= 0; )
if (fname[i] == '/')
{
file_info = dict_lookup (file_idx, kname);
if (!file_info)
{
+#if RECORD_BASE
+ Record rec = rec_new (records);
+
+ sysno = rec->sysno;
+ dict_insert (file_idx, kname, sizeof(sysno), &sysno);
+ rec->info[0] = rec_strdup (file_type);
+ rec->info[1] = rec_strdup (kname);
+ rec_put (records, rec);
+ rec_rm (rec);
+#else
sysno = sysno_next++;
dict_insert (file_idx, kname, sizeof(sysno), &sysno);
lseek (sys_idx_fd, sysno * SYS_IDX_ENTRY_LEN, SEEK_SET);
write (sys_idx_fd, file_type, strlen (file_type)+1);
write (sys_idx_fd, kname, strlen(kname)+1);
+#endif
}
else
memcpy (&sysno, (char*) file_info+1, sizeof(sysno));