lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r990194 - /lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/search/TestBooleanQuery.java
Date Fri, 27 Aug 2010 16:23:14 GMT
Author: yonik
Date: Fri Aug 27 16:23:14 2010
New Revision: 990194

URL: http://svn.apache.org/viewvc?rev=990194&view=rev
Log:
LUCENE-2617: add tests for non-matching clauses and coord

Modified:
    lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/search/TestBooleanQuery.java

Modified: lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/search/TestBooleanQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/search/TestBooleanQuery.java?rev=990194&r1=990193&r2=990194&view=diff
==============================================================================
--- lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/search/TestBooleanQuery.java
(original)
+++ lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/search/TestBooleanQuery.java
Fri Aug 27 16:23:14 2010
@@ -64,11 +64,37 @@ public class TestBooleanQuery extends Lu
     Document doc = new Document();
     doc.add(new Field("field", "a b c d", Field.Store.NO, Field.Index.ANALYZED));
     w.addDocument(doc);
+
     IndexReader r = w.getReader();
     IndexSearcher s = new IndexSearcher(r);
     BooleanQuery q = new BooleanQuery();
     q.add(new TermQuery(new Term("field", "a")), BooleanClause.Occur.SHOULD);
 
+    // LUCENE-2617: make sure that a term not in the index still contributes to the score
via coord factor
+    float score = s.search(q, 10).getMaxScore();
+    Query subQuery = new TermQuery(new Term("field", "not_in_index"));
+    subQuery.setBoost(0);
+    q.add(subQuery, BooleanClause.Occur.SHOULD);
+    float score2 = s.search(q, 10).getMaxScore();
+    assertEquals(score*.5, score2, 1e-6);
+
+    // LUCENE-2617: make sure that a clause not in the index still contributes to the score
via coord factor
+    BooleanQuery qq = (BooleanQuery)q.clone();
+    PhraseQuery phrase = new PhraseQuery();
+    phrase.add(new Term("field", "not_in_index"));
+    phrase.add(new Term("field", "another_not_in_index"));
+    phrase.setBoost(0);
+    qq.add(phrase, BooleanClause.Occur.SHOULD);
+    score2 = s.search(qq, 10).getMaxScore();
+    assertEquals(score*(1.0/3), score2, 1e-6);
+
+    // now test BooleanScorer2
+    subQuery = new TermQuery(new Term("field", "b"));
+    subQuery.setBoost(0);
+    q.add(subQuery, BooleanClause.Occur.MUST);
+    score2 = s.search(q, 10).getMaxScore();
+    assertEquals(score*(2.0/3), score2, 1e-6);
+ 
     // PhraseQuery w/ no terms added returns a null scorer
     PhraseQuery pq = new PhraseQuery();
     q.add(pq, BooleanClause.Occur.SHOULD);



Mime
View raw message