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

import com.yahoo.fs4.QueryPacket;
import com.yahoo.prelude.fastsearch.CacheKey;
import com.yahoo.search.Query;
import com.yahoo.search.Result;

import java.io.IOException;
import java.util.List;

/**
 * SearchInvoker encapsulates an allocated connection for running a single search query.
 * The invocation object can be stateful and should not be reused.
 *
 * @author ollivir
 */
public abstract class SearchInvoker extends CloseableInvoker {
    /**
     * Retrieve the hits for the given {@link Query}. The invoker may return more than one result, in which case the caller is responsible
     * for merging the results. If multiple results are returned and the search query had a hit offset other than zero, that offset is
     * set to zero and the number of requested hits is adjusted accordingly.
     */
    public List<Result> search(Query query, QueryPacket queryPacket, CacheKey cacheKey) throws IOException {
        sendSearchRequest(query, queryPacket);
        return getSearchResults(cacheKey);
    }

    protected abstract void sendSearchRequest(Query query, QueryPacket queryPacket) throws IOException;

    protected abstract List<Result> getSearchResults(CacheKey cacheKey) throws IOException;
}