/*
- * Copyright (C) 1995, Index Data I/S
+ * Copyright (C) 1994-1995, Index Data I/S
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: zrpn.c,v $
- * Revision 1.3 1995-09-04 15:20:22 adam
+ * Revision 1.6 1995-09-06 16:11:18 adam
+ * Option: only one word key per file.
+ *
+ * Revision 1.5 1995/09/06 10:33:04 adam
+ * More work on present. Some log messages removed.
+ *
+ * Revision 1.4 1995/09/05 15:28:40 adam
+ * More work on search engine.
+ *
+ * Revision 1.3 1995/09/04 15:20:22 adam
* Minor changes.
*
* Revision 1.2 1995/09/04 12:33:43 adam
#include <assert.h>
#include <unistd.h>
-#include <alexutil.h>
-#include <dict.h>
-#include <isam.h>
+#include "zserver.h"
+
#include <rsisam.h>
#include <rstemp.h>
+#include <rsnull.h>
-#include <proto.h>
-
-#include "index.h"
-
-struct index_info {
- Dict dict;
- ISAM isam;
-};
-
-static RSET rpn_search_APT (struct index_info *ii, Z_AttributesPlusTerm *zapt)
+static RSET rpn_search_APT (ZServerInfo *zi, Z_AttributesPlusTerm *zapt)
{
+ char termz[256];
+ size_t sizez;
struct rset_isam_parms parms;
const char *info;
Z_Term *term = zapt->term;
if (term->which != Z_Term_general)
return NULL;
- if (!(info = dict_lookup (ii->dict, term->u.general->buf)))
- return NULL;
+ sizez = term->u.general->len;
+ if (sizez > 255)
+ sizez = 255;
+ memcpy (termz, term->u.general->buf, sizez);
+ termz[sizez] = '\0';
+ logf (LOG_DEBUG, "dict_lookup: %s", termz);
+ if (!(info = dict_lookup (zi->wordDict, termz)))
+ return rset_create (rset_kind_null, NULL);
assert (*info == sizeof(parms.pos));
memcpy (&parms.pos, info+1, sizeof(parms.pos));
- parms.is = ii->isam;
+ parms.is = zi->wordIsam;
+ logf (LOG_DEBUG, "rset_create isam");
return rset_create (rset_kind_isam, &parms);
}
-static RSET rpn_search_and (struct index_info *ii, RSET r_l, RSET r_r)
+static RSET rpn_search_and (ZServerInfo *zi, RSET r_l, RSET r_r)
{
struct it_key k1, k2;
RSET r_dst;
return r_dst;
}
-static RSET rpn_search_or (struct index_info *ii, RSET r_l, RSET r_r)
+static RSET rpn_search_or (ZServerInfo *zi, RSET r_l, RSET r_r)
{
return r_l;
}
-static RSET rpn_search_not (struct index_info *ii, RSET r_l, RSET r_r)
+static RSET rpn_search_not (ZServerInfo *zi, RSET r_l, RSET r_r)
{
return r_l;
}
-static RSET rpn_search_ref (struct index_info *ii, Z_ResultSetId *resultSetId)
+static RSET rpn_search_ref (ZServerInfo *zi, Z_ResultSetId *resultSetId)
{
return NULL;
}
-static RSET rpn_search_structure (struct index_info *ii, Z_RPNStructure *zs)
+static RSET rpn_search_structure (ZServerInfo *zi, Z_RPNStructure *zs)
{
RSET r;
if (zs->which == Z_RPNStructure_complex)
{
RSET r_l, r_r;
- r_l = rpn_search_structure (ii, zs->u.complex->s1);
- r_r = rpn_search_structure (ii, zs->u.complex->s2);
+ r_l = rpn_search_structure (zi, zs->u.complex->s1);
+ r_r = rpn_search_structure (zi, zs->u.complex->s2);
switch (zs->u.complex->operator->which)
{
case Z_Operator_and:
- r = rpn_search_and (ii, r_l, r_r);
+ rset_delete (r_r);
break;
case Z_Operator_or:
- r = rpn_search_or (ii, r_l, r_r);
+ rset_delete (r_r);
break;
case Z_Operator_and_not:
- r = rpn_search_not (ii, r_l, r_r);
+ rset_delete (r_r);
break;
default:
assert (0);
}
- rset_delete (r_l);
- rset_delete (r_r);
+ r = r_l;
}
else if (zs->which == Z_RPNStructure_simple)
{
if (zs->u.simple->which == Z_Operand_APT)
- r = rpn_search_APT (ii, zs->u.simple->u.attributesPlusTerm);
+ {
+ logf (LOG_DEBUG, "rpn_search_APT");
+ r = rpn_search_APT (zi, zs->u.simple->u.attributesPlusTerm);
+ }
else if (zs->u.simple->which == Z_Operand_resultSetId)
- r = rpn_search_ref (ii, zs->u.simple->u.resultSetId);
+ {
+ logf (LOG_DEBUG, "rpn_search_ref");
+ r = rpn_search_ref (zi, zs->u.simple->u.resultSetId);
+ }
else
{
assert (0);
}
return r;
}
+
+static RSET rpn_save_set (RSET r, int *count)
+{
+#if 0
+ RSET d;
+ rset_temp_parms parms;
+#endif
+ int psysno = 0;
+ struct it_key key;
+
+ logf (LOG_DEBUG, "rpn_save_set");
+ *count = 0;
+#if 0
+ parms.key_size = sizeof(struct it_key);
+ d = rset_create (rset_kind_temp, &parms);
+ rset_open (d, 1);
+#endif
+
+ rset_open (r, 0);
+ while (rset_read (r, &key))
+ {
+ if (key.sysno != psysno)
+ {
+ psysno = key.sysno;
+ (*count)++;
+ }
+#if 0
+ rset_write (d, &key);
+#endif
+ }
+ rset_close (r);
+#if 0
+ rset_close (d);
+#endif
+ logf (LOG_DEBUG, "%d distinct sysnos", *count);
+#if 0
+ return d;
+#endif
+}
+
+int rpn_search (ZServerInfo *zi,
+ Z_RPNQuery *rpn, int num_bases, char **basenames,
+ const char *setname, int *hits)
+{
+ RSET rset, result_rset;
+
+ rset = rpn_search_structure (zi, rpn->RPNStructure);
+ if (!rset)
+ return 0;
+ result_rset = rpn_save_set (rset, hits);
+#if 0
+ rset_delete (result_rset);
+#endif
+
+ resultSetAdd (zi, setname, 1, rset);
+ return 0;
+}
+