-/*
- * Copyright (C) 1994-1998, Index Data I/S
- * All rights reserved.
- * Sebastian Hammer, Adam Dickmeiss
- *
- * $Log: rset.c,v $
- * Revision 1.12 1998-04-26 10:56:57 adam
- * Added include of string.h.
- *
- * Revision 1.11 1998/03/05 08:36:28 adam
- * New result set model.
- *
- * Revision 1.10 1998/02/10 11:56:46 adam
- * Implemented rset_dup.
- *
- * Revision 1.9 1996/10/29 13:55:21 adam
- * Include of zebrautl.h instead of alexutil.h.
- *
- * Revision 1.8 1995/12/11 09:15:23 adam
- * New set types: sand/sor/snot - ranked versions of and/or/not in
- * ranked/semi-ranked result sets.
- * Note: the snot not finished yet.
- * New rset member: flag.
- * Bug fix: r_delete in rsrel.c did free bad memory block.
- *
- * Revision 1.7 1995/10/12 12:41:56 adam
- * Private info (buf) moved from struct rset_control to struct rset.
- * Bug fixes in relevance.
- *
- * Revision 1.6 1995/09/08 14:52:41 adam
- * Work on relevance feedback.
- *
- * Revision 1.5 1995/09/07 13:58:43 adam
- * New parameter: result-set file descriptor (RSFD) to support multiple
- * positions within the same result-set.
- * Boolean operators: and, or, not implemented.
- *
- * Revision 1.4 1995/09/06 16:11:56 adam
- * More work on boolean sets.
- *
- * Revision 1.3 1995/09/04 15:20:39 adam
- * More work on temp sets. is_open member removed.
- *
- * Revision 1.2 1995/09/04 12:33:56 adam
- * Various cleanup. YAZ util used instead.
- *
- * Revision 1.1 1994/11/04 13:21:28 quinn
- * Working.
- *
- */
+/* $Id: rset.c,v 1.28 2004-08-24 15:00:16 heikki Exp $
+ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
+ Index Data Aps
+
+This file is part of the Zebra server.
+
+Zebra is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Zebra; see the file LICENSE.zebra. If not, write to the
+Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.
+*/
+
+
#include <stdio.h>
#include <string.h>
#include <zebrautl.h>
-
+#include <assert.h>
+#include <yaz/nmem.h>
#include <rset.h>
-RSET rset_create(const struct rset_control *sel, void *parms)
+RSET rset_create_base(const struct rset_control *sel, NMEM nmem)
+ /* FIXME - Add keysize and cmp function */
+ /* FIXME - Add a general key-func block for cmp, dump, etc */
{
RSET rnew;
- int i;
-
+ NMEM M;
logf (LOG_DEBUG, "rs_create(%s)", sel->desc);
- rnew = xmalloc(sizeof(*rnew));
+ if (nmem)
+ M=nmem;
+ else
+ M=nmem_create();
+ rnew = (RSET) nmem_malloc(M,sizeof(*rnew));
+ rnew->nmem=M;
+ if (nmem)
+ rnew->my_nmem=0;
+ else
+ rnew->my_nmem=1;
rnew->control = sel;
- rnew->flags = 0;
rnew->count = 1;
- rnew->rset_terms = NULL;
- rnew->no_rset_terms = 0;
- rnew->buf = (*sel->f_create)(rnew, sel, parms);
- logf (LOG_DEBUG, "no_rset_terms: %d", rnew->no_rset_terms);
- for (i = 0; i<rnew->no_rset_terms; i++)
- logf (LOG_DEBUG, " %s", rnew->rset_terms[i]->name);
+ rnew->priv = 0;
+
return rnew;
}
(rs->count)--;
if (!rs->count)
{
- (*rs->control->f_delete)(rs);
- xfree(rs);
+ (*rs->control->f_delete)(rs);
+ if (rs->my_nmem)
+ nmem_destroy(rs->nmem);
}
}
return rs;
}
-RSET_TERM *rset_terms(RSET rs, int *no)
-{
- *no = rs->no_rset_terms;
- return rs->rset_terms;
-}
+void rset_default_pos (RSFD rfd, double *current, double *total)
+{ /* This should never really be needed, but it is still used in */
+ /* those rsets that we don't really plan to use, like isam-s */
+ assert(rfd);
+ assert(current);
+ assert(total);
+ *current=-1; /* signal that pos is not implemented */
+ *total=-1;
+} /* rset_default_pos */
-RSET_TERM rset_term_create (const char *name, int length, const char *flags)
+int rset_default_forward(RSET ct, RSFD rfd, void *buf,
+ int (*cmpfunc)(const void *p1, const void *p2),
+ const void *untilbuf)
{
- RSET_TERM t = xmalloc (sizeof(*t));
- if (!name)
- t->name = NULL;
- else if (length == -1)
- t->name = xstrdup (name);
- else
+ int more=1;
+ int cmp=2;
+ logf (LOG_DEBUG, "rset_default_forward starting '%s' (ct=%p rfd=%p)",
+ ct->control->desc, ct,rfd);
+ /* key_logdump(LOG_DEBUG, untilbuf); */
+ while ( (cmp==2) && (more))
{
- t->name = xmalloc (length+1);
- memcpy (t->name, name, length);
- t->name[length] = '\0';
+ logf (LOG_DEBUG, "rset_default_forward looping m=%d c=%d",more,cmp);
+ more=rset_read(ct, rfd, buf);
+ if (more)
+ cmp=(*cmpfunc)(untilbuf,buf);
+/* if (more)
+ key_logdump(LOG_DEBUG,buf); */
}
- if (!flags)
- t->flags = NULL;
- else
- t->flags = xstrdup (flags);
- t->nn = 1;
- return t;
-}
+ logf (LOG_DEBUG, "rset_default_forward exiting m=%d c=%d",more,cmp);
-void rset_term_destroy (RSET_TERM t)
-{
- xfree (t->name);
- xfree (t->flags);
- xfree (t);
+ return more;
}
-RSET_TERM rset_term_dup (RSET_TERM t)
-{
- RSET_TERM nt = xmalloc (sizeof(*nt));
- if (t->name)
- nt->name = xstrdup (t->name);
- else
- nt->name = NULL;
- if (t->flags)
- nt->flags = xstrdup (t->flags);
- else
- nt->flags = NULL;
- nt->nn = t->nn;
- return nt;
-}