Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,11 @@ public final SearcherSupplier acquireSearcherSupplier(Function<Searcher, Searche
// Called before a {@link Searcher} is created, to allow subclasses to perform any stats or logging operations.
protected void onSearcherCreation(String source, SearcherScope scope) {}

// Allows subclasses to wrap the DirectoryReader before it is used to create Searchers
protected DirectoryReader wrapDirectoryReader(DirectoryReader reader) throws IOException {
return reader;
}

/**
* Acquires a point-in-time reader that can be used to create {@link Engine.Searcher}s on demand.
*/
Expand All @@ -1012,14 +1017,15 @@ public SearcherSupplier acquireSearcherSupplier(Function<Searcher, Searcher> wra
try {
ReferenceManager<ElasticsearchDirectoryReader> referenceManager = getReferenceManager(scope);
ElasticsearchDirectoryReader acquire = referenceManager.acquire();
DirectoryReader wrappedDirectoryReader = wrapDirectoryReader(acquire);
SearcherSupplier reader = new SearcherSupplier(wrapper) {
@Override
public Searcher acquireSearcherInternal(String source) {
assert assertSearcherIsWarmedUp(source, scope);
onSearcherCreation(source, scope);
return new Searcher(
source,
acquire,
wrappedDirectoryReader,
engineConfig.getSimilarity(),
engineConfig.getQueryCache(),
engineConfig.getQueryCachingPolicy(),
Expand Down