LUCENE-7187: Block join queries' Weight#extractTerms(...) implementations should delegate to the wrapped weight.

This commit is contained in:
Martijn van Groningen 2016-04-11 09:20:39 +02:00
parent 70ab80b341
commit f18cb90104
4 changed files with 40 additions and 5 deletions

View File

@ -66,6 +66,9 @@ Bug Fixes
* LUCENE-7168: Switch to stable encode for geo3d, remove quantization
test leniency, remove dead code (Mike McCandless)
* LUCENE-7187: Block join queries' Weight#extractTerms(...) implementations
should delegate to the wrapped weight. (Martijn van Groningen)
Other
* LUCENE-7174: Upgrade randomizedtesting to 2.3.4. (Uwe Schindler, Dawid Weiss)

View File

@ -103,7 +103,9 @@ public class ToChildBlockJoinQuery extends Query {
}
@Override
public void extractTerms(Set<Term> terms) {}
public void extractTerms(Set<Term> terms) {
parentWeight.extractTerms(terms);
}
@Override
public float getValueForNormalization() throws IOException {

View File

@ -125,21 +125,21 @@ public class ToParentBlockJoinQuery extends Query {
}
private static class BlockJoinWeight extends Weight {
private final Query joinQuery;
private final Weight childWeight;
private final BitSetProducer parentsFilter;
private final ScoreMode scoreMode;
public BlockJoinWeight(Query joinQuery, Weight childWeight, BitSetProducer parentsFilter, ScoreMode scoreMode) {
super(joinQuery);
this.joinQuery = joinQuery;
this.childWeight = childWeight;
this.parentsFilter = parentsFilter;
this.scoreMode = scoreMode;
}
@Override
public void extractTerms(Set<Term> terms) {}
public void extractTerms(Set<Term> terms) {
childWeight.extractTerms(terms);
}
@Override
public float getValueForNormalization() throws IOException {

View File

@ -20,8 +20,10 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
@ -101,7 +103,35 @@ public class TestBlockJoin extends LuceneTestCase {
job.add(new IntPoint("year", year));
return job;
}
public void testExtractTerms() throws Exception {
TermQuery termQuery = new TermQuery(new Term("field", "value"));
QueryBitSetProducer bitSetProducer = new QueryBitSetProducer(new MatchNoDocsQuery());
ToParentBlockJoinQuery toParentBlockJoinQuery = new ToParentBlockJoinQuery(termQuery, bitSetProducer, ScoreMode.None);
ToChildBlockJoinQuery toChildBlockJoinQuery = new ToChildBlockJoinQuery(toParentBlockJoinQuery, bitSetProducer);
Directory directory = newDirectory();
final IndexWriter w = new IndexWriter(directory, new IndexWriterConfig(new MockAnalyzer(random())));
w.close();
IndexReader indexReader = DirectoryReader.open(directory);
IndexSearcher indexSearcher = new IndexSearcher(indexReader);
Weight weight = toParentBlockJoinQuery.createWeight(indexSearcher, false);
Set<Term> terms = new HashSet<>();
weight.extractTerms(terms);
Term[] termArr =terms.toArray(new Term[0]);
assertEquals(1, termArr.length);
weight = toChildBlockJoinQuery.createWeight(indexSearcher, false);
terms = new HashSet<>();
weight.extractTerms(terms);
termArr =terms.toArray(new Term[0]);
assertEquals(1, termArr.length);
indexReader.close();
directory.close();
}
public void testEmptyChildFilter() throws Exception {
final Directory dir = newDirectory();
final IndexWriterConfig config = new IndexWriterConfig(new MockAnalyzer(random()));