@@ -999,8 +999,8 @@ public final SearcherSupplier acquireSearcherSupplier(Function<Searcher, Searche
999999 // Called before a {@link Searcher} is created, to allow subclasses to perform any stats or logging operations.
10001000 protected void onSearcherCreation (String source , SearcherScope scope ) {}
10011001
1002- // Allows subclasses to wrap the DirectoryReader before it is used to create Searchers
1003- protected DirectoryReader wrapDirectoryReader (DirectoryReader reader , SplitShardCountSummary ignored ) throws IOException {
1002+ // Allows subclasses to wrap the DirectoryReader before it is used to create external Searchers
1003+ protected DirectoryReader wrapExternalDirectoryReader (DirectoryReader reader , SplitShardCountSummary ignored ) throws IOException {
10041004 return reader ;
10051005 }
10061006
@@ -1026,15 +1026,20 @@ public SearcherSupplier acquireSearcherSupplier(
10261026 try {
10271027 ReferenceManager <ElasticsearchDirectoryReader > referenceManager = getReferenceManager (scope );
10281028 ElasticsearchDirectoryReader acquire = referenceManager .acquire ();
1029- DirectoryReader wrappedDirectoryReader = wrapDirectoryReader (acquire , splitShardCountSummary );
1029+ final DirectoryReader maybeWrappedDirectoryReader ;
1030+ if (scope == SearcherScope .EXTERNAL ) {
1031+ maybeWrappedDirectoryReader = wrapExternalDirectoryReader (acquire , splitShardCountSummary );
1032+ } else {
1033+ maybeWrappedDirectoryReader = acquire ;
1034+ }
10301035 SearcherSupplier reader = new SearcherSupplier (wrapper ) {
10311036 @ Override
10321037 public Searcher acquireSearcherInternal (String source ) {
10331038 assert assertSearcherIsWarmedUp (source , scope );
10341039 onSearcherCreation (source , scope );
10351040 return new Searcher (
10361041 source ,
1037- wrappedDirectoryReader ,
1042+ maybeWrappedDirectoryReader ,
10381043 engineConfig .getSimilarity (),
10391044 engineConfig .getQueryCache (),
10401045 engineConfig .getQueryCachingPolicy (),
0 commit comments