Make IndexSearcher#getSlices final and clarify docs (#12718)

IndexSearcher exposes a public getSlices method, that is used to
retrieve the slices that the searcher executes queries against, as well
as slices, which is supposed to be overridden to customize the creation
of slices.

I believe that getSlices should be final: there is no reason to override
the method. Also, it is too easy to confuse the two and end up
overriding the wrong one by mistake.
This commit is contained in:
Luca Cavanna 2023-10-26 12:34:37 +02:00 committed by GitHub
parent c701a5d9be
commit 09da2291c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -156,6 +156,8 @@ API Changes
* GITHUB#12646, GITHUB#12690: Move FST#addNode to FSTCompiler to avoid a circular dependency * GITHUB#12646, GITHUB#12690: Move FST#addNode to FSTCompiler to avoid a circular dependency
between FST and FSTCompiler (Anh Dung Bui) between FST and FSTCompiler (Anh Dung Bui)
* GITHUB#12718: Make IndexSearcher#getSlices final as it is not expected to be overridden (Luca Cavanna)
New Features New Features
--------------------- ---------------------

View File

@ -115,10 +115,10 @@ public class IndexSearcher {
protected final List<LeafReaderContext> leafContexts; protected final List<LeafReaderContext> leafContexts;
/** /**
* used with executor - LeafSlice supplier where each slice holds a set of leafs executed within * Used with executor - LeafSlice supplier where each slice holds a set of leafs executed within
* one thread. We are caching it instead of creating it eagerly to avoid calling a protected * one thread. We are caching it instead of creating it eagerly to avoid calling a protected
* method from constructor, which is a bad practice. This is {@code null} if no executor is * method from constructor, which is a bad practice. Always non-null, regardless of whether an
* provided * executor is provided or not.
*/ */
private final Supplier<LeafSlice[]> leafSlicesSupplier; private final Supplier<LeafSlice[]> leafSlicesSupplier;
@ -425,11 +425,12 @@ public class IndexSearcher {
} }
/** /**
* Returns the leaf slices used for concurrent searching * Returns the leaf slices used for concurrent searching. Override {@link #slices(List)} to
* customize how slices are created.
* *
* @lucene.experimental * @lucene.experimental
*/ */
public LeafSlice[] getSlices() { public final LeafSlice[] getSlices() {
return leafSlicesSupplier.get(); return leafSlicesSupplier.get();
} }