Skip to content

Commit

Permalink
Set the sortValues on SearchHit post aggregation instead of during th…
Browse files Browse the repository at this point in the history
…e reduce.
  • Loading branch information
martijnvg committed May 23, 2014
1 parent 0e920c1 commit 3f2f1f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ public InternalAggregation reduce(ReduceContext reduceContext) {
for (int i = 0; i < reducedTopDocs.scoreDocs.length; i++) {
ScoreDoc scoreDoc = reducedTopDocs.scoreDocs[i];
hits[i] = (InternalSearchHit) shardHits[scoreDoc.shardIndex].getAt(tracker[scoreDoc.shardIndex]++);
if (scoreDoc instanceof FieldDoc) {
FieldDoc fieldDoc = (FieldDoc) scoreDoc;
hits[i].sortValues(fieldDoc.fields);
}
}
return new InternalTopHits(name, new InternalSearchHits(hits, reducedTopDocs.totalHits, reducedTopDocs.getMaxScore()));
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,14 @@ public InternalAggregation buildAggregation(long owningBucketOrdinal) {
FetchSearchResult fetchResult = topHitsContext.fetchResult();
InternalSearchHit[] internalHits = fetchResult.fetchResult().hits().internalHits();
for (int i = 0; i < internalHits.length; i++) {
ScoreDoc scoreDoc = topDocs.scoreDocs[i];
InternalSearchHit searchHitFields = internalHits[i];
searchHitFields.shard(topHitsContext.shardTarget());
searchHitFields.score(topDocs.scoreDocs[i].score);
searchHitFields.score(scoreDoc.score);
if (scoreDoc instanceof FieldDoc) {
FieldDoc fieldDoc = (FieldDoc) scoreDoc;
searchHitFields.sortValues(fieldDoc.fields);
}
}
return new InternalTopHits(name, topHitsContext.size(), topHitsContext.sort(), topDocs, fetchResult.hits());
}
Expand Down

0 comments on commit 3f2f1f0

Please sign in to comment.