Skip to content

Commit c0b9879

Browse files
Revert "#17593 Add Extension Points For Pre and Post Collection of Scores in …" (#18913)
This reverts commit eda3a48. Signed-off-by: Martin Gaievski <gaievski@amazon.com>
1 parent 220ab52 commit c0b9879

File tree

7 files changed

+49
-717
lines changed

7 files changed

+49
-717
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2727
- [Workload Management] Modify logging message in WorkloadGroupService ([#18712](https://github.com/opensearch-project/OpenSearch/pull/18712))
2828
- Add BooleanQuery rewrite moving constant-scoring must clauses to filter clauses ([#18510](https://github.com/opensearch-project/OpenSearch/issues/18510))
2929
- Add functionality for plugins to inject QueryCollectorContext during QueryPhase ([#18637](https://github.com/opensearch-project/OpenSearch/pull/18637))
30-
- Add QueryPhaseListener interface for pre/post collection hooks ([#17593](https://github.com/opensearch-project/OpenSearch/issues/17593))
3130
- Add support for non-timing info in profiler ([#18460](https://github.com/opensearch-project/OpenSearch/issues/18460))
3231
- [Rule-based auto tagging] Bug fix and improvements ([#18726](https://github.com/opensearch-project/OpenSearch/pull/18726))
3332
- Extend Approximation Framework to other numeric types ([#18530](https://github.com/opensearch-project/OpenSearch/issues/18530))

server/src/main/java/org/opensearch/search/query/AbstractQueryPhaseSearcher.java

Lines changed: 0 additions & 101 deletions
This file was deleted.

server/src/main/java/org/opensearch/search/query/ConcurrentQueryPhaseSearcher.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.opensearch.search.internal.ContextIndexSearcher;
2020
import org.opensearch.search.internal.SearchContext;
2121
import org.opensearch.search.profile.query.ProfileCollectorManager;
22+
import org.opensearch.search.query.QueryPhase.DefaultQueryPhaseSearcher;
2223

2324
import java.io.IOException;
2425
import java.util.LinkedList;
@@ -29,7 +30,7 @@
2930
* The implementation of the {@link QueryPhaseSearcher} which attempts to use concurrent
3031
* search of Apache Lucene segments if it has been enabled.
3132
*/
32-
public class ConcurrentQueryPhaseSearcher extends AbstractQueryPhaseSearcher {
33+
public class ConcurrentQueryPhaseSearcher extends DefaultQueryPhaseSearcher {
3334
private static final Logger LOGGER = LogManager.getLogger(ConcurrentQueryPhaseSearcher.class);
3435
private final AggregationProcessor aggregationProcessor = new ConcurrentAggregationProcessor();
3536

@@ -39,15 +40,15 @@ public class ConcurrentQueryPhaseSearcher extends AbstractQueryPhaseSearcher {
3940
public ConcurrentQueryPhaseSearcher() {}
4041

4142
@Override
42-
protected boolean doSearchWith(
43+
protected boolean searchWithCollector(
4344
SearchContext searchContext,
4445
ContextIndexSearcher searcher,
4546
Query query,
4647
LinkedList<QueryCollectorContext> collectors,
48+
QueryCollectorContext queryCollectorContext,
4749
boolean hasFilterCollector,
4850
boolean hasTimeout
4951
) throws IOException {
50-
QueryCollectorContext queryCollectorContext = getQueryCollectorContext(searchContext, hasFilterCollector);
5152
return searchWithCollectorManager(
5253
searchContext,
5354
searcher,

server/src/main/java/org/opensearch/search/query/QueryPhase.java

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@
7676
import java.util.List;
7777
import java.util.Map;
7878
import java.util.Objects;
79+
import java.util.Optional;
7980
import java.util.concurrent.ExecutorService;
8081
import java.util.stream.Collectors;
8182

8283
import static org.opensearch.search.query.QueryCollectorContext.createEarlyTerminationCollectorContext;
8384
import static org.opensearch.search.query.QueryCollectorContext.createFilteredCollectorContext;
8485
import static org.opensearch.search.query.QueryCollectorContext.createMinScoreCollectorContext;
8586
import static org.opensearch.search.query.QueryCollectorContext.createMultiCollectorContext;
87+
import static org.opensearch.search.query.TopDocsCollectorContext.createTopDocsCollectorContext;
8688

8789
/**
8890
* Query phase of a search request, used to run the query and get back from each shard information about the matching documents
@@ -409,7 +411,7 @@ public static class TimeExceededException extends RuntimeException {
409411
*
410412
* @opensearch.internal
411413
*/
412-
public static class DefaultQueryPhaseSearcher extends AbstractQueryPhaseSearcher {
414+
public static class DefaultQueryPhaseSearcher implements QueryPhaseSearcher {
413415
private final AggregationProcessor aggregationProcessor;
414416

415417
/**
@@ -420,7 +422,7 @@ protected DefaultQueryPhaseSearcher() {
420422
}
421423

422424
@Override
423-
protected boolean doSearchWith(
425+
public boolean searchWith(
424426
SearchContext searchContext,
425427
ContextIndexSearcher searcher,
426428
Query query,
@@ -445,6 +447,47 @@ protected boolean searchWithCollector(
445447
boolean hasTimeout
446448
) throws IOException {
447449
QueryCollectorContext queryCollectorContext = getQueryCollectorContext(searchContext, hasFilterCollector);
450+
return searchWithCollector(searchContext, searcher, query, collectors, queryCollectorContext, hasFilterCollector, hasTimeout);
451+
}
452+
453+
private QueryCollectorContext getQueryCollectorContext(SearchContext searchContext, boolean hasFilterCollector) throws IOException {
454+
// create the top docs collector last when the other collectors are known
455+
final Optional<QueryCollectorContext> queryCollectorContextOpt = QueryCollectorContextSpecRegistry.getQueryCollectorContextSpec(
456+
searchContext,
457+
new QueryCollectorArguments.Builder().hasFilterCollector(hasFilterCollector).build()
458+
).map(queryCollectorContextSpec -> new QueryCollectorContext(queryCollectorContextSpec.getContextName()) {
459+
@Override
460+
Collector create(Collector in) throws IOException {
461+
return queryCollectorContextSpec.create(in);
462+
}
463+
464+
@Override
465+
CollectorManager<?, ReduceableSearchResult> createManager(CollectorManager<?, ReduceableSearchResult> in)
466+
throws IOException {
467+
return queryCollectorContextSpec.createManager(in);
468+
}
469+
470+
@Override
471+
void postProcess(QuerySearchResult result) throws IOException {
472+
queryCollectorContextSpec.postProcess(result);
473+
}
474+
});
475+
if (queryCollectorContextOpt.isPresent()) {
476+
return queryCollectorContextOpt.get();
477+
} else {
478+
return createTopDocsCollectorContext(searchContext, hasFilterCollector);
479+
}
480+
}
481+
482+
protected boolean searchWithCollector(
483+
SearchContext searchContext,
484+
ContextIndexSearcher searcher,
485+
Query query,
486+
LinkedList<QueryCollectorContext> collectors,
487+
QueryCollectorContext queryCollectorContext,
488+
boolean hasFilterCollector,
489+
boolean hasTimeout
490+
) throws IOException {
448491
return QueryPhase.searchWithCollector(
449492
searchContext,
450493
searcher,
@@ -455,6 +498,5 @@ protected boolean searchWithCollector(
455498
hasTimeout
456499
);
457500
}
458-
459501
}
460502
}

server/src/main/java/org/opensearch/search/query/QueryPhaseListener.java

Lines changed: 0 additions & 46 deletions
This file was deleted.

server/src/main/java/org/opensearch/search/query/QueryPhaseSearcher.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
import org.opensearch.search.internal.SearchContext;
1818

1919
import java.io.IOException;
20-
import java.util.Collections;
2120
import java.util.LinkedList;
22-
import java.util.List;
2321

2422
/**
2523
* The extension point which allows to plug in custom search implementation to be
@@ -55,12 +53,4 @@ boolean searchWith(
5553
default AggregationProcessor aggregationProcessor(SearchContext searchContext) {
5654
return new DefaultAggregationProcessor();
5755
}
58-
59-
/**
60-
* Get the list of query phase listeners that should be executed before and after score collection.
61-
* @return list of query phase listeners, empty list if none
62-
*/
63-
default List<QueryPhaseListener> queryPhaseListeners() {
64-
return Collections.emptyList();
65-
}
6656
}

0 commit comments

Comments
 (0)