X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=rset%2Frsprox.c;h=555e3007532ea486cb34425aec63e5bc11ede2cc;hb=3335cd5f7e7af06ac6ed943859c473e092d559a1;hp=072ff3a8c29e60dc8451bfc4a6e693f6eee5c75c;hpb=7cf3de518896b7bec9927356a71d9fa989560767;p=idzebra-moved-to-github.git diff --git a/rset/rsprox.c b/rset/rsprox.c index 072ff3a..555e300 100644 --- a/rset/rsprox.c +++ b/rset/rsprox.c @@ -1,4 +1,4 @@ -/* $Id: rsprox.c,v 1.2 2004-06-14 21:44:26 adam Exp $ +/* $Id: rsprox.c,v 1.8 2004-08-06 14:09:02 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -25,8 +25,8 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include #include +#include #ifndef RSET_DEBUG #define RSET_DEBUG 0 @@ -40,9 +40,9 @@ static void r_rewind (RSFD rfd); static int r_forward(RSET ct, RSFD rfd, void *buf, int *term_index, int (*cmpfunc)(const void *p1, const void *p2), const void *untilbuf); -static int r_count (RSET ct); static int r_read (RSFD rfd, void *buf, int *term_index); static int r_write (RSFD rfd, const void *buf); +static void r_pos (RSFD rfd, double *current, double *total); static const struct rset_control control_prox = { @@ -53,7 +53,7 @@ static const struct rset_control control_prox = r_delete, r_rewind, r_forward, - r_count, + r_pos, r_read, r_write, }; @@ -72,6 +72,7 @@ struct rset_prox_rfd { char *more; /* more in each lookahead? */ struct rset_prox_rfd *next; struct rset_prox_info *info; + zint hits; }; static void *r_create (RSET ct, const struct rset_control *sel, void *parms) @@ -81,12 +82,14 @@ static void *r_create (RSET ct, const struct rset_control *sel, void *parms) int i; char prox_term[512]; int length_prox_term = 0; - int min_nn = 10000000; + zint min_nn = 10000000; const char *flags = NULL; int term_type = 0; + info = (struct rset_prox_info *) xmalloc (sizeof(*info)); memcpy(&info->p, prox_parms, sizeof(struct rset_prox_parms)); + assert(info->p.rset_no >= 2); info->p.rset = xmalloc(info->p.rset_no * sizeof(*info->p.rset)); memcpy(info->p.rset, prox_parms->rset, info->p.rset_no * sizeof(*info->p.rset)); @@ -158,6 +161,7 @@ static RSFD r_open (RSET ct, int flag) for (i = 0; i < info->p.rset_no; i++) rfd->more[i] = rset_read (info->p.rset[i], rfd->rfd[i], rfd->buf[i], &dummy); + rfd->hits=0; return rfd; } @@ -214,6 +218,7 @@ static void r_rewind (RSFD rfd) rset_rewind (info->p.rset[i], p->rfd[i]); p->more[i] = rset_read (info->p.rset[i], p->rfd[i], p->buf[i], &dummy); } + p->hits=0; } static int r_forward (RSET ct, RSFD rfd, void *buf, int *term_index, @@ -251,7 +256,8 @@ static int r_forward (RSET ct, RSFD rfd, void *buf, int *term_index, cmp = (*info->p.cmp) (p->buf[i], p->buf[i-1]); if (cmp > 1) { - p->more[i-1] = rset_forward (info->p.rset[i-1], p->rfd[i-1], + p->more[i-1] = rset_forward (info->p.rset[i-1], + p->rfd[i-1], p->buf[i-1], &dummy, info->p.cmp, p->buf[i]); @@ -259,10 +265,12 @@ static int r_forward (RSET ct, RSFD rfd, void *buf, int *term_index, } else if (cmp == 1) { - if ((*info->p.getseq)(p->buf[i-1]) +1 != (*info->p.getseq)(p->buf[i])) + if ((*info->p.getseq)(p->buf[i-1]) +1 != + (*info->p.getseq)(p->buf[i])) { - p->more[i-1] = rset_read (info->p.rset[i-1], p->rfd[i-1], - p->buf[i-1], &dummy); + p->more[i-1] = rset_read ( + info->p.rset[i-1], p->rfd[i-1], + p->buf[i-1], &dummy); break; } } @@ -282,6 +290,7 @@ static int r_forward (RSET ct, RSFD rfd, void *buf, int *term_index, p->more[0] = rset_read (info->p.rset[0], p->rfd[0], p->buf[0], &dummy); + p->hits++; return 1; } } @@ -292,11 +301,13 @@ static int r_forward (RSET ct, RSFD rfd, void *buf, int *term_index, { int cmp = (*info->p.cmp)(p->buf[0], p->buf[1]); if (cmp < -1) - p->more[0] = rset_read (info->p.rset[0], p->rfd[0], p->buf[0], - term_index); + p->more[0] = rset_forward (info->p.rset[0], p->rfd[0], + p->buf[0], + term_index, info->p.cmp, p->buf[0]); else if (cmp > 1) - p->more[1] = rset_read (info->p.rset[1], p->rfd[1], p->buf[1], - term_index); + p->more[1] = rset_forward (info->p.rset[1], p->rfd[1], + p->buf[1], + term_index, info->p.cmp, p->buf[1]); else { int seqno[500]; @@ -351,6 +362,7 @@ static int r_forward (RSET ct, RSFD rfd, void *buf, int *term_index, p->more[1] = rset_read (info->p.rset[1], p->rfd[1], p->buf[1], term_index); + p->hits++; return 1; } } @@ -363,13 +375,10 @@ static int r_forward (RSET ct, RSFD rfd, void *buf, int *term_index, return 0; } -static int r_count (RSET ct) -{ - return 0; -} static int r_read (RSFD rfd, void *buf, int *term_index) { + { double cur,tot; r_pos(rfd,&cur,&tot); } /*!*/ return r_forward(0, rfd, buf, term_index, 0, 0); } @@ -379,3 +388,36 @@ static int r_write (RSFD rfd, const void *buf) return -1; } +static void r_pos (RSFD rfd, double *current, double *total) +{ + struct rset_prox_info *info = ((struct rset_prox_rfd*)rfd)->info; + struct rset_prox_rfd *p = (struct rset_prox_rfd *) rfd; + int i; + double cur,tot=-1; + double scur=0,stot=0; + double r; + + logf (LOG_DEBUG, "rsprox_pos"); + + for (i = 0; i < info->p.rset_no; i++) + { + rset_pos(info->p.rset[i], p->rfd[i], &cur, &tot); + if (tot>0) { + scur += cur; + stot += tot; + } + } + if (tot <0) { /* nothing found */ + *current=-1; + *total=-1; + } else if (tot <1) { /* most likely tot==0 */ + *current=0; + *total=0; + } else { + r=scur/stot; + *current=p->hits; + *total=*current/r ; + } + logf(LOG_DEBUG,"prox_pos: [%d] %0.1f/%0.1f= %0.4f ", + i,*current, *total, r); +}