Index: CHANGES.txt
===================================================================
--- CHANGES.txt	(revision 888624)
+++ CHANGES.txt	(working copy)
@@ -61,6 +61,10 @@
   backwards compatibility. If Version < 3.1 is passed to the constructor, 
   LowerCaseFilter yields the old behavior. (Simon Willnauer, Robert Muir)  
 
+* LUCENE-2138: IndexReaderFactory allows the creation of custom SegmentReaders
+  when using IndexReader.getReader.
+  (Jason Rutherglen)
+
 Optimizations
 
 * LUCENE-2086: When resolving deleted terms, do so in term sort order
Index: src/java/org/apache/lucene/index/IndexWriter.java
===================================================================
--- src/java/org/apache/lucene/index/IndexWriter.java	(revision 888624)
+++ src/java/org/apache/lucene/index/IndexWriter.java	(working copy)
@@ -605,7 +605,7 @@
         // TODO: we may want to avoid doing this while
         // synchronized
         // Returns a ref, which we xfer to readerMap:
-        sr = SegmentReader.get(false, info.dir, info, readBufferSize, doOpenStores, termsIndexDivisor);
+        sr = readerFactory.createReader(info, doOpenStores, readBufferSize, termsIndexDivisor);
         readerMap.put(info, sr);
       } else {
         if (doOpenStores) {
@@ -4884,4 +4884,31 @@
   synchronized boolean isClosed() {
     return closed;
   }
+  
+  private IndexReaderFactory readerFactory = new DefaultIndexReaderFactory();
+  
+  /** Set the index reader factory.  See {@link
+   *  IndexReaderFactory}. */
+  public void setIndexReaderFactory(IndexReaderFactory readerFactory) {
+    this.readerFactory = readerFactory;
+  }
+
+  /** Returns the current index reader factory.  See {@link
+   *  IndexReaderFactory}. */
+  public IndexReaderFactory getIndexReaderFactory() {
+    return readerFactory;
+  }
+  
+  /**
+   * This class is used to create new segment readers.
+   */
+  public static abstract class IndexReaderFactory {
+    public abstract SegmentReader createReader(SegmentInfo info, boolean doOpenStores, int readBufferSize, int termsIndexDivisor) throws IOException;
+  }
+  
+  public static class DefaultIndexReaderFactory extends IndexReaderFactory {
+    public SegmentReader createReader(SegmentInfo info, boolean doOpenStores, int readBufferSize, int termsIndexDivisor) throws IOException {
+      return SegmentReader.get(false, info.dir, info, readBufferSize, doOpenStores, termsIndexDivisor);
+    }
+  }
 }
