aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/dispatch/InvokerResult.java
blob: ce4891d7c25e080a0e097f596ce987c62a69f8e5 (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
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
 */
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);
            }
            fh.setQuery(query);
            fh.setFillable();
            fh.setCached(false);
            result.hits().add(fh);
        }
        leanHits.clear();
    }
}