Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-2345

Make it possible to subclass SegmentReader

Details

    • Wish
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • 4.9, 6.0
    • core/index
    • None
    • New

    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:

      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"

      Attachments

        1. LUCENE-2345_3.0.patch
          18 kB
          Tim Smith
        2. LUCENE-2345_3.0.plugins.patch
          19 kB
          Tim Smith

        Activity

          People

            Unassigned Unassigned
            tsmith Tim Smith
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: