projects
/
idzebra-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Ignore config.h stuff
[idzebra-moved-to-github.git]
/
rset
/
rsmultiandor.c
diff --git
a/rset/rsmultiandor.c
b/rset/rsmultiandor.c
index
49bcea2
..
fd7ed2b
100644
(file)
--- a/
rset/rsmultiandor.c
+++ b/
rset/rsmultiandor.c
@@
-1,8
+1,5
@@
-/* $Id: rsmultiandor.c,v 1.23 2006-07-04 14:10:31 adam Exp $
- Copyright (C) 1995-2006
- Index Data ApS
-
-This file is part of the Zebra server.
+/* This file is part of the Zebra server.
+ Copyright (C) 1994-2011 Index Data
Zebra is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Zebra is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
@@
-15,9
+12,9
@@
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
-along with Zebra; see the file LICENSE.zebra. If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
*/
*/
@@
-35,6
+32,9
@@
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
*/
*/
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
@@
-55,7
+55,8
@@
static int r_forward_and(RSFD rfd, void *buf, TERMID *term,
const void *untilbuf);
static int r_forward_or(RSFD rfd, void *buf, TERMID *term,
const void *untilbuf);
const void *untilbuf);
static int r_forward_or(RSFD rfd, void *buf, TERMID *term,
const void *untilbuf);
-static void r_pos (RSFD rfd, double *current, double *total);
+static void r_pos_and(RSFD rfd, double *current, double *total);
+static void r_pos_or(RSFD rfd, double *current, double *total);
static void r_get_terms(RSET ct, TERMID *terms, int maxterms, int *curterm);
static const struct rset_control control_or =
static void r_get_terms(RSET ct, TERMID *terms, int maxterms, int *curterm);
static const struct rset_control control_or =
@@
-66,7
+67,7
@@
static const struct rset_control control_or =
r_open_or,
r_close,
r_forward_or,
r_open_or,
r_close,
r_forward_or,
- r_pos,
+ r_pos_or,
r_read_or,
r_write,
};
r_read_or,
r_write,
};
@@
-79,7
+80,7
@@
static const struct rset_control control_and =
r_open_and,
r_close,
r_forward_and,
r_open_and,
r_close,
r_forward_and,
- r_pos,
+ r_pos_and,
r_read_and,
r_write,
};
r_read_and,
r_write,
};
@@
-442,7
+443,6
@@
static int r_read_or (RSFD rfd, void *buf, TERMID *term)
*term = rset->term;
else
*term = it->term;
*term = rset->term;
else
*term = it->term;
- assert(*term);
}
(mrfd->hits)++;
rdres = rset_read(it->fd, it->buf, &it->term);
}
(mrfd->hits)++;
rdres = rset_read(it->fd, it->buf, &it->term);
@@
-495,9
+495,7
@@
static int r_read_and (RSFD rfd, void *buf, TERMID *term)
mintail = i;
if (kctrl->get_segment)
mintail = i;
if (kctrl->get_segment)
- {
- /* segments enabled */
-
+ { /* segments enabled */
zint segment = kctrl->get_segment(p->items[i].buf);
/* store segment if not stored already */
if (!p->segment && segment)
zint segment = kctrl->get_segment(p->items[i].buf);
/* store segment if not stored already */
if (!p->segment && segment)
@@
-532,10
+530,11
@@
static int r_read_and (RSFD rfd, void *buf, TERMID *term)
}
if (p->skip)
continue; /* skip again.. eventually tailcount will be 0 */
}
if (p->skip)
continue; /* skip again.. eventually tailcount will be 0 */
- (p->hits)++;
+ if (p->tailcount == 0)
+ (p->hits)++;
return 1;
}
return 1;
}
- /* not tailing, forward until all reocrds match, and set up */
+ /* not tailing, forward until all records match, and set up */
/* as tails. the earlier 'if' will then return the hits */
if (p->eof)
return 0; /* nothing more to see */
/* as tails. the earlier 'if' will then return the hits */
if (p->eof)
return 0; /* nothing more to see */
@@
-610,21
+609,34
@@
static int r_forward_and(RSFD rfd, void *buf, TERMID *term,
return r_read_and(rfd,buf,term);
}
return r_read_and(rfd,buf,term);
}
-static void r_pos (RSFD rfd, double *current, double *total)
+static void r_pos_x(RSFD rfd, double *current, double *total, int and_op)
{
RSET ct = rfd->rset;
struct rfd_private *mrfd =
(struct rfd_private *)(rfd->priv);
{
RSET ct = rfd->rset;
struct rfd_private *mrfd =
(struct rfd_private *)(rfd->priv);
- double cur, tot;
- double scur = 0.0, stot = 0.0;
+ double ratio = and_op ? 0.0 : 1.0;
int i;
int i;
+ double sum_cur = 0.0;
+ double sum_tot = 0.0;
for (i = 0; i<ct->no_children; i++){
for (i = 0; i<ct->no_children; i++){
+ double nratio, cur, tot;
rset_pos(mrfd->items[i].fd, &cur, &tot);
rset_pos(mrfd->items[i].fd, &cur, &tot);
- yaz_log(log_level, "r_pos: %d %0.1f %0.1f", i, cur,tot);
- scur += cur;
- stot += tot;
+ yaz_log(log_level, "r_pos: %d %0.1f %0.1f", i, cur,tot);
+ nratio = cur / tot;
+ if (and_op)
+ {
+ if (nratio > ratio)
+ ratio = nratio;
+ }
+ else
+ {
+ sum_cur += cur;
+ sum_tot += tot;
+ }
}
}
- if (stot < 1.0) { /* nothing there */
+ if (!and_op)
+ ratio = sum_cur / sum_tot;
+ if (ratio == 0.0 || ratio == 1.0) { /* nothing there */
*current = 0;
*total = 0;
yaz_log(log_level, "r_pos: NULL %0.1f %0.1f", *current, *total);
*current = 0;
*total = 0;
yaz_log(log_level, "r_pos: NULL %0.1f %0.1f", *current, *total);
@@
-632,11
+644,21
@@
static void r_pos (RSFD rfd, double *current, double *total)
else
{
*current = (double) (mrfd->hits);
else
{
*current = (double) (mrfd->hits);
- *total = *current*stot/scur;
+ *total = *current / ratio;
yaz_log(log_level, "r_pos: = %0.1f %0.1f", *current, *total);
}
}
yaz_log(log_level, "r_pos: = %0.1f %0.1f", *current, *total);
}
}
+static void r_pos_and(RSFD rfd, double *current, double *total)
+{
+ r_pos_x(rfd, current, total, 1);
+}
+
+static void r_pos_or(RSFD rfd, double *current, double *total)
+{
+ r_pos_x(rfd, current, total, 0);
+}
+
static int r_write (RSFD rfd, const void *buf)
{
yaz_log (YLOG_FATAL, "multior set type is read-only");
static int r_write (RSFD rfd, const void *buf)
{
yaz_log (YLOG_FATAL, "multior set type is read-only");
@@
-672,6
+694,7
@@
static void r_get_terms(RSET ct, TERMID *terms, int maxterms, int *curterm)
/*
* Local variables:
* c-basic-offset: 4
/*
* Local variables:
* c-basic-offset: 4
+ * c-file-style: "Stroustrup"
* indent-tabs-mode: nil
* End:
* vim: shiftwidth=4 tabstop=8 expandtab
* indent-tabs-mode: nil
* End:
* vim: shiftwidth=4 tabstop=8 expandtab