Skip to content

Apache Lucene open-source search software

LUCENE-6649: Remove dependency of lucene/join on Filter.

Adrien Grand2919e13adc72
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 6cf590d9a67..f81e8d64f31 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -188,6 +188,10 @@ API Changes
* LUCENE-6646: Make EarlyTerminatingCollector take a Sort object directly
instead of a SortingMergePolicy. (Christine Poerschke via Adrien Grand)
+* LUCENE-6649: BitDocIdSetFilter and BitDocIdSetCachingWrapperFilter are now
+ deprecated in favour of BitSetProducer and QueryBitSetProducer, which do not
+ extend oal.search.Filter. (Adrien Grand)
+
Bug fixes
* LUCENE-6500: ParallelCompositeReader did not always call
diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java b/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
index 1b4bdb0b9b9..ddeee5438c7 100644
--- a/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
+++ b/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
@@ -81,8 +81,8 @@ import org.apache.lucene.search.TermRangeQuery;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.WildcardQuery;
import org.apache.lucene.search.highlight.SynonymTokenizer.TestHighlightRunner;
-import org.apache.lucene.search.join.BitDocIdSetCachingWrapperFilter;
-import org.apache.lucene.search.join.BitDocIdSetFilter;
+import org.apache.lucene.search.join.QueryBitSetProducer;
+import org.apache.lucene.search.join.BitSetProducer;
import org.apache.lucene.search.join.ScoreMode;
import org.apache.lucene.search.join.ToChildBlockJoinQuery;
import org.apache.lucene.search.join.ToParentBlockJoinQuery;
@@ -587,7 +587,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte
}
public void testToParentBlockJoinQuery() throws Exception {
- BitDocIdSetFilter parentFilter = new BitDocIdSetCachingWrapperFilter(
+ BitSetProducer parentFilter = new QueryBitSetProducer(
new QueryWrapperFilter(
new TermQuery(new Term(FIELD_NAME, "parent"))));
@@ -613,7 +613,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte
}
public void testToChildBlockJoinQuery() throws Exception {
- BitDocIdSetFilter parentFilter = new BitDocIdSetCachingWrapperFilter(
+ BitSetProducer parentFilter = new QueryBitSetProducer(
new QueryWrapperFilter(
new TermQuery(new Term(FIELD_NAME, "parent"))));
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/BitDocIdSetFilter.java b/lucene/join/src/java/org/apache/lucene/search/join/BitSetProducer.java
similarity index 52%
rename from lucene/join/src/java/org/apache/lucene/search/join/BitDocIdSetFilter.java
rename to lucene/join/src/java/org/apache/lucene/search/join/BitSetProducer.java
index 15709f65313..dfbc4f7883e 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/BitDocIdSetFilter.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/BitSetProducer.java
@@ -20,29 +20,17 @@ package org.apache.lucene.search.join;
import java.io.IOException;
import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.search.BitsFilteredDocIdSet;
-import org.apache.lucene.search.DocIdSet;
-import org.apache.lucene.search.Filter;
-import org.apache.lucene.util.BitDocIdSet;
-import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.BitSet;
/**
- * A {@link Filter} that produces {@link BitDocIdSet}s.
+ * A producer of {@link BitSet}s per segment.
*/
-public abstract class BitDocIdSetFilter extends Filter {
-
- /** Sole constructor, typically called from sub-classes. */
- protected BitDocIdSetFilter() {}
+public interface BitSetProducer {
/**
- * Same as {@link #getDocIdSet(LeafReaderContext, Bits)} but does not take
- * acceptDocs into account and guarantees to return a {@link BitDocIdSet}.
+ * Produce a {@link BitSet} matching the expected documents on the given
+ * segment. This may return {@code null} if no documents match.
*/
- public abstract BitDocIdSet getDocIdSet(LeafReaderContext context) throws IOException;
-
- @Override
- public final DocIdSet getDocIdSet(LeafReaderContext context, Bits acceptDocs) throws IOException {
- return BitsFilteredDocIdSet.wrap(getDocIdSet(context), acceptDocs);
- }
+ BitSet getBitSet(LeafReaderContext context) throws IOException;
}
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/BitDocIdSetCachingWrapperFilter.java b/lucene/join/src/java/org/apache/lucene/search/join/QueryBitSetProducer.java
similarity index 51%
rename from lucene/join/src/java/org/apache/lucene/search/join/BitDocIdSetCachingWrapperFilter.java
rename to lucene/join/src/java/org/apache/lucene/search/join/QueryBitSetProducer.java
index c898bd01ccc..2562ac8f04a 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/BitDocIdSetCachingWrapperFilter.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/QueryBitSetProducer.java
@@ -22,80 +22,84 @@ import java.util.Collections;
import java.util.Map;
import java.util.WeakHashMap;
+import org.apache.lucene.index.IndexReaderContext;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.ReaderUtil;
import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.DocIdSetIterator;
-import org.apache.lucene.search.Filter;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.Weight;
import org.apache.lucene.util.BitDocIdSet;
+import org.apache.lucene.util.BitSet;
/**
- * {@link Filter} wrapper that implements {@link BitDocIdSetFilter}.
+ * A {@link BitSetProducer} that wraps a query and caches matching
+ * {@link BitSet}s per segment.
*/
-public class BitDocIdSetCachingWrapperFilter extends BitDocIdSetFilter {
- private final Filter filter;
+public class QueryBitSetProducer implements BitSetProducer {
+ private final Query query;
private final Map<Object,DocIdSet> cache = Collections.synchronizedMap(new WeakHashMap<>());
- /** Wraps another filter's result and caches it into bitsets.
- * @param filter Filter to cache results of
+ /** Wraps another query's result and caches it into bitsets.
+ * @param query Query to cache results of
*/
- public BitDocIdSetCachingWrapperFilter(Filter filter) {
- this.filter = filter;
+ public QueryBitSetProducer(Query query) {
+ this.query = query;
}
/**
- * Gets the contained filter.
- * @return the contained filter.
+ * Gets the contained query.
+ * @return the contained query.
*/
- public Filter getFilter() {
- return filter;
- }
-
- private BitDocIdSet docIdSetToCache(DocIdSet docIdSet, LeafReader reader) throws IOException {
- final DocIdSetIterator it = docIdSet.iterator();
- if (it == null) {
- return null;
- } else {
- BitDocIdSet.Builder builder = new BitDocIdSet.Builder(reader.maxDoc());
- builder.or(it);
- return builder.build();
- }
+ public Query getQuery() {
+ return query;
}
@Override
- public BitDocIdSet getDocIdSet(LeafReaderContext context) throws IOException {
+ public BitSet getBitSet(LeafReaderContext context) throws IOException {
final LeafReader reader = context.reader();
final Object key = reader.getCoreCacheKey();
DocIdSet docIdSet = cache.get(key);
if (docIdSet == null) {
- docIdSet = filter.getDocIdSet(context, null);
- docIdSet = docIdSetToCache(docIdSet, reader);
+ final IndexReaderContext topLevelContext = ReaderUtil.getTopLevelContext(context);
+ final IndexSearcher searcher = new IndexSearcher(topLevelContext);
+ searcher.setQueryCache(null);
+ final Weight weight = searcher.createNormalizedWeight(query, false);
+ final DocIdSetIterator it = weight.scorer(context);
+
+ BitDocIdSet.Builder builder = new BitDocIdSet.Builder(context.reader().maxDoc());
+ if (it != null) {
+ builder.or(it);
+ }
+ docIdSet = builder.build();
if (docIdSet == null) {
// We use EMPTY as a sentinel for the empty set, which is cacheable
docIdSet = DocIdSet.EMPTY;
}
cache.put(key, docIdSet);
}
- return docIdSet == DocIdSet.EMPTY ? null : (BitDocIdSet) docIdSet;
+ return docIdSet == DocIdSet.EMPTY ? null : ((BitDocIdSet) docIdSet).bits();
}
@Override
- public String toString(String field) {
- return getClass().getSimpleName() + "("+filter.toString(field)+")";
+ public String toString() {
+ return getClass().getSimpleName() + "("+query.toString()+")";
}
@Override
public boolean equals(Object o) {
- if (super.equals(o) == false) {
+ if (o == null || getClass() != o.getClass()) {
return false;
}
- final BitDocIdSetCachingWrapperFilter other = (BitDocIdSetCachingWrapperFilter) o;
- return this.filter.equals(other.filter);
+ final QueryBitSetProducer other = (QueryBitSetProducer) o;
+ return this.query.equals(other.query);
}
@Override
public int hashCode() {
- return 31 * super.hashCode() + filter.hashCode();
+ return 31 * getClass().hashCode() + query.hashCode();
}
}
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
index ad093583795..6e0d39e2031 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
@@ -31,7 +31,6 @@ import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Weight;
-import org.apache.lucene.util.BitDocIdSet;
import org.apache.lucene.util.BitSet;
/**
@@ -51,7 +50,7 @@ public class ToChildBlockJoinQuery extends Query {
static final String INVALID_QUERY_MESSAGE = "Parent query yields document which is not matched by parents filter, docID=";
static final String ILLEGAL_ADVANCE_ON_PARENT = "Expect to be advanced on child docs only. got docID=";
- private final BitDocIdSetFilter parentsFilter;
+ private final BitSetProducer parentsFilter;
private final Query parentQuery;
// If we are rewritten, this is the original parentQuery we
@@ -67,14 +66,14 @@ public class ToChildBlockJoinQuery extends Query {
* @param parentQuery Query that matches parent documents
* @param parentsFilter Filter identifying the parent documents.
*/
- public ToChildBlockJoinQuery(Query parentQuery, BitDocIdSetFilter parentsFilter) {
+ public ToChildBlockJoinQuery(Query parentQuery, BitSetProducer parentsFilter) {
super();
this.origParentQuery = parentQuery;
this.parentQuery = parentQuery;
this.parentsFilter = parentsFilter;
}
- private ToChildBlockJoinQuery(Query origParentQuery, Query parentQuery, BitDocIdSetFilter parentsFilter) {
+ private ToChildBlockJoinQuery(Query origParentQuery, Query parentQuery, BitSetProducer parentsFilter) {
super();
this.origParentQuery = origParentQuery;
this.parentQuery = parentQuery;
@@ -94,10 +93,10 @@ public class ToChildBlockJoinQuery extends Query {
private static class ToChildBlockJoinWeight extends Weight {
private final Query joinQuery;
private final Weight parentWeight;
- private final BitDocIdSetFilter parentsFilter;
+ private final BitSetProducer parentsFilter;
private final boolean doScores;
- public ToChildBlockJoinWeight(Query joinQuery, Weight parentWeight, BitDocIdSetFilter parentsFilter, boolean doScores) {
+ public ToChildBlockJoinWeight(Query joinQuery, Weight parentWeight, BitSetProducer parentsFilter, boolean doScores) {
super(joinQuery);
this.joinQuery = joinQuery;
this.parentWeight = parentWeight;
@@ -132,13 +131,13 @@ public class ToChildBlockJoinQuery extends Query {
// NOTE: this doesn't take acceptDocs into account, the responsibility
// to not match deleted docs is on the scorer
- final BitDocIdSet parents = parentsFilter.getDocIdSet(readerContext);
+ final BitSet parents = parentsFilter.getBitSet(readerContext);
if (parents == null) {
// No parents
return null;
}
- return new ToChildBlockJoinScorer(this, parentScorer, parents.bits(), doScores);
+ return new ToChildBlockJoinScorer(this, parentScorer, parents, doScores);
}
@Override
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
index c221750200f..fd6256b6b1b 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
@@ -35,9 +35,7 @@ import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Weight;
import org.apache.lucene.search.grouping.TopGroups;
import org.apache.lucene.util.ArrayUtil;
-import org.apache.lucene.util.BitDocIdSet;
import org.apache.lucene.util.BitSet;
-import org.apache.lucene.util.Bits;
/**
* This query requires that you index
@@ -83,7 +81,7 @@ import org.apache.lucene.util.Bits;
*/
public class ToParentBlockJoinQuery extends Query {
- private final BitDocIdSetFilter parentsFilter;
+ private final BitSetProducer parentsFilter;
private final Query childQuery;
// If we are rewritten, this is the original childQuery we
@@ -101,7 +99,7 @@ public class ToParentBlockJoinQuery extends Query {
* @param scoreMode How to aggregate multiple child scores
* into a single parent score.
**/
- public ToParentBlockJoinQuery(Query childQuery, BitDocIdSetFilter parentsFilter, ScoreMode scoreMode) {
+ public ToParentBlockJoinQuery(Query childQuery, BitSetProducer parentsFilter, ScoreMode scoreMode) {
super();
this.origChildQuery = childQuery;
this.childQuery = childQuery;
@@ -109,7 +107,7 @@ public class ToParentBlockJoinQuery extends Query {
this.scoreMode = scoreMode;
}
- private ToParentBlockJoinQuery(Query origChildQuery, Query childQuery, BitDocIdSetFilter parentsFilter, ScoreMode scoreMode) {
+ private ToParentBlockJoinQuery(Query origChildQuery, Query childQuery, BitSetProducer parentsFilter, ScoreMode scoreMode) {
super();
this.origChildQuery = origChildQuery;
this.childQuery = childQuery;
@@ -130,10 +128,10 @@ public class ToParentBlockJoinQuery extends Query {
private static class BlockJoinWeight extends Weight {
private final Query joinQuery;
private final Weight childWeight;
- private final BitDocIdSetFilter parentsFilter;
+ private final BitSetProducer parentsFilter;
private final ScoreMode scoreMode;
- public BlockJoinWeight(Query joinQuery, Weight childWeight, BitDocIdSetFilter parentsFilter, ScoreMode scoreMode) {
+ public BlockJoinWeight(Query joinQuery, Weight childWeight, BitSetProducer parentsFilter, ScoreMode scoreMode) {
super(joinQuery);
this.joinQuery = joinQuery;
this.childWeight = childWeight;
@@ -173,14 +171,14 @@ public class ToParentBlockJoinQuery extends Query {
// NOTE: this does not take accept docs into account, the responsibility
// to not match deleted docs is on the scorer
- final BitDocIdSet parents = parentsFilter.getDocIdSet(readerContext);
+ final BitSet parents = parentsFilter.getBitSet(readerContext);
if (parents == null) {
// No matches
return null;
}
- return new BlockJoinScorer(this, childScorer, parents.bits(), firstChildDoc, scoreMode);
+ return new BlockJoinScorer(this, childScorer, parents, firstChildDoc, scoreMode);
}
@Override
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinSortField.java b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinSortField.java
index 801bb8c7d62..8590a756528 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinSortField.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinSortField.java
@@ -25,7 +25,7 @@ import org.apache.lucene.index.SortedNumericDocValues;
import org.apache.lucene.index.SortedSetDocValues;
import org.apache.lucene.search.FieldComparator;
import org.apache.lucene.search.SortField;
-import org.apache.lucene.util.BitDocIdSet;
+import org.apache.lucene.util.BitSet;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.NumericUtils;
@@ -40,8 +40,8 @@ import java.io.IOException;
public class ToParentBlockJoinSortField extends SortField {
private final boolean order;
- private final BitDocIdSetFilter parentFilter;
- private final BitDocIdSetFilter childFilter;
+ private final BitSetProducer parentFilter;
+ private final BitSetProducer childFilter;
/**
* Create ToParentBlockJoinSortField. The parent document ordering is based on child document ordering (reverse).
@@ -52,7 +52,7 @@ public class ToParentBlockJoinSortField extends SortField {
* @param parentFilter Filter that identifies the parent documents.
* @param childFilter Filter that defines which child documents participates in sorting.
*/
- public ToParentBlockJoinSortField(String field, Type type, boolean reverse, BitDocIdSetFilter parentFilter, BitDocIdSetFilter childFilter) {
+ public ToParentBlockJoinSortField(String field, Type type, boolean reverse, BitSetProducer parentFilter, BitSetProducer childFilter) {
super(field, type, reverse);
switch (getType()) {
case STRING:
@@ -80,7 +80,7 @@ public class ToParentBlockJoinSortField extends SortField {
* @param parentFilter Filter that identifies the parent documents.
* @param childFilter Filter that defines which child documents participates in sorting.
*/
- public ToParentBlockJoinSortField(String field, Type type, boolean reverse, boolean order, BitDocIdSetFilter parentFilter, BitDocIdSetFilter childFilter) {
+ public ToParentBlockJoinSortField(String field, Type type, boolean reverse, boolean order, BitSetProducer parentFilter, BitSetProducer childFilter) {
super(field, type, reverse);
this.order = order;
this.parentFilter = parentFilter;
@@ -114,12 +114,12 @@ public class ToParentBlockJoinSortField extends SortField {
final BlockJoinSelector.Type type = order
? BlockJoinSelector.Type.MAX
: BlockJoinSelector.Type.MIN;
- final BitDocIdSet parents = parentFilter.getDocIdSet(context);
- final BitDocIdSet children = childFilter.getDocIdSet(context);
+ final BitSet parents = parentFilter.getBitSet(context);
+ final BitSet children = childFilter.getBitSet(context);
if (children == null) {
return DocValues.emptySorted();
}
- return BlockJoinSelector.wrap(sortedSet, type, parents.bits(), children.bits());
+ return BlockJoinSelector.wrap(sortedSet, type, parents, children);
}
};
@@ -133,22 +133,22 @@ public class ToParentBlockJoinSortField extends SortField {
final BlockJoinSelector.Type type = order
? BlockJoinSelector.Type.MAX
: BlockJoinSelector.Type.MIN;
- final BitDocIdSet parents = parentFilter.getDocIdSet(context);
- final BitDocIdSet children = childFilter.getDocIdSet(context);
+ final BitSet parents = parentFilter.getBitSet(context);
+ final BitSet children = childFilter.getBitSet(context);
if (children == null) {
return DocValues.emptyNumeric();
}
- return BlockJoinSelector.wrap(sortedNumeric, type, parents.bits(), children.bits());
+ return BlockJoinSelector.wrap(sortedNumeric, type, parents, children);
}
@Override
protected Bits getDocsWithValue(LeafReaderContext context, String field) throws IOException {
final Bits docsWithValue = DocValues.getDocsWithField(context.reader(), field);
- final BitDocIdSet parents = parentFilter.getDocIdSet(context);
- final BitDocIdSet children = childFilter.getDocIdSet(context);
+ final BitSet parents = parentFilter.getBitSet(context);
+ final BitSet children = childFilter.getBitSet(context);
if (children == null) {
return new Bits.MatchNoBits(context.reader().maxDoc());
}
- return BlockJoinSelector.wrap(docsWithValue, parents.bits(), children.bits());
+ return BlockJoinSelector.wrap(docsWithValue, parents, children);
}
};
}
@@ -161,22 +161,22 @@ public class ToParentBlockJoinSortField extends SortField {
final BlockJoinSelector.Type type = order
? BlockJoinSelector.Type.MAX
: BlockJoinSelector.Type.MIN;
- final BitDocIdSet parents = parentFilter.getDocIdSet(context);
- final BitDocIdSet children = childFilter.getDocIdSet(context);
+ final BitSet parents = parentFilter.getBitSet(context);
+ final BitSet children = childFilter.getBitSet(context);
if (children == null) {
return DocValues.emptyNumeric();
}
- return BlockJoinSelector.wrap(sortedNumeric, type, parents.bits(), children.bits());
+ return BlockJoinSelector.wrap(sortedNumeric, type, parents, children);
}
@Override
protected Bits getDocsWithValue(LeafReaderContext context, String field) throws IOException {
final Bits docsWithValue = DocValues.getDocsWithField(context.reader(), field);
- final BitDocIdSet parents = parentFilter.getDocIdSet(context);
- final BitDocIdSet children = childFilter.getDocIdSet(context);
+ final BitSet parents = parentFilter.getBitSet(context);
+ final BitSet children = childFilter.getBitSet(context);
if (children == null) {
return new Bits.MatchNoBits(context.reader().maxDoc());
}
- return BlockJoinSelector.wrap(docsWithValue, parents.bits(), children.bits());
+ return BlockJoinSelector.wrap(docsWithValue, parents, children);
}
};
}
@@ -189,12 +189,12 @@ public class ToParentBlockJoinSortField extends SortField {
final BlockJoinSelector.Type type = order
? BlockJoinSelector.Type.MAX
: BlockJoinSelector.Type.MIN;
- final BitDocIdSet parents = parentFilter.getDocIdSet(context);
- final BitDocIdSet children = childFilter.getDocIdSet(context);
+ final BitSet parents = parentFilter.getBitSet(context);
+ final BitSet children = childFilter.getBitSet(context);
if (children == null) {
return DocValues.emptyNumeric();
}
- final NumericDocValues view = BlockJoinSelector.wrap(sortedNumeric, type, parents.bits(), children.bits());
+ final NumericDocValues view = BlockJoinSelector.wrap(sortedNumeric, type, parents, children);
// undo the numericutils sortability
return new NumericDocValues() {
@Override
@@ -214,12 +214,12 @@ public class ToParentBlockJoinSortField extends SortField {
final BlockJoinSelector.Type type = order
? BlockJoinSelector.Type.MAX
: BlockJoinSelector.Type.MIN;
- final BitDocIdSet parents = parentFilter.getDocIdSet(context);
- final BitDocIdSet children = childFilter.getDocIdSet(context);
+ final BitSet parents = parentFilter.getBitSet(context);
+ final BitSet children = childFilter.getBitSet(context);
if (children == null) {
return DocValues.emptyNumeric();
}
- final NumericDocValues view = BlockJoinSelector.wrap(sortedNumeric, type, parents.bits(), children.bits());
+ final NumericDocValues view = BlockJoinSelector.wrap(sortedNumeric, type, parents, children);
// undo the numericutils sortability
return new NumericDocValues() {
@Override
@@ -231,12 +231,12 @@ public class ToParentBlockJoinSortField extends SortField {
@Override
protected Bits getDocsWithValue(LeafReaderContext context, String field) throws IOException {
final Bits docsWithValue = DocValues.getDocsWithField(context.reader(), field);
- final BitDocIdSet parents = parentFilter.getDocIdSet(context);
- final BitDocIdSet children = childFilter.getDocIdSet(context);
+ final BitSet parents = parentFilter.getBitSet(context);
+ final BitSet children = childFilter.getBitSet(context);
if (children == null) {
return new Bits.MatchNoBits(context.reader().maxDoc());
}
- return BlockJoinSelector.wrap(docsWithValue, parents.bits(), children.bits());
+ return BlockJoinSelector.wrap(docsWithValue, parents, children);
}
};
}
diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
index 6f7b8a0934d..f8c259be034 100644
--- a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
+++ b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
@@ -52,7 +52,6 @@ import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.FieldDoc;
-import org.apache.lucene.search.Filter;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.MatchNoDocsQuery;
@@ -61,7 +60,6 @@ import org.apache.lucene.search.NumericRangeQuery;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryUtils;
-import org.apache.lucene.search.QueryWrapperFilter;
import org.apache.lucene.search.RandomApproximationQuery;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.Sort;
@@ -139,7 +137,7 @@ public class TestBlockJoin extends LuceneTestCase {
w.close();
assertTrue(r.leaves().size() > 1);
IndexSearcher s = new IndexSearcher(r);
- BitDocIdSetFilter parentsFilter = new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("docType", "resume"))));
+ BitSetProducer parentsFilter = new QueryBitSetProducer(new TermQuery(new Term("docType", "resume")));
BooleanQuery.Builder childQuery = new BooleanQuery.Builder();
childQuery.add(new BooleanClause(new TermQuery(new Term("skill", "java")), Occur.MUST));
@@ -191,7 +189,7 @@ public class TestBlockJoin extends LuceneTestCase {
IndexSearcher s = newSearcher(r);
// Create a filter that defines "parent" documents in the index - in this case resumes
- BitDocIdSetFilter parentsFilter = new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("docType", "resume"))));
+ BitSetProducer parentsFilter = new QueryBitSetProducer(new TermQuery(new Term("docType", "resume")));
// Define child document criteria (finds an example of relevant work experience)
BooleanQuery.Builder childQuery = new BooleanQuery.Builder();
@@ -281,7 +279,7 @@ public class TestBlockJoin extends LuceneTestCase {
// iterations:
qc.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_REWRITE);
- BitDocIdSetFilter parentsFilter = new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("docType", "resume"))));
+ BitSetProducer parentsFilter = new QueryBitSetProducer(new TermQuery(new Term("docType", "resume")));
int h1 = qc.hashCode();
Query qw1 = qc.rewrite(r);
@@ -306,8 +304,8 @@ public class TestBlockJoin extends LuceneTestCase {
dir.close();
}
- protected QueryWrapperFilter skill(String skill) {
- return new QueryWrapperFilter(new TermQuery(new Term("skill", skill)));
+ protected Query skill(String skill) {
+ return new TermQuery(new Term("skill", skill));
}
public void testSimpleFilter() throws Exception {
@@ -342,7 +340,7 @@ public class TestBlockJoin extends LuceneTestCase {
IndexSearcher s = newSearcher(r);
// Create a filter that defines "parent" documents in the index - in this case resumes
- BitDocIdSetFilter parentsFilter = new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("docType", "resume"))));
+ BitSetProducer parentsFilter = new QueryBitSetProducer(new TermQuery(new Term("docType", "resume")));
// Define child document criteria (finds an example of relevant work experience)
BooleanQuery.Builder childQuery = new BooleanQuery.Builder();
@@ -360,7 +358,7 @@ public class TestBlockJoin extends LuceneTestCase {
Query query = new BooleanQuery.Builder()
.add(childJoinQuery, Occur.MUST)
- .add(parentsFilter, Occur.FILTER)
+ .add(new TermQuery(new Term("docType", "resume")), Occur.FILTER)
.build();
assertEquals("dummy filter passes everyone ", 2, s.search(query, 10).totalHits);
query = new BooleanQuery.Builder()
@@ -372,19 +370,14 @@ public class TestBlockJoin extends LuceneTestCase {
// not found test
query = new BooleanQuery.Builder()
.add(childJoinQuery, Occur.MUST)
- .add(new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("country", "Oz")))), Occur.FILTER)
- .build();
- assertEquals("noone live there", 0, s.search(query, 1).totalHits);
- query = new BooleanQuery.Builder()
- .add(childJoinQuery, Occur.MUST)
- .add(new QueryWrapperFilter(new TermQuery(new Term("country", "Oz"))), Occur.FILTER)
+ .add(new TermQuery(new Term("country", "Oz")), Occur.FILTER)
.build();
assertEquals("noone live there", 0, s.search(query, 1).totalHits);
// apply the UK filter by the searcher
query = new BooleanQuery.Builder()
.add(childJoinQuery, Occur.MUST)
- .add(new QueryWrapperFilter(parentQuery), Occur.FILTER)
+ .add(parentQuery, Occur.FILTER)
.build();
TopDocs ukOnly = s.search(query, 1);
assertEquals("has filter - single passed", 1, ukOnly.totalHits);
@@ -392,7 +385,7 @@ public class TestBlockJoin extends LuceneTestCase {
query = new BooleanQuery.Builder()
.add(childJoinQuery, Occur.MUST)
- .add(new QueryWrapperFilter(new TermQuery(new Term("country", "United States"))), Occur.FILTER)
+ .add(new TermQuery(new Term("country", "United States")), Occur.FILTER)
.build();
// looking for US candidates
TopDocs usThen = s.search(query, 1);
@@ -430,11 +423,11 @@ public class TestBlockJoin extends LuceneTestCase {
}
}
- private StoredDocument getParentDoc(IndexReader reader, BitDocIdSetFilter parents, int childDocID) throws IOException {
+ private StoredDocument getParentDoc(IndexReader reader, BitSetProducer parents, int childDocID) throws IOException {
final List<LeafReaderContext> leaves = reader.leaves();
final int subIndex = ReaderUtil.subIndex(childDocID, leaves);
final LeafReaderContext leaf = leaves.get(subIndex);
- final BitSet bits = parents.getDocIdSet(leaf).bits();
+ final BitSet bits = parents.getBitSet(leaf);
return leaf.reader().document(bits.nextSetBit(childDocID - leaf.docBase));
}
@@ -445,7 +438,7 @@ public class TestBlockJoin extends LuceneTestCase {
w.close();
IndexSearcher s = newSearcher(r);
- ToParentBlockJoinQuery q = new ToParentBlockJoinQuery(new MatchNoDocsQuery(), new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new MatchAllDocsQuery())), ScoreMode.Avg);
+ ToParentBlockJoinQuery q = new ToParentBlockJoinQuery(new MatchNoDocsQuery(), new QueryBitSetProducer(new MatchAllDocsQuery()), ScoreMode.Avg);
QueryUtils.check(random(), q, s);
s.search(q, 10);
BooleanQuery.Builder bqB = new BooleanQuery.Builder();
@@ -656,7 +649,7 @@ public class TestBlockJoin extends LuceneTestCase {
final IndexSearcher joinS = new IndexSearcher(joinR);
- final BitDocIdSetFilter parentsFilter = new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("isParent", "x"))));
+ final BitSetProducer parentsFilter = new QueryBitSetProducer(new TermQuery(new Term("isParent", "x")));
final int iters = 200*RANDOM_MULTIPLIER;
@@ -906,10 +899,9 @@ public class TestBlockJoin extends LuceneTestCase {
final Term childTerm = randomChildTerm(childFields[0]);
if (random().nextBoolean()) { // filtered case
childJoinQuery2 = parentJoinQuery2;
- final Filter f = new QueryWrapperFilter(new TermQuery(childTerm));
childJoinQuery2 = new BooleanQuery.Builder()
.add(childJoinQuery2, Occur.MUST)
- .add(random().nextBoolean() ? new BitDocIdSetCachingWrapperFilter(f): f, Occur.FILTER)
+ .add(new TermQuery(childTerm), Occur.FILTER)
.build();
} else {
// AND child field w/ parent query:
@@ -928,10 +920,9 @@ public class TestBlockJoin extends LuceneTestCase {
if (random().nextBoolean()) { // filtered case
childQuery2 = parentQuery2;
- final Filter f = new QueryWrapperFilter(new TermQuery(childTerm));
childQuery2 = new BooleanQuery.Builder()
.add(childQuery2, Occur.MUST)
- .add(random().nextBoolean() ? new BitDocIdSetCachingWrapperFilter(f): f, Occur.FILTER)
+ .add(new TermQuery(childTerm), Occur.FILTER)
.build();
} else {
final BooleanQuery.Builder bq2 = new BooleanQuery.Builder();
@@ -1067,7 +1058,7 @@ public class TestBlockJoin extends LuceneTestCase {
IndexSearcher s = newSearcher(r);
// Create a filter that defines "parent" documents in the index - in this case resumes
- BitDocIdSetFilter parentsFilter = new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("docType", "resume"))));
+ BitSetProducer parentsFilter = new QueryBitSetProducer(new TermQuery(new Term("docType", "resume")));
// Define child document criteria (finds an example of relevant work experience)
BooleanQuery.Builder childJobQuery = new BooleanQuery.Builder();
@@ -1147,9 +1138,8 @@ public class TestBlockJoin extends LuceneTestCase {
w.close();
IndexSearcher s = newSearcher(r);
Query tq = new TermQuery(new Term("child", "1"));
- BitDocIdSetFilter parentFilter = new BitDocIdSetCachingWrapperFilter(
- new QueryWrapperFilter(
- new TermQuery(new Term("parent", "1"))));
+ BitSetProducer parentFilter = new QueryBitSetProducer(
+ new TermQuery(new Term("parent", "1")));
ToParentBlockJoinQuery q = new ToParentBlockJoinQuery(tq, parentFilter, ScoreMode.Avg);
Weight weight = s.createNormalizedWeight(q, true);
@@ -1181,9 +1171,8 @@ public class TestBlockJoin extends LuceneTestCase {
w.close();
IndexSearcher s = newSearcher(r);
Query tq = new TermQuery(new Term("child", "2"));
- BitDocIdSetFilter parentFilter = new BitDocIdSetCachingWrapperFilter(
- new QueryWrapperFilter(
- new TermQuery(new Term("isparent", "yes"))));
+ BitSetProducer parentFilter = new QueryBitSetProducer(
+ new TermQuery(new Term("isparent", "yes")));
ToParentBlockJoinQuery q = new ToParentBlockJoinQuery(tq, parentFilter, ScoreMode.Avg);
Weight weight = s.createNormalizedWeight(q, true);
@@ -1215,7 +1204,7 @@ public class TestBlockJoin extends LuceneTestCase {
IndexSearcher s = new IndexSearcher(r);
// Create a filter that defines "parent" documents in the index - in this case resumes
- BitDocIdSetFilter parentsFilter = new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("docType", "resume"))));
+ BitSetProducer parentsFilter = new QueryBitSetProducer(new TermQuery(new Term("docType", "resume")));
// Define child document criteria (finds an example of relevant work experience)
BooleanQuery.Builder childQuery = new BooleanQuery.Builder();
@@ -1321,7 +1310,7 @@ public class TestBlockJoin extends LuceneTestCase {
IndexSearcher searcher = new ToParentBlockJoinIndexSearcher(r);
Query childQuery = new TermQuery(new Term("childText", "text"));
- BitDocIdSetFilter parentsFilter = new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("isParent", "yes"))));
+ BitSetProducer parentsFilter = new QueryBitSetProducer(new TermQuery(new Term("isParent", "yes")));
ToParentBlockJoinQuery childJoinQuery = new ToParentBlockJoinQuery(childQuery, parentsFilter, ScoreMode.Avg);
BooleanQuery.Builder parentQuery = new BooleanQuery.Builder();
parentQuery.add(childJoinQuery, Occur.SHOULD);
@@ -1391,7 +1380,7 @@ public class TestBlockJoin extends LuceneTestCase {
// never matches:
Query childQuery = new TermQuery(new Term("childText", "bogus"));
- BitDocIdSetFilter parentsFilter = new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("isParent", "yes"))));
+ BitSetProducer parentsFilter = new QueryBitSetProducer(new TermQuery(new Term("isParent", "yes")));
ToParentBlockJoinQuery childJoinQuery = new ToParentBlockJoinQuery(childQuery, parentsFilter, ScoreMode.Avg);
BooleanQuery.Builder parentQuery = new BooleanQuery.Builder();
parentQuery.add(childJoinQuery, Occur.SHOULD);
@@ -1456,7 +1445,7 @@ public class TestBlockJoin extends LuceneTestCase {
// illegally matches parent:
Query childQuery = new TermQuery(new Term("parentText", "text"));
- BitDocIdSetFilter parentsFilter = new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("isParent", "yes"))));
+ BitSetProducer parentsFilter = new QueryBitSetProducer(new TermQuery(new Term("isParent", "yes")));
ToParentBlockJoinQuery childJoinQuery = new ToParentBlockJoinQuery(childQuery, parentsFilter, ScoreMode.Avg);
BooleanQuery.Builder parentQuery = new BooleanQuery.Builder();
parentQuery.add(childJoinQuery, Occur.SHOULD);
@@ -1508,7 +1497,7 @@ public class TestBlockJoin extends LuceneTestCase {
IndexSearcher s = newSearcher(r);
// Create a filter that defines "parent" documents in the index - in this case resumes
- BitDocIdSetFilter parentsFilter = new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("isparent", "yes"))));
+ BitSetProducer parentsFilter = new QueryBitSetProducer(new TermQuery(new Term("isparent", "yes")));
Query parentQuery = new TermQuery(new Term("parent", "2"));
@@ -1543,7 +1532,7 @@ public class TestBlockJoin extends LuceneTestCase {
final IndexSearcher searcher = newSearcher(reader);
searcher.setQueryCache(null); // to have real advance() calls
- final BitDocIdSetFilter parentsFilter = new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("parent", "true"))));
+ final BitSetProducer parentsFilter = new QueryBitSetProducer(new TermQuery(new Term("parent", "true")));
final Query toChild = new ToChildBlockJoinQuery(new TermQuery(new Term("foo_parent", "bar")), parentsFilter);
final Query childQuery = new TermQuery(new Term("foo_child", "baz"));
@@ -1587,7 +1576,7 @@ public class TestBlockJoin extends LuceneTestCase {
IndexSearcher s = newSearcher(r);
// Create a filter that defines "parent" documents in the index - in this case resumes
- BitDocIdSetFilter parentsFilter = new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("docType", "resume"))));
+ BitSetProducer parentsFilter = new QueryBitSetProducer(new TermQuery(new Term("docType", "resume")));
Query parentQuery = new PrefixQuery(new Term("country", "United"));
ToChildBlockJoinQuery toChildQuery = new ToChildBlockJoinQuery(parentQuery, parentsFilter);
@@ -1625,7 +1614,7 @@ public class TestBlockJoin extends LuceneTestCase {
IndexSearcher s = newSearcher(r);
// Create a filter that defines "parent" documents in the index - in this case resumes
- BitDocIdSetFilter parentsFilter = new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("docType", "resume"))));
+ BitSetProducer parentsFilter = new QueryBitSetProducer(new TermQuery(new Term("docType", "resume")));
Query parentQuery = new PrefixQuery(new Term("country", "United"));
ToChildBlockJoinQuery toChildQuery = new ToChildBlockJoinQuery(parentQuery, parentsFilter);
diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinSorting.java b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinSorting.java
index de853ee43db..c16051d00d0 100644
--- a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinSorting.java
+++ b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinSorting.java
@@ -29,7 +29,6 @@ import org.apache.lucene.index.Term;
import org.apache.lucene.search.FieldDoc;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.PrefixQuery;
-import org.apache.lucene.search.QueryWrapperFilter;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TermQuery;
@@ -228,11 +227,11 @@ public class TestBlockJoinSorting extends LuceneTestCase {
IndexSearcher searcher = new IndexSearcher(DirectoryReader.open(w.w, false));
w.close();
- BitDocIdSetFilter parentFilter = new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("__type", "parent"))));
- BitDocIdSetFilter childFilter = new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new PrefixQuery(new Term("field2"))));
+ BitSetProducer parentFilter = new QueryBitSetProducer(new TermQuery(new Term("__type", "parent")));
+ BitSetProducer childFilter = new QueryBitSetProducer(new PrefixQuery(new Term("field2")));
ToParentBlockJoinQuery query = new ToParentBlockJoinQuery(
- childFilter,
- new BitDocIdSetCachingWrapperFilter(parentFilter),
+ new PrefixQuery(new Term("field2")),
+ parentFilter,
ScoreMode.None
);
@@ -294,10 +293,10 @@ public class TestBlockJoinSorting extends LuceneTestCase {
assertEquals("g", ((BytesRef) ((FieldDoc) topDocs.scoreDocs[4]).fields[0]).utf8ToString());
// Sort by field descending, order last, sort filter (filter_1:T)
- childFilter = new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery((new Term("filter_1", "T")))));
+ childFilter = new QueryBitSetProducer(new TermQuery((new Term("filter_1", "T"))));
query = new ToParentBlockJoinQuery(
- childFilter,
- new BitDocIdSetCachingWrapperFilter(parentFilter),
+ new TermQuery((new Term("filter_1", "T"))),
+ parentFilter,
ScoreMode.None
);
sortField = new ToParentBlockJoinSortField(
diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinValidation.java b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinValidation.java
index 1a279f96693..c868a12ed5d 100644
--- a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinValidation.java
+++ b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinValidation.java
@@ -34,7 +34,6 @@ import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
-import org.apache.lucene.search.QueryWrapperFilter;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.Weight;
@@ -54,7 +53,7 @@ public class TestBlockJoinValidation extends LuceneTestCase {
private Directory directory;
private IndexReader indexReader;
private IndexSearcher indexSearcher;
- private BitDocIdSetFilter parentsFilter;
+ private BitSetProducer parentsFilter;
@Override
public void setUp() throws Exception {
@@ -70,7 +69,7 @@ public class TestBlockJoinValidation extends LuceneTestCase {
indexReader = DirectoryReader.open(indexWriter, random().nextBoolean());
indexWriter.close();
indexSearcher = new IndexSearcher(indexReader);
- parentsFilter = new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new WildcardQuery(new Term("parent", "*"))));
+ parentsFilter = new QueryBitSetProducer(new WildcardQuery(new Term("parent", "*")));
}
@Override
@@ -132,7 +131,7 @@ public class TestBlockJoinValidation extends LuceneTestCase {
final LeafReaderContext context = indexSearcher.getIndexReader().leaves().get(0);
Weight weight = indexSearcher.createNormalizedWeight(blockJoinQuery, true);
Scorer scorer = weight.scorer(context);
- final Bits parentDocs = parentsFilter.getDocIdSet(context).bits();
+ final Bits parentDocs = parentsFilter.getBitSet(context);
int target;
do {
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestHierarchicalDocBuilder.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestHierarchicalDocBuilder.java
index 377a5bbdc41..5014619613e 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestHierarchicalDocBuilder.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestHierarchicalDocBuilder.java
@@ -34,8 +34,8 @@ import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryWrapperFilter;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocs;
-import org.apache.lucene.search.join.BitDocIdSetCachingWrapperFilter;
-import org.apache.lucene.search.join.BitDocIdSetFilter;
+import org.apache.lucene.search.join.QueryBitSetProducer;
+import org.apache.lucene.search.join.BitSetProducer;
import org.apache.lucene.search.join.ScoreMode;
import org.apache.lucene.search.join.ToParentBlockJoinQuery;
import org.apache.solr.common.util.StrUtils;
@@ -457,10 +457,10 @@ public class TestHierarchicalDocBuilder extends AbstractDataImportHandlerTestCas
**/
private final String childEntityTemplate = "<entity " + ConfigNameConstants.CHILD + "=\"true\" name=\"{0}\" query=\"{1}\">\n {2} {3} </entity>\n";
- private BitDocIdSetFilter createParentFilter(String type) {
+ private BitSetProducer createParentFilter(String type) {
BooleanQuery.Builder parentQuery = new BooleanQuery.Builder();
parentQuery.add(new TermQuery(new Term("type_s", type)), Occur.MUST);
- return new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(parentQuery.build()));
+ return new QueryBitSetProducer(new QueryWrapperFilter(parentQuery.build()));
}
private String nextId() {
diff --git a/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java b/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java
index ada0ca90756..4c812997259 100644
--- a/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java
+++ b/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java
@@ -23,8 +23,8 @@ import org.apache.lucene.index.StoredDocument;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryWrapperFilter;
import org.apache.lucene.search.Sort;
-import org.apache.lucene.search.join.BitDocIdSetCachingWrapperFilter;
-import org.apache.lucene.search.join.BitDocIdSetFilter;
+import org.apache.lucene.search.join.QueryBitSetProducer;
+import org.apache.lucene.search.join.BitSetProducer;
import org.apache.lucene.search.join.ToChildBlockJoinQuery;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrException;
@@ -75,10 +75,10 @@ public class ChildDocTransformerFactory extends TransformerFactory {
String childFilter = params.get( "childFilter" );
int limit = params.getInt( "limit", 10 );
- BitDocIdSetFilter parentsFilter = null;
+ BitSetProducer parentsFilter = null;
try {
Query parentFilterQuery = QParser.getParser( parentFilter, null, req).getQuery();
- parentsFilter = new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(parentFilterQuery));
+ parentsFilter = new QueryBitSetProducer(new QueryWrapperFilter(parentFilterQuery));
} catch (SyntaxError syntaxError) {
throw new SolrException( ErrorCode.BAD_REQUEST, "Failed to create correct parent filter query" );
}
@@ -100,11 +100,11 @@ class ChildDocTransformer extends TransformerWithContext {
private final String name;
private final SchemaField idField;
private final IndexSchema schema;
- private BitDocIdSetFilter parentsFilter;
+ private BitSetProducer parentsFilter;
private Query childFilterQuery;
private int limit;
- public ChildDocTransformer( String name, final BitDocIdSetFilter parentsFilter,
+ public ChildDocTransformer( String name, final BitSetProducer parentsFilter,
final SchemaField idField, IndexSchema schema,
final Query childFilterQuery, int limit) {
this.name = name;
diff --git a/solr/core/src/java/org/apache/solr/search/join/BlockJoinChildQParser.java b/solr/core/src/java/org/apache/solr/search/join/BlockJoinChildQParser.java
index 62fbe131824..9c3ba641620 100644
--- a/solr/core/src/java/org/apache/solr/search/join/BlockJoinChildQParser.java
+++ b/solr/core/src/java/org/apache/solr/search/join/BlockJoinChildQParser.java
@@ -29,7 +29,7 @@ public class BlockJoinChildQParser extends BlockJoinParentQParser {
}
protected Query createQuery(Query parentListQuery, Query query) {
- return new ToChildBlockJoinQuery(query, getFilter(parentListQuery));
+ return new ToChildBlockJoinQuery(query, getFilter(parentListQuery).filter);
}
@Override
diff --git a/solr/core/src/java/org/apache/solr/search/join/BlockJoinParentQParser.java b/solr/core/src/java/org/apache/solr/search/join/BlockJoinParentQParser.java
index 47ba8395a14..d9175b0fbb5 100644
--- a/solr/core/src/java/org/apache/solr/search/join/BlockJoinParentQParser.java
+++ b/solr/core/src/java/org/apache/solr/search/join/BlockJoinParentQParser.java
@@ -17,13 +17,21 @@
package org.apache.solr.search.join;
+import java.io.IOException;
+
+import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.search.BitsFilteredDocIdSet;
+import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryWrapperFilter;
-import org.apache.lucene.search.join.BitDocIdSetCachingWrapperFilter;
-import org.apache.lucene.search.join.BitDocIdSetFilter;
+import org.apache.lucene.search.join.QueryBitSetProducer;
+import org.apache.lucene.search.join.BitSetProducer;
import org.apache.lucene.search.join.ScoreMode;
import org.apache.lucene.search.join.ToParentBlockJoinQuery;
+import org.apache.lucene.util.BitDocIdSet;
+import org.apache.lucene.util.BitSet;
+import org.apache.lucene.util.Bits;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.search.QParser;
@@ -63,21 +71,21 @@ class BlockJoinParentQParser extends QParser {
}
protected Query createQuery(Query parentList, Query query) {
- return new ToParentBlockJoinQuery(query, getFilter(parentList), ScoreMode.None);
+ return new ToParentBlockJoinQuery(query, getFilter(parentList).filter, ScoreMode.None);
}
- BitDocIdSetFilter getFilter(Query parentList) {
+ BitDocIdSetFilterWrapper getFilter(Query parentList) {
SolrCache parentCache = req.getSearcher().getCache(CACHE_NAME);
// lazily retrieve from solr cache
Filter filter = null;
if (parentCache != null) {
filter = (Filter) parentCache.get(parentList);
}
- BitDocIdSetFilter result;
- if (filter instanceof BitDocIdSetFilter) {
- result = (BitDocIdSetFilter) filter;
+ BitDocIdSetFilterWrapper result;
+ if (filter instanceof BitDocIdSetFilterWrapper) {
+ result = (BitDocIdSetFilterWrapper) filter;
} else {
- result = createParentFilter(parentList);
+ result = new BitDocIdSetFilterWrapper(createParentFilter(parentList));
if (parentCache != null) {
parentCache.put(parentList, result);
}
@@ -85,9 +93,48 @@ class BlockJoinParentQParser extends QParser {
return result;
}
- private BitDocIdSetFilter createParentFilter(Query parentQ) {
- return new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(parentQ));
+ private BitSetProducer createParentFilter(Query parentQ) {
+ return new QueryBitSetProducer(new QueryWrapperFilter(parentQ));
+ }
+
+ // We need this wrapper since BitDocIdSetFilter does not extend Filter
+ static class BitDocIdSetFilterWrapper extends Filter {
+
+ final BitSetProducer filter;
+
+ BitDocIdSetFilterWrapper(BitSetProducer filter) {
+ this.filter = filter;
+ }
+
+ @Override
+ public DocIdSet getDocIdSet(LeafReaderContext context, Bits acceptDocs) throws IOException {
+ BitSet set = filter.getBitSet(context);
+ if (set == null) {
+ return null;
+ }
+ return BitsFilteredDocIdSet.wrap(new BitDocIdSet(set), acceptDocs);
+ }
+
+ @Override
+ public String toString(String field) {
+ return getClass().getSimpleName() + "(" + filter + ")";
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (super.equals(obj) == false) {
+ return false;
+ }
+ return filter.equals(((BitDocIdSetFilterWrapper) obj).filter);
+ }
+
+ @Override
+ public int hashCode() {
+ return 31 * super.hashCode() + filter.hashCode();
+ }
+
}
+
}
diff --git a/solr/core/src/test/org/apache/solr/update/AddBlockUpdateTest.java b/solr/core/src/test/org/apache/solr/update/AddBlockUpdateTest.java
index 7200d7d200f..10cad42fb28 100644
--- a/solr/core/src/test/org/apache/solr/update/AddBlockUpdateTest.java
+++ b/solr/core/src/test/org/apache/solr/update/AddBlockUpdateTest.java
@@ -26,7 +26,7 @@ import org.apache.lucene.search.QueryWrapperFilter;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TermRangeQuery;
import org.apache.lucene.search.TopDocs;
-import org.apache.lucene.search.join.BitDocIdSetCachingWrapperFilter;
+import org.apache.lucene.search.join.QueryBitSetProducer;
import org.apache.lucene.search.join.ScoreMode;
import org.apache.lucene.search.join.ToParentBlockJoinQuery;
import org.apache.solr.SolrTestCaseJ4;
@@ -562,7 +562,7 @@ public class AddBlockUpdateTest extends SolrTestCaseJ4 {
protected ToParentBlockJoinQuery join(final String childTerm) {
return new ToParentBlockJoinQuery(
- new TermQuery(new Term(child, childTerm)), new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(
+ new TermQuery(new Term(child, childTerm)), new QueryBitSetProducer(new QueryWrapperFilter(
new TermRangeQuery(parent, null, null, false, false))), ScoreMode.None);
}