- logit( info, "between: start of loop", p->buf_l, p->buf_m, p->buf_r);
-
- /* forward L until past m, count levels, note rec boundaries */
- if (p->more_l)
- cmp_l= (*info->cmp)(p->buf_l, p->buf_m);
- else
- cmp_l=2; /* past this record */
- while (cmp_l < 0) /* l before m */
- {
- if (cmp_l == -2)
- p->level=0; /* earlier record */
- if (cmp_l == -1)
- p->level++; /* relevant start tag */
- if (p->more_l)
- {
- p->more_l = rset_read (info->rset_l, p->rfd_l, p->buf_l,
- &p->term_index_l);
- cmp_l= (*info->cmp)(p->buf_l, p->buf_m);
- }
- else
- cmp_l=2;
- } /* forward L */
-
- /* forward R until past m, count levels */
- if (p->more_r)
- cmp_r= (*info->cmp)(p->buf_r, p->buf_m);
- else
- cmp_r=2;
- while (cmp_r < 0) /* r before m */
- {
- /* -2, earlier record, doesn't matter */
- if (cmp_r == -1)
- p->level--; /* relevant end tag */
- if (p->more_r)
+ yaz_log(log_level,"read loop term=%p d=%d ad=%d",
+ *term,p->depth, p->attrdepth);
+ if (p->hits<0)
+ {/* first time? */
+ memcpy(p->recbuf,buf,kctrl->key_size);
+ p->hits=0;
+ cmp=rfd->rset->scope; /* force newrecord */
+ }
+ else {
+ cmp=(kctrl->cmp)(buf,p->recbuf);
+ yaz_log(log_level, "cmp=%d",cmp);
+ }
+
+ if (cmp>=rfd->rset->scope)
+ {
+ yaz_log(log_level,"new record");
+ p->depth=0;
+ p->attrdepth=0;
+ memcpy(p->recbuf,buf,kctrl->key_size);
+ }
+
+ if (*term)
+ yaz_log(log_level," term: '%s'", (*term)->name);
+ if (*term==info->startterm)
+ {
+ 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 */
+ }
+ else if (*term==info->stopterm)
+ {
+ if (p->depth == p->attrdepth)
+ p->attrdepth=0; /* ending the tag with attr match */
+ p->depth--;
+ yaz_log(log_level,"read end tag. d=%d ad=%d",p->depth, p->attrdepth);
+ }
+ else if (*term==info->attrterm)
+ {
+ 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 */
+ }
+ else
+ { /* mut be a real hit */
+ if (p->depth && p->attrdepth)