lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r808516 - /lucene/java/branches/lucene_2_4_back_compat_tests/src/test/org/apache/lucene/search/TestBooleanPrefixQuery.java
Date Thu, 27 Aug 2009 16:56:12 GMT
Author: mikemccand
Date: Thu Aug 27 16:56:12 2009
New Revision: 808516

URL: http://svn.apache.org/viewvc?rev=808516&view=rev
Log:
LUCENE-1860: default all multi-term queries to constant score auto

Modified:
    lucene/java/branches/lucene_2_4_back_compat_tests/src/test/org/apache/lucene/search/TestBooleanPrefixQuery.java

Modified: lucene/java/branches/lucene_2_4_back_compat_tests/src/test/org/apache/lucene/search/TestBooleanPrefixQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_4_back_compat_tests/src/test/org/apache/lucene/search/TestBooleanPrefixQuery.java?rev=808516&r1=808515&r2=808516&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_4_back_compat_tests/src/test/org/apache/lucene/search/TestBooleanPrefixQuery.java
(original)
+++ lucene/java/branches/lucene_2_4_back_compat_tests/src/test/org/apache/lucene/search/TestBooleanPrefixQuery.java
Thu Aug 27 16:56:12 2009
@@ -53,7 +53,22 @@
     super(name);
   }
 
-  public void testMethod() {
+  private int getCount(IndexReader r, Query q) throws Exception {
+    if (q instanceof BooleanQuery) {
+      return ((BooleanQuery) q).getClauses().length;
+    } else if (q instanceof ConstantScoreQuery) {
+      DocIdSetIterator iter = ((ConstantScoreQuery) q).getFilter().getDocIdSet(r).iterator();
+      int count = 0;
+      while(iter.next()) {
+        count++;
+      }
+      return count;
+    } else {
+      throw new RuntimeException("unepxected query " + q);
+    }
+  }
+
+  public void testMethod() throws Exception {
     RAMDirectory directory = new RAMDirectory();
 
     String[] categories = new String[]{"food",
@@ -63,6 +78,7 @@
 
     Query rw1 = null;
     Query rw2 = null;
+    IndexReader reader = null;
     try {
       IndexWriter writer = new IndexWriter(directory, new
                                            WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
@@ -73,9 +89,8 @@
       }
       writer.close();
       
-      IndexReader reader = IndexReader.open(directory);
+      reader = IndexReader.open(directory);
       PrefixQuery query = new PrefixQuery(new Term("category", "foo"));
-      
       rw1 = query.rewrite(reader);
       
       BooleanQuery bq = new BooleanQuery();
@@ -86,20 +101,7 @@
       fail(e.getMessage());
     }
 
-    BooleanQuery bq1 = null;
-    if (rw1 instanceof BooleanQuery) {
-      bq1 = (BooleanQuery) rw1;
-    }
-
-    BooleanQuery bq2 = null;
-    if (rw2 instanceof BooleanQuery) {
-        bq2 = (BooleanQuery) rw2;
-    } else {
-      fail("Rewrite");
-    }
-
-    assertEquals("Number of Clauses Mismatch", bq1.getClauses().length,
-                 bq2.getClauses().length);
+    assertEquals("Number of Clauses Mismatch", getCount(reader, rw1), getCount(reader, rw2));
   }
 }
 



Mime
View raw message