Author: rooneg
Date: Mon Mar  7 19:18:43 2005
New Revision: 156489

URL: http://svn.apache.org/viewcvs?view=rev&rev=156489
Log:
If there are any 'must' clauses in a boolean query then the 'should'
clauses are pointless, so don't even bother running them.  This fixes
boolean queries that contain some must and some should queries.

* src/search/scorer.c
  (lcn_boolean_scorer_create): drop should scorers if we have any must
   scorers.

* test/search/scorer_test.c
  (test_boolean_scorer): add a test for a search with one must and one
   should query.

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=156488&r2=156489
==============================================================================
--- incubator/lucene4c/trunk/src/search/scorer.c (original)
+++ incubator/lucene4c/trunk/src/search/scorer.c Mon Mar  7 19:18:43 2005
@@ -326,9 +326,12 @@
                                 should->nelts,
                                 sizeof (lcn_scorer_t *));
 
-  LCN_ERR (fill_scorers_array (should, bsb->should, index, pool));
+  if (must->nelts == 0)
+    {
+      LCN_ERR (fill_scorers_array (should, bsb->should, index, pool));
 
-  bsb->should_left = should->nelts;
+      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=156488&r2=156489
==============================================================================
--- incubator/lucene4c/trunk/test/search/scorer_test.c (original)
+++ incubator/lucene4c/trunk/test/search/scorer_test.c Mon Mar  7 19:18:43 2005
@@ -182,6 +182,40 @@
 
   ABTS_INT_EQUAL (tc, 113, count);
 
+  /* now let's try a mixed query, one must and one should... */
+  CHK_ERR (lcn_boolean_query_create (&query, p));
+
+  CHK_ERR (lcn_term_query_create (&tquery,
+                                  lcn_term_create_cstring ("lucene",
+                                                           "contents",
+                                                           p),
+                                  p));
+
+  CHK_ERR (lcn_boolean_query_add (query, tquery, LCN_SHOULD));
+
+  CHK_ERR (lcn_term_query_create (&tquery,
+                                  lcn_term_create_cstring ("cutting",
+                                                           "contents",
+                                                           p),
+                                  p));
+
+  CHK_ERR (lcn_boolean_query_add (query, tquery, LCN_MUST));
+
+  CHK_ERR (lcn_query_scorer (&scorer, query, index, p));
+
+  count = 1;
+
+  while ((err = lcn_scorer_next (&next, scorer)) == LCN_NO_ERROR && next)
+    {
+      ++count;
+    }
+
+  ABTS_TRUE (tc, ! next);
+
+  ABTS_PTR_EQUAL (tc, LCN_NO_ERROR, err);
+
+  ABTS_INT_EQUAL (tc, 42, count);
+
   apr_pool_clear (p);
 }
 


Reply via email to