Author: rooneg
Date: Mon Feb 28 16:37:21 2005
New Revision: 155723
URL: http://svn.apache.org/viewcvs?view=rev&rev=155723
Log:
Finish fixing up boolean queries containing should occurances.
If we have should queries then we can't just bail the first time one of
the scorers returns EOF, if it was a should scorer then we remove that
scorer from our set of candidates and move on, until we run out of should
scorers, at which point we're done.
* src/search/scorer.c
(boolean_search_scorer_t): add should_left member to track the number
of should scorers left.
(pick_scorer): deal with the fact that should scorers can be NULL.
(boolean_scorer_find_doc): handle EOF errors more carefully, deal
with the fact that should scorers can be NULL.
(lcn_boolean_scorer_create): initialize bsb->should_left.
* test/search/scorer_test.c
(test_boolean_scorer): remove out of date comment.
Modified:
incubator/lucene4c/trunk/src/search/scorer.c
incubator/lucene4c/trunk/test/search/scorer_test.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=155722&r2=155723
==============================================================================
--- incubator/lucene4c/trunk/src/search/scorer.c (original)
+++ incubator/lucene4c/trunk/src/search/scorer.c Mon Feb 28 16:37:21 2005
@@ -65,6 +65,9 @@
apr_array_header_t *should;
apr_array_header_t *must_not;
+ /* the number of should scorers we have left in the array */
+ int should_left;
+
/* the scorer we used last time through boolean_scorer_find_doc's main
* loop to get our initial document for comparisons. */
lcn_scorer_t *last_scorer;
@@ -102,6 +105,8 @@
lcn_scorer_t *scorer = APR_ARRAY_IDX (bsb->should,
i,
lcn_scorer_t *);
+ if (! scorer)
+ continue;
apr_uint32_t doc = lcn_scorer_doc (scorer);
@@ -139,7 +144,39 @@
/* 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_ERR (lcn_scorer_next (bsb->last_scorer));
+ {
+ 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;
+ }
/* when we add support for should scorers the selection of this
* scorer becomes more complex, but for now we can just pick an
@@ -158,6 +195,8 @@
lcn_scorer_t *should_scorer = APR_ARRAY_IDX (bsb->should,
i,
lcn_scorer_t *);
+ if (! should_scorer)
+ continue;
apr_uint32_t otherdoc = lcn_scorer_doc (should_scorer);
@@ -267,6 +306,8 @@
sizeof (lcn_scorer_t *));
LCN_ERR (fill_scorers_array (should, bsb->should, index, pool));
+
+ bsb->should_left = should->nelts;
bsb->must_not = apr_array_make (pool,
must_not->nelts,
Modified: incubator/lucene4c/trunk/test/search/scorer_test.c
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/test/search/scorer_test.c?view=diff&r1=155722&r2=155723
==============================================================================
--- incubator/lucene4c/trunk/test/search/scorer_test.c (original)
+++ incubator/lucene4c/trunk/test/search/scorer_test.c Mon Feb 28 16:37:21 2005
@@ -174,7 +174,6 @@
ABTS_INT_EQUAL (tc, APR_EOF, err->apr_err);
- /* expected to fail for now, should queries aren't quite working yet */
ABTS_INT_EQUAL (tc, 113, count);
apr_pool_clear (p);