Example usage for org.apache.lucene.search FieldDoc FieldDoc

List of usage examples for org.apache.lucene.search FieldDoc FieldDoc

Introduction

In this page you can find the example usage for org.apache.lucene.search FieldDoc FieldDoc.

Prototype

public FieldDoc(int doc, float score, Object[] fields, int shardIndex) 

Source Link

Document

Expert: Creates one of these objects with the given sort information.

Usage

From source file:org.elasticsearch.search.aggregations.metrics.tophits.InternalTopHitsTests.java

License:Apache License

@Override
protected void assertReduced(InternalTopHits reduced, List<InternalTopHits> inputs) {
    SearchHits actualHits = reduced.getHits();
    List<Tuple<ScoreDoc, SearchHit>> allHits = new ArrayList<>();
    float maxScore = Float.MIN_VALUE;
    long totalHits = 0;
    for (int input = 0; input < inputs.size(); input++) {
        SearchHits internalHits = inputs.get(input).getHits();
        totalHits += internalHits.getTotalHits();
        maxScore = max(maxScore, internalHits.getMaxScore());
        for (int i = 0; i < internalHits.internalHits().length; i++) {
            ScoreDoc doc = inputs.get(input).getTopDocs().scoreDocs[i];
            if (testInstancesLookSortedByField) {
                doc = new FieldDoc(doc.doc, doc.score, ((FieldDoc) doc).fields, input);
            } else {
                doc = new ScoreDoc(doc.doc, doc.score, input);
            }//from   w  w w. j a  v a2  s  .c  o m
            allHits.add(new Tuple<>(doc, internalHits.internalHits()[i]));
        }
    }
    allHits.sort(comparing(Tuple::v1, scoreDocComparator()));
    SearchHit[] expectedHitsHits = new SearchHit[min(inputs.get(0).getSize(), allHits.size())];
    for (int i = 0; i < expectedHitsHits.length; i++) {
        expectedHitsHits[i] = allHits.get(i).v2();
    }
    SearchHits expectedHits = new SearchHits(expectedHitsHits, totalHits, maxScore);
    assertEqualsWithErrorMessageFromXContent(expectedHits, actualHits);
}