Parent / child queries should work with non-default similarities

This commit is contained in:
George P. Stathis 2014-01-31 17:01:58 -05:00 committed by Martijn van Groningen
parent 244723d401
commit 74dd33689e
6 changed files with 10 additions and 0 deletions

View File

@ -95,6 +95,7 @@ public class ChildrenConstantScoreQuery extends Query {
childQuery = rewrittenChildQuery;
}
IndexSearcher indexSearcher = new IndexSearcher(searcher.getIndexReader());
indexSearcher.setSimilarity(searcher.getSimilarity());
indexSearcher.search(childQuery, collector);
int remaining = collectedUids.v().size();

View File

@ -157,6 +157,7 @@ public class ChildrenQuery extends Query {
childQuery = rewrittenChildQuery;
}
IndexSearcher indexSearcher = new IndexSearcher(searcher.getIndexReader());
indexSearcher.setSimilarity(searcher.getSimilarity());
indexSearcher.search(childQuery, collector);
int size = uidToScore.v().size();

View File

@ -22,6 +22,7 @@ import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.MultiReader;
import org.apache.lucene.search.*;
import org.apache.lucene.search.similarities.Similarity;
import org.apache.lucene.util.Bits;
import org.elasticsearch.search.internal.SearchContext;
@ -65,7 +66,9 @@ public class DeleteByQueryWrappingFilter extends Filter {
try {
if (!contains(indexReader, context)) {
multiReader = new MultiReader(new IndexReader[]{indexReader, context.reader()}, false);
Similarity similarity = searcher.getSimilarity();
searcher = new IndexSearcher(new MultiReader(indexReader, context.reader()));
searcher.setSimilarity(similarity);
}
weight = searcher.createNormalizedWeight(query);
} finally {
@ -78,7 +81,9 @@ public class DeleteByQueryWrappingFilter extends Filter {
if (!contains(indexReader, context)) {
IndexReader multiReader = new MultiReader(new IndexReader[]{indexReader, context.reader()}, false);
try {
Similarity similarity = searcher.getSimilarity();
searcher = new IndexSearcher(multiReader);
searcher.setSimilarity(similarity);
weight = searcher.createNormalizedWeight(query);
} finally {
multiReader.close();

View File

@ -87,6 +87,7 @@ public class ParentConstantScoreQuery extends Query {
parentQuery = rewrittenParentQuery = originalParentQuery.rewrite(searcher.getIndexReader());
}
IndexSearcher indexSearcher = new IndexSearcher(searcher.getIndexReader());
indexSearcher.setSimilarity(searcher.getSimilarity());
indexSearcher.search(parentQuery, collector);
if (parents.v().isEmpty()) {

View File

@ -129,6 +129,7 @@ public class ParentQuery extends Query {
parentQuery = rewrittenParentQuery;
}
IndexSearcher indexSearcher = new IndexSearcher(searcher.getIndexReader());
indexSearcher.setSimilarity(searcher.getSimilarity());
indexSearcher.search(parentQuery, collector);
if (uidToScore.v().isEmpty()) {

View File

@ -124,6 +124,7 @@ public class TopChildrenQuery extends Query {
}
IndexSearcher indexSearcher = new IndexSearcher(searcher.getIndexReader());
indexSearcher.setSimilarity(searcher.getSimilarity());
while (true) {
parentDocs.v().clear();
TopDocs topChildDocs = indexSearcher.search(childQuery, numChildDocs);