blob: aec59df9a38c97636e8f864dbcf9507ed10fe40a (
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
|
// 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 com.yahoo.search.dispatch.searchcluster.Node;
import com.yahoo.search.searchchain.Execution;
import java.io.IOException;
import java.util.Optional;
/**
* 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 {
private final Optional<Node> node;
private ResponseMonitor<SearchInvoker> monitor;
protected SearchInvoker(Optional<Node> node) {
this.node = node;
}
/**
* Retrieve the hits for the given {@link Query}. If the search is run on multiple content
* nodes, the provided {@link Execution} may be used to retrieve document summaries required
* for correct result windowing.
*/
public Result search(Query query, QueryPacket queryPacket, CacheKey cacheKey, Execution execution) throws IOException {
sendSearchRequest(query, queryPacket);
Result result = getSearchResult(cacheKey, execution);
setFinalStatus(result.hits().getError() == null);
return result;
}
protected abstract void sendSearchRequest(Query query, QueryPacket queryPacket) throws IOException;
protected abstract Result getSearchResult(CacheKey cacheKey, Execution execution) throws IOException;
protected void setMonitor(ResponseMonitor<SearchInvoker> monitor) {
this.monitor = monitor;
}
protected void responseAvailable() {
if (monitor != null) {
monitor.responseAvailable(this);
}
}
protected Optional<Integer> distributionKey() {
return node.map(Node::key);
}
}
|