Author: rooneg
Date: Thu Mar 3 18:44:58 2005
New Revision: 156124
URL: http://svn.apache.org/viewcvs?view=rev&rev=156124
Log:
Finish cleaning up use of lcn_error_t as a way to exit loops.
This change removes the use of an APR_EOF error to exit a scorer result
loop, instead adding in a boolean parameter that signals the presence of
more results.
* include/lcn_scorer.h
(lcn_scorer_next): add boolean parameter, update doc.
* src/search/scorer.c
(scorer_next_internal_t): add boolean parameter.
(term_scorer_next_internal): ditto, plus remove code that returns an
error when we get FALSE back from lcn_doc_iter_next.
(carefully_advance_scorer): add boolean parameter, use it to see if
we have more results in the scorer.
(pick_scorer): add boolean parameter, passing it on to various other
functions that advance scorers, checking after each one to see if
we should bail out.
(boolean_scorer_next_internal): add boolean parameter, pass it on to
boolean_scorer_find_doc.
(lcn_boolean_scorer_create): update call to boolean_scorer_find_doc.
(lcn_scorer_next): add boolean parameter.
* test/search/scorer_test.c
(test_term_scorer, test_boolean_scorer): update for new APIs.
Modified:
incubator/lucene4c/trunk/include/lcn_scorer.h
incubator/lucene4c/trunk/src/search/scorer.c
incubator/lucene4c/trunk/test/search/scorer_test.c
Modified: incubator/lucene4c/trunk/include/lcn_scorer.h
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/include/lcn_scorer.h?view=diff&r1=156123&r2=156124
==============================================================================
--- incubator/lucene4c/trunk/include/lcn_scorer.h (original)
+++ incubator/lucene4c/trunk/include/lcn_scorer.h Thu Mar 3 18:44:58 2005
@@ -59,8 +59,12 @@
lcn_index_t *index,
apr_pool_t *pool);
-/** Advance @a scorer to the next document. */
-lcn_error_t * lcn_scorer_next (lcn_scorer_t *scorer);
+/** Advance @a scorer to the next document.
+ *
+ * If there is another document in the sequence @a next is set to TRUE,
+ * otherwise @a next is set to FALSE.
+ */
+lcn_error_t * lcn_scorer_next (lcn_boolean_t *next, lcn_scorer_t *scorer);
/** Return the current document for @a scorer. */
apr_uint32_t lcn_scorer_doc (lcn_scorer_t *scorer);
Modified: incubator/lucene4c/trunk/src/search/scorer.c
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/src/search/scorer.c?view=diff&r1=156123&r2=156124
==============================================================================
--- incubator/lucene4c/trunk/src/search/scorer.c (original)
+++ incubator/lucene4c/trunk/src/search/scorer.c Thu Mar 3 18:44:58 2005
@@ -17,7 +17,8 @@
#include "lcn_scorer.h"
#include "lcn_query.h"
-typedef lcn_error_t * (*scorer_next_internal_t) (lcn_scorer_t *scorer);
+typedef lcn_error_t * (*scorer_next_internal_t) (lcn_boolean_t *next,
+ lcn_scorer_t *scorer);
struct lcn_scorer_t {
apr_uint32_t doc;
@@ -29,25 +30,20 @@
};
static lcn_error_t *
-term_scorer_next_internal (lcn_scorer_t *scorer)
+term_scorer_next_internal (lcn_boolean_t *next, lcn_scorer_t *scorer)
{
lcn_doc_iter_t *iter = scorer->baton;
- lcn_boolean_t next;
- LCN_ERR (lcn_doc_iter_next (&next, iter));
+ LCN_ERR (lcn_doc_iter_next (next, iter));
- if (next)
+ if (*next)
{
scorer->doc = lcn_doc_iter_doc (iter);
scorer->score = 1.0; /* XXX */
-
- return LCN_NO_ERROR;
- }
- else
- {
- return lcn_error_create (APR_EOF, NULL, "no more terms");
}
+
+ return LCN_NO_ERROR;
}
lcn_error_t *
@@ -82,9 +78,11 @@
} boolean_scorer_baton_t;
static lcn_error_t *
-carefully_advance_scorer (boolean_scorer_baton_t *bsb, lcn_scorer_t *scorer)
+carefully_advance_scorer (lcn_boolean_t *next,
+ boolean_scorer_baton_t *bsb,
+ lcn_scorer_t *scorer)
{
- lcn_error_t *err = lcn_scorer_next (scorer);
+ LCN_ERR (lcn_scorer_next (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
@@ -93,7 +91,7 @@
* 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)
+ if ((! *next) && bsb->should_left > 0)
{
lcn_boolean_t its_a_should = FALSE;
int i;
@@ -109,20 +107,17 @@
}
if (bsb->should_left == 0 || its_a_should == FALSE)
- return err;
+ *next = FALSE;
else
- {
- lcn_error_clear (err);
- return LCN_NO_ERROR;
- }
+ *next = TRUE;
}
- return err;
+ return LCN_NO_ERROR;
}
/* select the scorer from which we should pull our initial candidate doc. */
static lcn_error_t *
-pick_scorer (boolean_scorer_baton_t *bsb)
+pick_scorer (lcn_boolean_t *next, boolean_scorer_baton_t *bsb)
{
if (bsb->must->nelts == 0
&& bsb->should->nelts == 0
@@ -165,7 +160,7 @@
else if (doc == lowest)
{
/* move on to avoid duplicates next time around... */
- LCN_ERR (carefully_advance_scorer (bsb, scorer));
+ LCN_ERR (carefully_advance_scorer (next, bsb, scorer));
}
}
}
@@ -181,7 +176,9 @@
}
static lcn_error_t *
-boolean_scorer_find_doc (apr_uint32_t *doc, boolean_scorer_baton_t *bsb)
+boolean_scorer_find_doc (lcn_boolean_t *next,
+ apr_uint32_t *doc,
+ boolean_scorer_baton_t *bsb)
{
for (;;)
{
@@ -191,9 +188,12 @@
/* 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 (carefully_advance_scorer (bsb, bsb->last_scorer));
+ LCN_ERR (carefully_advance_scorer (next, bsb, bsb->last_scorer));
- LCN_ERR (pick_scorer (bsb));
+ LCN_ERR (pick_scorer (next, bsb));
+
+ if (! *next)
+ return LCN_NO_ERROR;
*doc = lcn_scorer_doc (bsb->last_scorer);
@@ -216,7 +216,10 @@
while (otherdoc < *doc)
{
- LCN_ERR (lcn_scorer_next (should_scorer));
+ LCN_ERR (lcn_scorer_next (next, should_scorer));
+
+ if (! *next)
+ return LCN_NO_ERROR;
otherdoc = lcn_scorer_doc (should_scorer);
}
@@ -241,7 +244,10 @@
while (otherdoc < *doc)
{
- LCN_ERR (lcn_scorer_next (must_scorer));
+ LCN_ERR (lcn_scorer_next (next, must_scorer));
+
+ if (! *next)
+ return LCN_NO_ERROR;
otherdoc = lcn_scorer_doc (must_scorer);
}
@@ -261,11 +267,11 @@
}
static lcn_error_t *
-boolean_scorer_next_internal (lcn_scorer_t *scorer)
+boolean_scorer_next_internal (lcn_boolean_t *next, lcn_scorer_t *scorer)
{
boolean_scorer_baton_t *bsb = scorer->baton;
- LCN_ERR (boolean_scorer_find_doc (&scorer->doc, bsb));
+ LCN_ERR (boolean_scorer_find_doc (next, &scorer->doc, bsb));
scorer->score = 1.0; /* XXX */
@@ -304,6 +310,7 @@
apr_pool_t *pool)
{
boolean_scorer_baton_t *bsb = apr_pcalloc (pool, sizeof (*bsb));
+ lcn_boolean_t next = TRUE;
*scorer = apr_pcalloc (pool, sizeof (lcn_scorer_t));
@@ -331,7 +338,10 @@
(*scorer)->next_internal = boolean_scorer_next_internal;
- LCN_ERR (boolean_scorer_find_doc (&(*scorer)->doc, bsb));
+ LCN_ERR (boolean_scorer_find_doc (&next, &(*scorer)->doc, bsb));
+
+ if (! next)
+ return lcn_error_create (APR_ENOENT, NULL, "query didn't match");
(*scorer)->score = 1.0; /* XXX */
@@ -341,7 +351,7 @@
apr_uint32_t lcn_scorer_doc (lcn_scorer_t *scorer) { return scorer->doc; }
lcn_error_t *
-lcn_scorer_next (lcn_scorer_t *scorer)
+lcn_scorer_next (lcn_boolean_t *next, lcn_scorer_t *scorer)
{
- return scorer->next_internal (scorer);
+ return scorer->next_internal (next, scorer);
}
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=156123&r2=156124
==============================================================================
--- incubator/lucene4c/trunk/test/search/scorer_test.c (original)
+++ incubator/lucene4c/trunk/test/search/scorer_test.c Thu Mar 3 18:44:58 2005
@@ -25,6 +25,7 @@
test_term_scorer (abts_case *tc, void *data)
{
lcn_query_t *query;
+ lcn_boolean_t next;
lcn_scorer_t *scorer;
lcn_index_t *index;
lcn_error_t *err;
@@ -44,7 +45,7 @@
/* XXX check score */
- while ((err = lcn_scorer_next (scorer)) == LCN_NO_ERROR)
+ while ((err = lcn_scorer_next (&next, scorer)) == LCN_NO_ERROR && next)
{
if (++count == 1)
{
@@ -54,9 +55,9 @@
}
}
- ABTS_INT_EQUAL (tc, APR_EOF, err->apr_err);
+ ABTS_TRUE (tc, ! next);
- lcn_error_clear (err);
+ ABTS_PTR_EQUAL (tc, LCN_NO_ERROR, err);
ABTS_INT_EQUAL (tc, 75, count);
@@ -68,6 +69,7 @@
{
lcn_query_t *query, *tquery;
lcn_scorer_t *scorer;
+ lcn_boolean_t next;
lcn_index_t *index;
lcn_error_t *err;
int count = 0;
@@ -98,7 +100,7 @@
ABTS_INT_EQUAL (tc, 1, lcn_scorer_doc (scorer));
- while ((err = lcn_scorer_next (scorer)) == LCN_NO_ERROR)
+ while ((err = lcn_scorer_next (&next, scorer)) == LCN_NO_ERROR && next)
{
if (++count == 1)
{
@@ -106,7 +108,9 @@
}
}
- ABTS_INT_EQUAL (tc, APR_EOF, err->apr_err);
+ ABTS_TRUE (tc, ! next);
+
+ ABTS_PTR_EQUAL (tc, LCN_NO_ERROR, err);
ABTS_INT_EQUAL (tc, 75, count);
@@ -125,7 +129,7 @@
ABTS_INT_EQUAL (tc, 40, lcn_scorer_doc (scorer));
- while ((err = lcn_scorer_next (scorer)) == LCN_NO_ERROR)
+ while ((err = lcn_scorer_next (&next, scorer)) == LCN_NO_ERROR && next)
{
if (count == 0)
ABTS_INT_EQUAL (tc, 175, lcn_scorer_doc (scorer));
@@ -139,7 +143,9 @@
++count;
}
- ABTS_INT_EQUAL (tc, APR_EOF, err->apr_err);
+ ABTS_TRUE (tc, ! next);
+
+ ABTS_PTR_EQUAL (tc, LCN_NO_ERROR, err);
CHK_ERR (lcn_boolean_query_create (&query, p));
@@ -165,14 +171,14 @@
count = 0;
- while ((err = lcn_scorer_next (scorer)) == LCN_NO_ERROR)
+ while ((err = lcn_scorer_next (&next, scorer)) == LCN_NO_ERROR && next)
{
++count;
}
- ABTS_PTR_NOTNULL (tc, err);
+ ABTS_TRUE (tc, ! next);
- ABTS_INT_EQUAL (tc, APR_EOF, err->apr_err);
+ ABTS_PTR_EQUAL (tc, LCN_NO_ERROR, err);
ABTS_INT_EQUAL (tc, 113, count);