Skip to content

Commit 76fd57b

Browse files
committed
Fix more comments
Signed-off-by: Atri Sharma <atri.jiit@gmail.com>
1 parent 7dd41c6 commit 76fd57b

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed

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

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import org.apache.logging.log4j.LogManager;
1212
import org.apache.logging.log4j.Logger;
13-
import org.apache.logging.log4j.message.ParameterizedMessage;
1413
import org.apache.lucene.search.Collector;
1514
import org.apache.lucene.search.CollectorManager;
1615
import org.apache.lucene.search.Query;
@@ -24,7 +23,6 @@
2423

2524
import java.io.IOException;
2625
import java.util.LinkedList;
27-
import java.util.List;
2826
import java.util.Objects;
2927
import java.util.concurrent.ExecutionException;
3028

@@ -50,21 +48,7 @@ public boolean searchWith(
5048
boolean hasFilterCollector,
5149
boolean hasTimeout
5250
) throws IOException {
53-
List<QueryPhaseExtension> extensions = queryPhaseExtensions();
54-
55-
// Execute beforeScoreCollection extensions
56-
for (QueryPhaseExtension extension : extensions) {
57-
try {
58-
extension.beforeScoreCollection(searchContext);
59-
} catch (Exception e) {
60-
LOGGER.warn(
61-
new ParameterizedMessage("Failed to execute beforeScoreCollection extension [{}]", extension.getClass().getName()),
62-
e
63-
);
64-
}
65-
}
66-
67-
try {
51+
return executeWithExtensions(searchContext, () -> {
6852
QueryCollectorContext queryCollectorContext = getQueryCollectorContext(searchContext, hasFilterCollector);
6953
return searchWithCollectorManager(
7054
searchContext,
@@ -75,19 +59,7 @@ public boolean searchWith(
7559
hasFilterCollector,
7660
hasTimeout
7761
);
78-
} finally {
79-
// Execute afterScoreCollection extensions
80-
for (QueryPhaseExtension extension : extensions) {
81-
try {
82-
extension.afterScoreCollection(searchContext);
83-
} catch (Exception e) {
84-
LOGGER.warn(
85-
new ParameterizedMessage("Failed to execute afterScoreCollection extension [{}]", extension.getClass().getName()),
86-
e
87-
);
88-
}
89-
}
90-
}
62+
});
9163
}
9264

9365
@Override

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,17 @@ public boolean searchWith(
431431
boolean hasFilterCollector,
432432
boolean hasTimeout
433433
) throws IOException {
434+
return executeWithExtensions(
435+
searchContext,
436+
() -> searchWithCollector(searchContext, searcher, query, collectors, hasFilterCollector, hasTimeout)
437+
);
438+
}
439+
440+
/**
441+
* Executes the provided search operation with before/after extension hooks.
442+
* This method handles extension execution and error handling consistently.
443+
*/
444+
protected boolean executeWithExtensions(SearchContext searchContext, SearchOperation searchOperation) throws IOException {
434445
List<QueryPhaseExtension> extensions = queryPhaseExtensions();
435446

436447
// Execute beforeScoreCollection extensions
@@ -446,7 +457,7 @@ public boolean searchWith(
446457
}
447458

448459
try {
449-
return searchWithCollector(searchContext, searcher, query, collectors, hasFilterCollector, hasTimeout);
460+
return searchOperation.execute();
450461
} finally {
451462
// Execute afterScoreCollection extensions
452463
for (QueryPhaseExtension extension : extensions) {
@@ -465,6 +476,14 @@ public boolean searchWith(
465476
}
466477
}
467478

479+
/**
480+
* Functional interface for search operations that can throw IOException
481+
*/
482+
@FunctionalInterface
483+
protected interface SearchOperation {
484+
boolean execute() throws IOException;
485+
}
486+
468487
@Override
469488
public AggregationProcessor aggregationProcessor(SearchContext searchContext) {
470489
return aggregationProcessor;

0 commit comments

Comments
 (0)