Author: rooneg
Date: Tue Mar 1 05:46:20 2005
New Revision: 155777
URL: http://svn.apache.org/viewcvs?view=rev&rev=155777
Log:
Extract our code for advancing a scorer without prematurely bailing if
we hit EOF on a should scorer into a new function, which needs to be used
in one other spot where we could in theory hit that sort of situation.
* src/search/scorer.c
(carefully_advance_scorer): new helper function.
(pick_scorer): use carefully_advance_scorer.
(boolean_scorer_find_doc): ditto, plus add a comment about a potential
optimization.
Modified:
incubator/lucene4c/trunk/src/search/scorer.c
Modified: incubator/lucene4c/trunk/src/search/scorer.c
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/src/search/scorer.c?view=diff&r1=155776&r2=155777
==============================================================================
--- incubator/lucene4c/trunk/src/search/scorer.c (original)
+++ incubator/lucene4c/trunk/src/search/scorer.c Tue Mar 1 05:46:20 2005
@@ -73,6 +73,45 @@
lcn_scorer_t *last_scorer;
} boolean_scorer_baton_t;
+static lcn_error_t *
+carefully_advance_scorer (boolean_scorer_baton_t *bsb, lcn_scorer_t *scorer)
+{
+ lcn_error_t *err = lcn_scorer_next (scorer);
+
+ /* If we get an EOF we need to be careful... If there are any
+ * should scorers then we have to check to see if this was one
+ * of them, and if it was we don't bail out, instead we remove
+ * it from the array and reduce our count, if we hit zero then
+ * we're done with all the shoulds and that means we are done,
+ * otherwise clear the error and continue looping. */
+
+ if (err && err->apr_err == APR_EOF && bsb->should_left > 0)
+ {
+ lcn_boolean_t its_a_should = FALSE;
+ int i;
+
+ for (i = 0; i < bsb->should->nelts; ++i)
+ {
+ if (APR_ARRAY_IDX (bsb->should, i, lcn_scorer_t *) == scorer)
+ {
+ APR_ARRAY_IDX (bsb->should, i, lcn_scorer_t *) = NULL;
+ bsb->should_left--;
+ its_a_should = TRUE;
+ }
+ }
+
+ if (bsb->should_left == 0 || its_a_should == FALSE)
+ return err;
+ else
+ {
+ lcn_error_clear (err);
+ return LCN_NO_ERROR;
+ }
+ }
+
+ return err;
+}
+
/* select the scorer from which we should pull our initial candidate doc. */
static lcn_error_t *
pick_scorer (boolean_scorer_baton_t *bsb)
@@ -117,10 +156,8 @@
}
else if (doc == lowest)
{
- /* move on to avoid duplicates next time around...
- *
- * XXX couldn't this move us past the last hit? */
- LCN_ERR (lcn_scorer_next (scorer));
+ /* move on to avoid duplicates next time around... */
+ LCN_ERR (carefully_advance_scorer (bsb, scorer));
}
}
}
@@ -146,39 +183,7 @@
/* if we have a last scorer (i.e. we already came through this
* function already) move it along to the next document. */
if (bsb->last_scorer != NULL)
- {
- lcn_error_t *err = lcn_scorer_next (bsb->last_scorer);
-
- /* If we get an EOF we need to be careful... If there are any
- * should scorers then we have to check to see if this was one
- * of them, and if it was we don't bail out, instead we remove
- * it from the array and reduce our count, if we hit zero then
- * we're done with all the shoulds and that means we are done,
- * otherwise clear the error and continue looping. */
-
- if (err && err->apr_err == APR_EOF && bsb->should_left > 0)
- {
- lcn_boolean_t its_a_should = FALSE;
-
- for (i = 0; i < bsb->should->nelts; ++i)
- {
- if (APR_ARRAY_IDX (bsb->should, i, lcn_scorer_t *)
- == bsb->last_scorer)
- {
- APR_ARRAY_IDX (bsb->should, i, lcn_scorer_t *) = NULL;
- bsb->should_left--;
- its_a_should = TRUE;
- }
- }
-
- if (bsb->should_left == 0 || its_a_should == FALSE)
- return err;
- else
- lcn_error_clear (err);
- }
- else if (err)
- return err;
- }
+ LCN_ERR (carefully_advance_scorer (bsb, bsb->last_scorer));
LCN_ERR (pick_scorer (bsb));
@@ -189,6 +194,8 @@
if (bsb->should->nelts)
got_a_hit = FALSE;
+ /* it seems like we should be able to avoid this loop entirely if we
+ * knew for sure that our initial pick was from a should scorer... */
for (i = 0; i < bsb->should->nelts; ++i)
{
lcn_scorer_t *should_scorer = APR_ARRAY_IDX (bsb->should,