Author: rooneg
Date: Sat Feb 26 12:42:51 2005
New Revision: 155581
URL: http://svn.apache.org/viewcvs?view=rev&rev=155581
Log:
Clarify some of the boolean scorer code and handle the case where someone
tries to use a boolean query that hasn't had any queries added to it yet.
* src/search/scorer.c
(boolean_scorer_find_doc): handle error cases better, stop duplicating so
much code.
* test/search/scorer_test.c
(test_boolean_scorer): add a test for the case where the query hasn't had
any subqueries added to it yet, note a place we should have more tests,
and add a comment that describes what we're expecting to see.
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=155580&r2=155581
==============================================================================
--- incubator/lucene4c/trunk/src/search/scorer.c (original)
+++ incubator/lucene4c/trunk/src/search/scorer.c Sat Feb 26 12:42:51 2005
@@ -74,41 +74,52 @@
if (bsb->must_not->nelts)
return lcn_error_create (APR_ENOTIMPL, NULL, "must_not isn't implemented");
- for (;;)
+ if (bsb->must->nelts != 0)
{
- int i;
-
- *doc = lcn_scorer_doc (APR_ARRAY_IDX (bsb->must, 0, lcn_scorer_t *));
+ for (;;)
+ {
+ lcn_boolean_t got_a_hit = TRUE;
+ int i;
- /* XXX make sure that calling lcn_scorer_next isn't making us bail
- * without checking the final doc in the scorer... */
+ *doc = lcn_scorer_doc (APR_ARRAY_IDX (bsb->must, 0, lcn_scorer_t *));
- LCN_ERR (lcn_scorer_next (APR_ARRAY_IDX (bsb->must, 0, lcn_scorer_t *)));
+ /* XXX make sure that calling lcn_scorer_next isn't making us bail
+ * without checking the final doc in the scorer... */
- for (i = 1; i < bsb->must->nelts; ++i)
- {
- apr_uint32_t otherdoc
- = lcn_scorer_doc (APR_ARRAY_IDX (bsb->must, i, lcn_scorer_t *));
+ LCN_ERR (lcn_scorer_next (APR_ARRAY_IDX (bsb->must,
+ 0,
+ lcn_scorer_t *)));
- while (otherdoc < *doc)
+ for (i = 1; i < bsb->must->nelts; ++i)
{
- LCN_ERR (lcn_scorer_next (APR_ARRAY_IDX (bsb->must,
- i,
- lcn_scorer_t *)));
-
- otherdoc
- = lcn_scorer_doc (APR_ARRAY_IDX (bsb->must,
- i,
- lcn_scorer_t *));
+ lcn_scorer_t *must_scorer = APR_ARRAY_IDX (bsb->must,
+ i,
+ lcn_scorer_t *);
+
+ apr_uint32_t otherdoc = lcn_scorer_doc (must_scorer);
+
+ while (otherdoc < *doc)
+ {
+ LCN_ERR (lcn_scorer_next (must_scorer));
+
+ otherdoc = lcn_scorer_doc (must_scorer);
+ }
+
+ if (otherdoc != *doc)
+ {
+ got_a_hit = FALSE;
+ break;
+ }
}
- if (otherdoc != *doc)
- break;
+ if (got_a_hit)
+ return LCN_NO_ERROR;
}
-
- if (i == bsb->must->nelts)
- return LCN_NO_ERROR;
}
+ else
+ return lcn_error_create (APR_EINVAL,
+ NULL,
+ "boolean query needs at least one subquery");
}
static lcn_error_t *
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=155580&r2=155581
==============================================================================
--- incubator/lucene4c/trunk/test/search/scorer_test.c (original)
+++ incubator/lucene4c/trunk/test/search/scorer_test.c Sat Feb 26 12:42:51 2005
@@ -76,6 +76,15 @@
CHK_ERR (lcn_boolean_query_create (&query, p));
+ /* should fail if we don't have any queries added */
+ err = lcn_query_scorer (&scorer, query, index, p);
+
+ ABTS_PTR_NOTNULL (tc, err);
+
+ ABTS_INT_EQUAL (tc, APR_EINVAL, err->apr_err);
+
+ lcn_error_clear (err);
+
CHK_ERR (lcn_term_query_create (&tquery,
lcn_term_create_cstring ("lucene",
"contents",
@@ -84,6 +93,8 @@
CHK_ERR (lcn_boolean_query_add (query, tquery, LCN_MUST));
+ /* XXX test this point, should be identical to just using the term query. */
+
CHK_ERR (lcn_term_query_create (&tquery,
lcn_term_create_cstring ("cutting",
"contents",
@@ -92,6 +103,7 @@
CHK_ERR (lcn_boolean_query_add (query, tquery, LCN_MUST));
+ /* now we should get results that contain both 'lucene' 'cutting' */
CHK_ERR (lcn_query_scorer (&scorer, query, index, p));
ABTS_INT_EQUAL (tc, 40, lcn_scorer_doc (scorer));