-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathQueryPhaseSearcherWrapper.java
87 lines (80 loc) · 3.62 KB
/
QueryPhaseSearcherWrapper.java
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.search.query;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.search.CollectorManager;
import org.apache.lucene.search.Query;
import org.opensearch.common.util.FeatureFlags;
import org.opensearch.search.aggregations.AggregationProcessor;
import org.opensearch.search.internal.ContextIndexSearcher;
import org.opensearch.search.internal.SearchContext;
import java.io.IOException;
import java.util.LinkedList;
/**
* Wrapper class for QueryPhaseSearcher that handles path selection for concurrent vs
* non-concurrent search query phase and aggregation processor.
*
* @opensearch.internal
*/
public class QueryPhaseSearcherWrapper implements QueryPhaseSearcher {
private static final Logger LOGGER = LogManager.getLogger(QueryPhaseSearcherWrapper.class);
private final QueryPhaseSearcher defaultQueryPhaseSearcher;
private final QueryPhaseSearcher concurrentQueryPhaseSearcher;
public QueryPhaseSearcherWrapper() {
this.defaultQueryPhaseSearcher = new QueryPhase.DefaultQueryPhaseSearcher();
this.concurrentQueryPhaseSearcher = FeatureFlags.isEnabled(FeatureFlags.CONCURRENT_SEGMENT_SEARCH)
? new ConcurrentQueryPhaseSearcher()
: null;
}
/**
* Perform search using {@link CollectorManager}
*
* @param searchContext search context
* @param searcher context index searcher
* @param query query
* @param hasTimeout "true" if timeout was set, "false" otherwise
* @return is rescoring required or not
* @throws java.io.IOException IOException
*/
@Override
public boolean searchWith(
SearchContext searchContext,
ContextIndexSearcher searcher,
Query query,
LinkedList<QueryCollectorContext> collectors,
boolean hasFilterCollector,
boolean hasTimeout
) throws IOException {
if (searchContext.shouldUseConcurrentSearch()) {
LOGGER.debug("Using concurrent search over segments (experimental) for request with context id {}", searchContext.id());
return concurrentQueryPhaseSearcher.searchWith(searchContext, searcher, query, collectors, hasFilterCollector, hasTimeout);
} else {
LOGGER.debug("Using non-concurrent search over segments for request with context id {}", searchContext.id());
return defaultQueryPhaseSearcher.searchWith(searchContext, searcher, query, collectors, hasFilterCollector, hasTimeout);
}
}
/**
* {@link AggregationProcessor} to use to setup and post process aggregation related collectors during search request
* @param searchContext search context
* @return {@link AggregationProcessor} to use
*/
@Override
public AggregationProcessor aggregationProcessor(SearchContext searchContext) {
if (searchContext.shouldUseConcurrentSearch()) {
LOGGER.debug(
"Using concurrent aggregation processor over segments (experimental) for request with context id {}",
searchContext.id()
);
return concurrentQueryPhaseSearcher.aggregationProcessor(searchContext);
} else {
LOGGER.debug("Using non-concurrent aggregation processor over segments for request with context id {}", searchContext.id());
return defaultQueryPhaseSearcher.aggregationProcessor(searchContext);
}
}
}