lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sim...@apache.org
Subject svn commit: r1436859 - in /lucene/dev/trunk/lucene: CHANGES.txt core/src/java/org/apache/lucene/search/FilteredQuery.java core/src/test/org/apache/lucene/search/TestFilteredQuery.java
Date Tue, 22 Jan 2013 12:08:31 GMT
Author: simonw
Date: Tue Jan 22 12:08:30 2013
New Revision: 1436859

URL: http://svn.apache.org/viewvc?rev=1436859&view=rev
Log:
LUCENE-4705: Pass on FilterStrategy in FilteredQuery if the filtered query is rewritten

Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFilteredQuery.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1436859&r1=1436858&r2=1436859&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Tue Jan 22 12:08:30 2013
@@ -64,6 +64,11 @@ New Features
 * LUCENE-4599: New oal.codecs.compressing.CompressingTermVectorsFormat which
   compresses term vectors into chunks of documents similarly to
   CompressingStoredFieldsFormat. (Adrien Grand)
+  
+Bug Fixes
+
+* LUCENE-4705: Pass on FilterStrategy in FilteredQuery if the filtered query is 
+  rewritten. (Simon Willnauer)
 
 ======================= Lucene 4.1.0 =======================
 

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java?rev=1436859&r1=1436858&r2=1436859&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java Tue
Jan 22 12:08:30 2013
@@ -344,7 +344,7 @@ public class FilteredQuery extends Query
     
     if (queryRewritten != query) {
       // rewrite to a new FilteredQuery wrapping the rewritten query
-      final Query rewritten = new FilteredQuery(queryRewritten, filter);
+      final Query rewritten = new FilteredQuery(queryRewritten, filter, strategy);
       rewritten.setBoost(this.getBoost());
       return rewritten;
     } else {
@@ -362,6 +362,11 @@ public class FilteredQuery extends Query
   public final Filter getFilter() {
     return filter;
   }
+  
+  /** Returns this FilteredQuery's {@link FilterStrategy} */
+  public FilterStrategy getFilterStrategy() {
+    return this.strategy;
+  }
 
   // inherit javadoc
   @Override

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFilteredQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFilteredQuery.java?rev=1436859&r1=1436858&r2=1436859&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFilteredQuery.java
(original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFilteredQuery.java
Tue Jan 22 12:08:30 2013
@@ -31,6 +31,7 @@ import org.apache.lucene.index.IndexRead
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.BooleanClause.Occur;
+import org.apache.lucene.search.FilteredQuery.FilterStrategy;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.DocIdBitSet;
@@ -341,11 +342,16 @@ public class TestFilteredQuery extends L
     }
   }
   
+  private FilterStrategy randomFilterStrategy() {
+    return randomFilterStrategy(random(), true);
+  }
+  
   private void assertRewrite(FilteredQuery fq, Class<? extends Query> clazz) throws
Exception {
     // assign crazy boost to FQ
     final float boost = random().nextFloat() * 100.f;
     fq.setBoost(boost);
     
+    
     // assign crazy boost to inner
     final float innerBoost = random().nextFloat() * 100.f;
     fq.getQuery().setBoost(innerBoost);
@@ -356,6 +362,7 @@ public class TestFilteredQuery extends L
     if (rewritten instanceof FilteredQuery) {
       assertEquals(boost, rewritten.getBoost(), 1.E-5f);
       assertEquals(innerBoost, ((FilteredQuery) rewritten).getQuery().getBoost(), 1.E-5f);
+      assertEquals(fq.getFilterStrategy(), ((FilteredQuery) rewritten).getFilterStrategy());
     } else {
       assertEquals(boost * innerBoost, rewritten.getBoost(), 1.E-5f);
     }
@@ -366,8 +373,15 @@ public class TestFilteredQuery extends L
   }
 
   public void testRewrite() throws Exception {
-    assertRewrite(new FilteredQuery(new TermQuery(new Term("field", "one")), new PrefixFilter(new
Term("field", "o"))), FilteredQuery.class);
-    assertRewrite(new FilteredQuery(new MatchAllDocsQuery(), new PrefixFilter(new Term("field",
"o"))), ConstantScoreQuery.class);
+    assertRewrite(new FilteredQuery(new TermQuery(new Term("field", "one")), new PrefixFilter(new
Term("field", "o")), randomFilterStrategy()), FilteredQuery.class);
+    assertRewrite(new FilteredQuery(new PrefixQuery(new Term("field", "one")), new PrefixFilter(new
Term("field", "o")), randomFilterStrategy()), FilteredQuery.class);
+    assertRewrite(new FilteredQuery(new MatchAllDocsQuery(), new PrefixFilter(new Term("field",
"o")), randomFilterStrategy()), ConstantScoreQuery.class);
+  }
+  
+  public void testGetFilterStrategy() {
+    FilterStrategy randomFilterStrategy = randomFilterStrategy();
+    FilteredQuery filteredQuery = new FilteredQuery(new TermQuery(new Term("field", "one")),
new PrefixFilter(new Term("field", "o")), randomFilterStrategy);
+    assertSame(randomFilterStrategy, filteredQuery.getFilterStrategy());
   }
   
   private static FilteredQuery.FilterStrategy randomFilterStrategy(Random random, final boolean
useRandomAccess) {



Mime
View raw message