summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/prelude/searcher/FillSearcher.java
blob: f1d14972033b1b1e21fdf9641a0d5c3610c36ff5 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.searcher;

import com.yahoo.component.ComponentId;
import com.yahoo.search.Query;
import com.yahoo.search.Result;
import com.yahoo.search.Searcher;
import com.yahoo.search.searchchain.Execution;

/**
 * This searcher fills the results in the first phase. May be put into
 * a search chain to ensure full results are present at an earlier
 * time than they would normally be.
 *
 * @author <a href="mailto:havardpe@yahoo-inc.com">havardpe</a>
 **/
public class FillSearcher extends Searcher {
    private final Searcher next;

    public FillSearcher() {
        next = null;
    }

    public FillSearcher(Searcher next) {
        this.next = next;
    }

    @Override
    public Result search(Query query, Execution execution) {
        Result result;
        if (next == null) {
            result = execution.search(query);
            execution.fill(result);
        } else {
            Execution e = new Execution(next, execution.context());
            result = e.search(query);
            e.fill(result);
        }
        return result;
    }

    // TODO: Remove this method as it does nothing new
    @Override
    public void fill(Result result, String summaryClass, Execution execution) {
        if (next == null) {
            execution.fill(result, summaryClass);
        } else {
            Execution e = new Execution(next, execution.context());
            e.fill(result, summaryClass);
        }
    }
}