Set the sortValues on SearchHit post aggregation instead of during the reduce.

This commit is contained in:
Martijn van Groningen 2014-05-23 19:05:16 +02:00
parent 0e920c17dd
commit 3f2f1f088d
2 changed files with 6 additions and 5 deletions

View File

@ -109,10 +109,6 @@ public class InternalTopHits extends InternalAggregation implements TopHits, ToX
for (int i = 0; i < reducedTopDocs.scoreDocs.length; i++) { for (int i = 0; i < reducedTopDocs.scoreDocs.length; i++) {
ScoreDoc scoreDoc = reducedTopDocs.scoreDocs[i]; ScoreDoc scoreDoc = reducedTopDocs.scoreDocs[i];
hits[i] = (InternalSearchHit) shardHits[scoreDoc.shardIndex].getAt(tracker[scoreDoc.shardIndex]++); 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())); return new InternalTopHits(name, new InternalSearchHits(hits, reducedTopDocs.totalHits, reducedTopDocs.getMaxScore()));
} catch (IOException e) { } catch (IOException e) {

View File

@ -79,9 +79,14 @@ public class TopHitsAggregator extends BucketsAggregator implements ScorerAware
FetchSearchResult fetchResult = topHitsContext.fetchResult(); FetchSearchResult fetchResult = topHitsContext.fetchResult();
InternalSearchHit[] internalHits = fetchResult.fetchResult().hits().internalHits(); InternalSearchHit[] internalHits = fetchResult.fetchResult().hits().internalHits();
for (int i = 0; i < internalHits.length; i++) { for (int i = 0; i < internalHits.length; i++) {
ScoreDoc scoreDoc = topDocs.scoreDocs[i];
InternalSearchHit searchHitFields = internalHits[i]; InternalSearchHit searchHitFields = internalHits[i];
searchHitFields.shard(topHitsContext.shardTarget()); 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()); return new InternalTopHits(name, topHitsContext.size(), topHitsContext.sort(), topDocs, fetchResult.hits());
} }