54 const void *untilbuf);
56 const void *untilbuf);
57 static void r_pos_and(
RSFD rfd,
double *current,
double *total);
58 static void r_pos_or(
RSFD rfd,
double *current,
double *total);
154 int cur = 1, child = 2;
157 while (child <= h->heapnum)
159 if (child < h->heapnum &&
heap_cmp(h, child, 1 + child) > 0)
178 int cur = 1, child = 2;
179 while (child <= h->heapnum)
181 if (child < h->heapnum &&
heap_cmp(h, child, 1 + child) > 0)
199 assert(cur <= h->heapmax);
202 while (parent && (
heap_cmp(h,parent,cur) > 0))
214 HEAP h = (
HEAP) nmem_malloc(nmem,
sizeof(*h));
243 double cur, totx, toty;
246 if (totx > toty + 0.5)
248 if (totx < toty - 0.5)
256 int no_rsets,
RSET* rsets,
264 log_level = yaz_log_module_level(
"rsmultiandor");
300 yaz_log(YLOG_FATAL,
"multiandor set type is read-only");
380 TERMID *term,
const void *untilbuf)
418 it = mrfd->
h->
heap[1];
523 while (i < ct->no_children)
560 const void *untilbuf)
593 static void r_pos_x(
RSFD rfd,
double *current,
double *total,
int and_op)
597 double ratio = and_op ? 0.0 : 1.0;
599 double sum_cur = 0.0;
600 double sum_tot = 0.0;
606 yaz_log(
log_level,
"r_pos: %d %0.1f %0.1f", i,
cur,tot);
611 double nratio =
cur / tot;
619 sum_cur += (
cur - 1);
623 if (!and_op && sum_tot > 0.0)
625 yaz_log(YLOG_LOG,
"or op sum_cur=%0.1f sum_tot=%0.1f hits=%f", sum_cur, sum_tot, (
double) mrfd->
hits);
626 ratio = sum_cur / sum_tot;
628 if (ratio == 0.0 || ratio == 1.0)
632 yaz_log(
log_level,
"r_pos: NULL %0.1f %0.1f", *current, *total);
636 *current = (double) (mrfd->
hits);
637 *total = *current / ratio;
638 yaz_log(
log_level,
"r_pos: = %0.1f %0.1f", *current, *total);
644 r_pos_x(rfd, current, total, 1);
649 r_pos_x(rfd, current, total, 0);
662 int firstterm = *curterm;
667 if (*curterm > firstterm + 1 && *curterm <= maxterms &&
668 terms[(*curterm) - 1] == terms[firstterm])
RSET rset_create_base(const struct rset_control *sel, NMEM nmem, struct rset_key_control *kcontrol, int scope, TERMID term, int no_children, RSET *children)
Common constuctor for RSETs.
#define rset_read(rfd, buf, term)
int rset_no_write(RSFD rfd, const void *buf)
RSFD rfd_create_base(RSET rs)
Common constuctor for RFDs.
void rset_get_one_term(RSET ct, TERMID *terms, int maxterms, int *curterm)
is a getterms function for those that don't have any
#define rset_getterms(ct, terms, maxterms, curterm)
#define rset_pos(rfd, cur, tot)
#define rset_open(rs, wflag)
void rset_close(RSFD rfd)
Closes a result set RFD handle.
#define rset_forward(rfd, buf, term, untilbuf)
static void r_pos_and(RSFD rfd, double *current, double *total)
static RSET rsmulti_andor_create(NMEM nmem, struct rset_key_control *kcontrol, int scope, TERMID termid, int no_rsets, RSET *rsets, const struct rset_control *ctrl)
int compare_ands(const void *x, const void *y)
compare and items for quicksort used in qsort to get the multi-and args in optimal order that is,...
RSET rset_create_or(NMEM nmem, struct rset_key_control *kcontrol, int scope, TERMID termid, int no_rsets, RSET *rsets)
static int r_forward_and(RSFD rfd, void *buf, TERMID *term, const void *untilbuf)
RSET rset_create_and(NMEM nmem, struct rset_key_control *kcontrol, int scope, int no_rsets, RSET *rsets)
static RSFD r_open_andor(RSET ct, int flag, int is_and)
static RSFD r_open_or(RSET ct, int flag)
static int heap_cmp(HEAP h, int x, int y)
static void heap_clear(HEAP h)
static int r_forward_or(RSFD rfd, void *buf, TERMID *term, const void *untilbuf)
static const struct rset_control control_or
static void r_get_terms(RSET ct, TERMID *terms, int maxterms, int *curterm)
static RSFD r_open_and(RSET ct, int flag)
static void r_delete(RSET ct)
static void heap_swap(HEAP h, int x, int y)
static int heap_empty(HEAP h)
static void r_pos_x(RSFD rfd, double *current, double *total, int and_op)
static int r_read_and(RSFD rfd, void *buf, TERMID *term)
reads one item key from an 'and' set
static const struct rset_control control_and
static int r_read_or(RSFD rfd, void *buf, TERMID *term)
reads one item key from an 'or' set
static void heap_destroy(HEAP h)
static void r_pos_or(RSFD rfd, double *current, double *total)
static void heap_balance(HEAP h)
puts item into heap. The heap root element has changed value (to bigger) Swap downwards until the hea...
static void heap_insert(HEAP h, struct heap_item *hi)
static HEAP heap_create(NMEM nmem, int size, const struct rset_key_control *kctrl)
static int log_level_initialized
static void heap_delete(HEAP h)
deletes the first item in the heap, and balances the rest
static void r_close(RSFD rfd)
const struct rset_key_control * kctrl
int(* cmp)(const void *p1, const void *p2)
zint(* get_segment)(const void *p)
struct rset_key_control * keycontrol