X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=rset%2Frssbool.c;h=c640952ef31c2b42f770d0f8a255336599fcfa10;hb=5f8ba9f35bd3c9aeafe26613021f2edd141b8611;hp=32855d38cb082865aaefae034a32ddba74e428be;hpb=7b0a5daa703117cde2dc0d54d5a39941a1c01ce8;p=idzebra-moved-to-github.git diff --git a/rset/rssbool.c b/rset/rssbool.c index 32855d3..c640952 100644 --- a/rset/rssbool.c +++ b/rset/rssbool.c @@ -1,10 +1,23 @@ /* - * Copyright (C) 1994-1995, Index Data I/S + * Copyright (C) 1994-1996, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: rssbool.c,v $ - * Revision 1.1 1995-12-11 09:15:27 adam + * Revision 1.5 1997-09-09 13:38:16 adam + * Partial port to WIN95/NT. + * + * Revision 1.4 1996/10/29 13:55:27 adam + * Include of zebrautl.h instead of alexutil.h. + * + * Revision 1.3 1996/10/08 13:00:41 adam + * Bug fix: result sets with ranked operands in boolean operations weren't + * sorted. + * + * Revision 1.2 1996/05/15 18:35:17 adam + * Implemented snot operation. + * + * Revision 1.1 1995/12/11 09:15:27 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. @@ -13,11 +26,12 @@ * */ -#include #include +#include +#include #include -#include +#include static void *r_create_and(const struct rset_control *sel, void *parms, int *flags); @@ -87,6 +101,7 @@ struct rset_bool_info { RSET rset_r; char *key_buf; int *score_buf; + int *score_idx; int key_no; int key_max; int (*cmp)(const void *p1, const void *p2); @@ -98,12 +113,21 @@ struct rset_bool_rfd { struct rset_bool_info *info; int position; int last_pos; - int open_flag; + int flag; }; static void *r_create_common (const struct rset_control *sel, rset_bool_parms *bool_parms, int *flags); - + +static struct rset_bool_info *qsort_info; + +static int qcomp (const void *p1, const void *p2) +{ + int i1 = *(int*) p1; + int i2 = *(int*) p2; + return qsort_info->score_buf[i2] - qsort_info->score_buf[i1]; +} + static void key_add (struct rset_bool_info *info, char *buf, int score) { @@ -112,6 +136,7 @@ static void key_add (struct rset_bool_info *info, memcpy (info->key_buf + info->key_size * info->key_no, buf, info->key_size); info->score_buf[info->key_no] = score; + info->score_idx[info->key_no] = info->key_no; (info->key_no)++; } @@ -161,19 +186,9 @@ static void *r_create_and (const struct rset_control *sel, void *parms, more_r = rset_read (info->rset_r, fd_r, buf_r); } else if (cmp > 1) - { - rset_score (info->rset_r, fd_r, &score_r); - if (score_r != -1) - key_add (info, buf_r, 1); more_r = rset_read (info->rset_r, fd_r, buf_r); - } else - { - rset_score (info->rset_l, fd_l, &score_l); - if (score_l != -1) - key_add (info, buf_l, 1); more_l = rset_read (info->rset_l, fd_l, buf_l); - } } rset_close (info->rset_l, fd_l); rset_close (info->rset_r, fd_r); @@ -181,6 +196,8 @@ static void *r_create_and (const struct rset_control *sel, void *parms, rset_delete (info->rset_r); xfree (buf_l); xfree (buf_r); + qsort_info = info; + qsort (info->score_idx, info->key_no, sizeof(*info->score_idx), qcomp); return info; } @@ -250,6 +267,8 @@ static void *r_create_or (const struct rset_control *sel, void *parms, rset_delete (info->rset_r); xfree (buf_l); xfree (buf_r); + qsort_info = info; + qsort (info->score_idx, info->key_no, sizeof(*info->score_idx), qcomp); return info; } @@ -257,16 +276,55 @@ static void *r_create_not (const struct rset_control *sel, void *parms, int *flags) { char *buf_l, *buf_r; + int more_l, more_r; + RSFD fd_l, fd_r; struct rset_bool_info *info; info = r_create_common (sel, parms, flags); buf_l = xmalloc (info->key_size); buf_r = xmalloc (info->key_size); + + fd_l = rset_open (info->rset_l, RSETF_SORT_SYSNO|RSETF_READ); + fd_r = rset_open (info->rset_r, RSETF_SORT_SYSNO|RSETF_READ); + + more_l = rset_read(info->rset_l, fd_l, buf_l); + more_r = rset_read(info->rset_r, fd_r, buf_r); + + while (more_l || more_r) + { + int cmp; + int score; + + if (more_l && more_r) + cmp = (*info->cmp)(buf_l, buf_r); + else if (more_r) + cmp = 2; + else + cmp = -2; + + if (cmp >= -1 && cmp <= 1) + more_l = rset_read (info->rset_l, fd_l, buf_l); + else if (cmp > 1) + { + more_r = rset_read (info->rset_r, fd_r, buf_r); + } + else + { + rset_score (info->rset_l, fd_l, &score); + key_add (info, buf_l, score == -1 ? 1 : score); + more_l = rset_read (info->rset_l, fd_l, buf_l); + } + } + rset_close (info->rset_l, fd_l); + rset_close (info->rset_r, fd_r); + rset_delete (info->rset_l); rset_delete (info->rset_r); xfree (buf_l); xfree (buf_r); + qsort_info = info; + qsort (info->score_idx, info->key_no, sizeof(*info->score_idx), qcomp); return info; } @@ -293,6 +351,7 @@ static void *r_create_common (const struct rset_control *sel, info->key_max = 1000; info->key_buf = xmalloc (info->key_size * info->key_max); info->score_buf = xmalloc (info->key_max * sizeof(*info->score_buf)); + info->score_idx = xmalloc (info->key_max * sizeof(*info->score_idx)); info->key_no = 0; return info; @@ -315,7 +374,7 @@ static RSFD r_open (RSET ct, int flag) rfd->position = 0; rfd->last_pos = 0; - rfd->open_flag = flag; + rfd->flag = flag; return rfd; } @@ -342,6 +401,7 @@ static void r_delete (RSET ct) assert (info->rfd_list == NULL); xfree (info->score_buf); + xfree (info->score_idx); xfree (info->key_buf); xfree (info); } @@ -368,7 +428,10 @@ static int r_read (RSFD rfd, void *buf) if (p->position >= info->key_no) return 0; - p->last_pos = (p->position)++; + if (p->flag & RSETF_SORT_RANK) + p->last_pos = info->score_idx[(p->position)++]; + else + p->last_pos = (p->position)++; memcpy (buf, info->key_buf + info->key_size * p->last_pos, info->key_size); return 1;