Make it possible to subclass SegmentReader [LUCENE-2345]
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.4k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 88
Description
I would like the ability to subclass SegmentReader for numerous reasons:
- to capture initialization/close events
- attach custom objects to an instance of a segment reader (caches, statistics, so on and so forth)
- override methods on segment reader as needed
currently this isn't really possible
I propose adding a SegmentReaderFactory that would allow creating custom subclasses of SegmentReader
default implementation would be something like:
```Java
public class SegmentReaderFactory {
public SegmentReader get(boolean readOnly) {
return readOnly ? new ReadOnlySegmentReader() : new SegmentReader();
}
public SegmentReader reopen(SegmentReader reader, boolean readOnly) {
return newSegmentReader(readOnly);
}
}
```
It would then be made possible to pass a SegmentReaderFactory to IndexWriter (for pooled readers) as well as to SegmentReader.get() (DirectoryReader.open, etc)
I could prepare a patch if others think this has merit
Obviously, this API would be "experimental/advanced/will change in future"
---
Migrated from [LUCENE-2345](https://issues.apache.org/jira/browse/LUCENE-2345) by Tim Smith, updated May 09 2016
Attachments: [LUCENE-2345_3.0.patch](https://apache.github.io/lucene-jira-archive/attachments/LUCENE-2345/LUCENE-2345_3.0.patch), [LUCENE-2345_3.0.plugins.patch](https://apache.github.io/lucene-jira-archive/attachments/LUCENE-2345/LUCENE-2345_3.0.plugins.patch)
Contributor guide
Research direction
Read the existing SegmentReader creation paths, including SegmentReader.get(), DirectoryReader.open(), and IndexWriter handling of pooled readers. Determine how a SegmentReaderFactory could support custom subclasses and lifecycle behavior, then verify that the proposed extension points cover both read-only and reopen flows without breaking existing callers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend, search
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100