lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpou...@apache.org
Subject svn commit: r1636827 - in /lucene/dev/trunk/lucene/core/src: java/org/apache/lucene/search/FieldValueFilter.java test/org/apache/lucene/search/TestFieldValueFilter.java
Date Wed, 05 Nov 2014 09:04:53 GMT
Author: jpountz
Date: Wed Nov  5 09:04:53 2014
New Revision: 1636827

URL: http://svn.apache.org/r1636827
Log:
LUCENE-6038: Re-enable FieldValueFilter optimizations based on the way the docsWithField bits
are implemented.

Modified:
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/FieldValueFilter.java
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFieldValueFilter.java

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/FieldValueFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/FieldValueFilter.java?rev=1636827&r1=1636826&r2=1636827&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/FieldValueFilter.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/FieldValueFilter.java Wed
Nov  5 09:04:53 2014
@@ -20,6 +20,8 @@ import java.io.IOException;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.DocValues;
+import org.apache.lucene.util.BitDocIdSet;
+import org.apache.lucene.util.BitSet;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.Bits.MatchAllBits;
 import org.apache.lucene.util.Bits.MatchNoBits;
@@ -93,10 +95,10 @@ public class FieldValueFilter extends Fi
       if (docsWithField instanceof MatchNoBits) {
         return null;
       }
-      if (docsWithField instanceof DocIdSet) {
+      if (docsWithField instanceof BitSet) {
         // UweSays: this is always the case for our current impl - but who knows
         // :-)
-        return BitsFilteredDocIdSet.wrap((DocIdSet) docsWithField, acceptDocs);
+        return BitsFilteredDocIdSet.wrap(new BitDocIdSet((BitSet) docsWithField), acceptDocs);
       }
       return new DocValuesDocIdSet(context.reader().maxDoc(), acceptDocs) {
         @Override

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFieldValueFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFieldValueFilter.java?rev=1636827&r1=1636826&r2=1636827&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFieldValueFilter.java
(original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFieldValueFilter.java
Wed Nov  5 09:04:53 2014
@@ -23,12 +23,20 @@ import org.apache.lucene.document.Docume
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.SortedDocValuesField;
 import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.FilterLeafReader;
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.LeafReader;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.BitDocIdSet;
+import org.apache.lucene.util.BitSet;
+import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.FixedBitSet;
 import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.SparseFixedBitSet;
 
 /**
  * 
@@ -77,8 +85,8 @@ public class TestFieldValueFilter extend
     }
     IndexReader reader = DirectoryReader.open(directory);
     IndexSearcher searcher = newSearcher(reader);
-    TopDocs search = searcher.search(new TermQuery(new Term("all", "test")),
-        new FieldValueFilter("some"), docs);
+    Filter filter = new FieldValueFilter("some");
+    TopDocs search = searcher.search(new TermQuery(new Term("all", "test")), filter, docs);
     assertEquals(search.totalHits, numDocsWithValue);
     
     ScoreDoc[] scoreDocs = search.scoreDocs;
@@ -90,6 +98,48 @@ public class TestFieldValueFilter extend
     directory.close();
   }
 
+  public void testOptimizations() throws IOException {
+    Directory directory = newDirectory();
+    RandomIndexWriter writer = new RandomIndexWriter(random(), directory,
+        newIndexWriterConfig(new MockAnalyzer(random())));
+    final int docs = atLeast(10);
+    buildIndex(writer, docs);
+    IndexReader reader = DirectoryReader.open(directory);
+    LeafReader leafReader = reader.leaves().get(0).reader();
+    
+    FilterLeafReader filterReader = new FilterLeafReader(leafReader) {
+      @Override
+      public Bits getDocsWithField(String field) throws IOException {
+        switch (field) {
+          case "with_matchall":
+            return new Bits.MatchAllBits(maxDoc());
+          case "with_matchno":
+            return new Bits.MatchNoBits(maxDoc());
+          case "with_bitset":
+            BitSet b = random().nextBoolean() ? new SparseFixedBitSet(maxDoc()) : new FixedBitSet(maxDoc());
+            b.set(random().nextInt(maxDoc()));
+            return b;
+        }
+        return super.getDocsWithField(field);
+      }
+    };
+
+    Filter filter = new FieldValueFilter("with_matchall", true);
+    DocIdSet set = filter.getDocIdSet(filterReader.getContext(), null);
+    assertNull(set);
+
+    filter = new FieldValueFilter("with_matchno");
+    set = filter.getDocIdSet(filterReader.getContext(), null);
+    assertNull(set);
+
+    filter = new FieldValueFilter("with_bitset");
+    set = filter.getDocIdSet(filterReader.getContext(), null);
+    assertTrue(set instanceof BitDocIdSet);
+
+    reader.close();
+    directory.close();
+  }
+
   private int[] buildIndex(RandomIndexWriter writer, int docs)
       throws IOException {
     int[] docStates = new int[docs];



Mime
View raw message