LUCENE-5225: The ToParentBlockJoinQuery only keeps tracks of the the child doc ids and child scores if the ToParentBlockJoinCollector is used.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1527975 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Martijn van Groningen 2013-10-01 08:54:45 +00:00
parent ba17276592
commit 0a3ac487a1
3 changed files with 33 additions and 16 deletions

View File

@ -96,6 +96,12 @@ API Changes:
with IndexSearcher when an ExecutorService is specified.
(Ryan Ernst, Mike McCandless, Robert Muir)
Optimizations
* LUCENE-5225: The ToParentBlockJoinQuery only keeps tracks of the the child
doc ids and child scores if the ToParentBlockJoinCollector is used.
(Martijn van Groningen)
Documentation
* LUCENE-5211: Better javadocs and error checking of 'format' option in

View File

@ -283,6 +283,7 @@ public class ToParentBlockJoinCollector extends Collector {
}
private void enroll(ToParentBlockJoinQuery query, ToParentBlockJoinQuery.BlockJoinScorer scorer) {
scorer.trackPendingChildHits();
final Integer slot = joinQueryID.get(query);
if (slot == null) {
joinQueryID.put(query, joinScorers.length);

View File

@ -17,15 +17,9 @@ package org.apache.lucene.search.join;
* limitations under the License.
*/
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Locale;
import java.util.Set;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter; // javadocs
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.ComplexExplanation;
import org.apache.lucene.search.DocIdSet;
@ -41,6 +35,12 @@ import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.FixedBitSet;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Locale;
import java.util.Set;
/**
* This query requires that you index
* children and parent docs as a single block, using the
@ -218,8 +218,7 @@ public class ToParentBlockJoinQuery extends Query {
private float parentScore;
private int parentFreq;
private int nextChildDoc;
private int[] pendingChildDocs = new int[5];
private int[] pendingChildDocs;
private float[] pendingChildScores;
private int childDocUpto;
@ -230,9 +229,6 @@ public class ToParentBlockJoinQuery extends Query {
this.childScorer = childScorer;
this.scoreMode = scoreMode;
this.acceptDocs = acceptDocs;
if (scoreMode != ScoreMode.None) {
pendingChildScores = new float[5];
}
nextChildDoc = firstChildDoc;
}
@ -321,18 +317,22 @@ public class ToParentBlockJoinQuery extends Query {
do {
//System.out.println(" c=" + nextChildDoc);
if (pendingChildDocs.length == childDocUpto) {
if (pendingChildDocs != null && pendingChildDocs.length == childDocUpto) {
pendingChildDocs = ArrayUtil.grow(pendingChildDocs);
}
if (scoreMode != ScoreMode.None && pendingChildScores.length == childDocUpto) {
if (pendingChildScores != null && scoreMode != ScoreMode.None && pendingChildScores.length == childDocUpto) {
pendingChildScores = ArrayUtil.grow(pendingChildScores);
}
pendingChildDocs[childDocUpto] = nextChildDoc;
if (pendingChildDocs != null) {
pendingChildDocs[childDocUpto] = nextChildDoc;
}
if (scoreMode != ScoreMode.None) {
// TODO: specialize this into dedicated classes per-scoreMode
final float childScore = childScorer.score();
final int childFreq = childScorer.freq();
pendingChildScores[childDocUpto] = childScore;
if (pendingChildScores != null) {
pendingChildScores[childDocUpto] = childScore;
}
maxScore = Math.max(childScore, maxScore);
totalScore += childScore;
parentFreq += childFreq;
@ -432,6 +432,16 @@ public class ToParentBlockJoinQuery extends Query {
public long cost() {
return childScorer.cost();
}
/**
* Instructs this scorer to keep track of the child docIds and score ids for retrieval purposes.
*/
public void trackPendingChildHits() {
pendingChildDocs = new int[5];
if (scoreMode != ScoreMode.None) {
pendingChildScores = new float[5];
}
}
}
@Override