aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/dispatch/InvokerResult.java
blob: 88d6b68a610f3119fbad82de71346c11a03022d3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.dispatch;

import com.yahoo.prelude.fastsearch.FastHit;
import com.yahoo.search.Query;
import com.yahoo.search.Result;
import com.yahoo.search.query.Sorting;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Wraps a Result and a flat, skinny hit list
 *
 * @author baldersheim
 */
public class InvokerResult {

    private final Result result;
    private final List<LeanHit> leanHits;

    public InvokerResult(Result result) {
        this.result = result;
        this.leanHits = Collections.emptyList();
    }

    public InvokerResult(Query query, int expectedHits) {
        result = new Result(query);
        leanHits = new ArrayList<>(expectedHits);
    }

    public Result getResult() {
        return result;
    }

    public List<LeanHit> getLeanHits() {
        return leanHits;
    }

    void complete() {
        Query query = result.getQuery();
        Sorting sorting = query.getRanking().getSorting();
        for (LeanHit hit : leanHits) {
            FastHit fh = new FastHit(hit.getGid(), hit.getRelevance(), hit.getPartId(), hit.getDistributionKey());
            if (hit.hasSortData()) {
                fh.setSortData(hit.getSortData(), sorting);
            }
            if (hit.hasMatchFeatures()) {
                fh.setField("matchfeatures", hit.getMatchFeatures());
            }
            fh.setQuery(query);
            fh.setFillable();
            fh.setCached(false);
            result.hits().add(fh);
        }
        leanHits.clear();
    }

}