-/* $Id: rsbetween.c,v 1.30 2004-11-05 17:44:32 heikki Exp $
- Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
- Index Data Aps
+/* $Id: rsbetween.c,v 1.34 2005-01-15 19:38:33 adam Exp $
+ Copyright (C) 1995-2005
+ Index Data ApS
This file is part of the Zebra server.
static int log_level_initialized=0;
+/* make sure that the rset has a term attached. If not, create one */
+/* we need these terms for the tags, to distinguish what we read */
+static void checkterm( RSET rs, char *tag, NMEM nmem)
+{
+ if (!rs->term)
+ {
+ rs->term=
+ rset_term_create(tag,strlen(tag),"",0,nmem);
+ rs->term->rset=rs;
+ }
+}
+
+
RSET rsbetween_create( NMEM nmem, const struct key_control *kcontrol,
int scope,
RSET rset_l, RSET rset_m, RSET rset_r, RSET rset_attr)
rsetarray[ATTRTAG] = rset_attr;
/* make sure we have decent terms for all rsets. Create dummies if needed*/
- if (!rsetarray[STARTTAG]->term)
- {
- rsetarray[STARTTAG]->term=
- rset_term_create("<starttag>",strlen("<starttag>"),"",0,nmem);
- rsetarray[STARTTAG]->term->rset=rsetarray[STARTTAG];
- }
+ checkterm( rsetarray[STARTTAG], "(start)",nmem);
+ checkterm( rsetarray[STOPTAG], "(start)",nmem);
info->startterm=rsetarray[STARTTAG]->term;
-
- if (!rsetarray[STOPTAG]->term)
- {
- rsetarray[STOPTAG]->term=
- rset_term_create("<stoptag>",strlen("<stoptag>"),"",0,nmem);
- rsetarray[STOPTAG]->term->rset=rsetarray[STOPTAG];
- }
info->stopterm=rsetarray[STOPTAG]->term;
if (rset_attr)
{
- if (!rsetarray[ATTRTAG]->term)
- {
- rsetarray[ATTRTAG]->term=
- rset_term_create("<attrtag>",strlen("<attrtag>"),"",0,nmem);
- rsetarray[ATTRTAG]->term->rset=rsetarray[ATTRTAG];
- }
+ checkterm( rsetarray[ATTRTAG], "(start)",nmem);
info->attrterm=rsetarray[ATTRTAG]->term;
+ n=4;
}
else
{
info->attrterm=NULL;
- n--; /* smaller and */
+ n=3;
}
info->andset=rsmultiand_create( nmem, kcontrol, scope, n, rsetarray);
rnew->priv=info;
- logf(log_level,"create rset at %p",rnew);
+ yaz_log(log_level,"create rset at %p",rnew);
return rnew;
}
static void r_delete (RSET ct)
{
struct rset_between_info *info = (struct rset_between_info *) ct->priv;
- logf(log_level,"delete rset at %p",ct);
+ yaz_log(log_level,"delete rset at %p",ct);
rset_delete(info->andset);
}
if (flag & RSETF_WRITE)
{
- logf (LOG_FATAL, "between set type is read-only");
+ yaz_log (YLOG_FATAL, "between set type is read-only");
return NULL;
}
rfd=rfd_create_base(ct);
p->attrdepth=0;
p->attrbufok=0;
p->startbufok=0;
- logf(log_level,"open rset=%p rfd=%p", ct, rfd);
+ yaz_log(log_level,"open rset=%p rfd=%p", ct, rfd);
return rfd;
}
static void r_close (RSFD rfd)
{
struct rset_between_rfd *p=(struct rset_between_rfd *)rfd->priv;
- logf(log_level,"close rfd=%p", rfd);
+ yaz_log(log_level,"close rfd=%p", rfd);
rset_close (p->andrfd);
rfd_delete_base(rfd);
}
{
struct rset_between_rfd *p=(struct rset_between_rfd *)rfd->priv;
int rc;
- logf(log_level, "forwarding ");
+ yaz_log(log_level, "forwarding ");
rc=rset_forward(p->andrfd,buf,term,untilbuf);
return rc;
}
if (0==cmp) /* and the keys match */
{
p->attrdepth=p->depth;
- logf(log_level, "found attribute match at depth %d",p->attrdepth);
+ yaz_log(log_level, "found attribute match at depth %d",p->attrdepth);
}
}
}
struct rset_between_rfd *p=(struct rset_between_rfd *)rfd->priv;
const struct key_control *kctrl=rfd->rset->keycontrol;
int cmp;
- logf(log_level,"== read: term=%p",term);
TERMID dummyterm=0;
+ yaz_log(log_level,"== read: term=%p",term);
if (!term)
term=&dummyterm;
while ( rset_read(p->andrfd,buf,term) )
{
- logf(log_level,"read loop term=%p d=%d ad=%d",
+ yaz_log(log_level,"read loop term=%p d=%d ad=%d",
*term,p->depth, p->attrdepth);
if (p->hits<0)
{/* first time? */
}
else {
cmp=(kctrl->cmp)(buf,p->recbuf);
- logf(log_level, "cmp=%d",cmp);
+ yaz_log(log_level, "cmp=%d",cmp);
}
if (cmp>=rfd->rset->scope)
{
- logf(log_level,"new record");
+ yaz_log(log_level,"new record");
p->depth=0;
p->attrdepth=0;
memcpy(p->recbuf,buf,kctrl->key_size);
}
if (*term)
- logf(log_level," term: '%s'", (*term)->name);
+ yaz_log(log_level," term: '%s'", (*term)->name);
if (*term==info->startterm)
{
p->depth++;
- logf(log_level,"read start tag. d=%d",p->depth);
+ yaz_log(log_level,"read start tag. d=%d",p->depth);
memcpy(p->startbuf,buf,kctrl->key_size);
p->startbufok=1;
checkattr(rfd); /* in case we already saw the attr here */
if (p->depth == p->attrdepth)
p->attrdepth=0; /* ending the tag with attr match */
p->depth--;
- logf(log_level,"read end tag. d=%d ad=%d",p->depth, p->attrdepth);
+ yaz_log(log_level,"read end tag. d=%d ad=%d",p->depth, p->attrdepth);
}
else if (*term==info->attrterm)
{
- logf(log_level,"read attr");
+ yaz_log(log_level,"read attr");
memcpy(p->attrbuf,buf,kctrl->key_size);
p->attrbufok=1;
checkattr(rfd); /* in case the start tag came first */
if (p->depth && p->attrdepth)
{
p->hits++;
- logf(log_level,"got a hit h="ZINT_FORMAT" d=%d ad=%d",
+ yaz_log(log_level,"got a hit h="ZINT_FORMAT" d=%d ad=%d",
p->hits,p->depth,p->attrdepth);
return 1; /* we have everything in place already! */
} else
- logf(log_level, "Ignoring hit. h="ZINT_FORMAT" d=%d ad=%d",
+ yaz_log(log_level, "Ignoring hit. h="ZINT_FORMAT" d=%d ad=%d",
p->hits,p->depth,p->attrdepth);
}
} /* while read */
static int r_write (RSFD rfd, const void *buf)
{
- logf (LOG_FATAL, "between set type is read-only");
+ yaz_log (YLOG_FATAL, "between set type is read-only");
return -1;
}
{
struct rset_between_rfd *p=(struct rset_between_rfd *)rfd->priv;
rset_pos(p->andrfd,current, total);
- logf(log_level,"pos: %0.1f/%0.1f ", *current, *total);
+ yaz_log(log_level,"pos: %0.1f/%0.1f ", *current, *total);
}
static void r_get_terms(RSET ct, TERMID *terms, int maxterms, int *curterm)