Index: CHANGES.txt
===================================================================
--- CHANGES.txt	(revision 769601)
+++ CHANGES.txt	(working copy)
@@ -269,6 +269,10 @@
 
 22. LUCENE-1605: Added BitVector.subset().  (Jeremy Volkman via Mike
     McCandless)
+    
+23. LUCENE-1618: Added FileSwitchDirectory which enables per directory
+    file access based on the extension of the file. (Jason Rutherglen 
+    via Mike McCandless)
 
 Optimizations
 
Index: src/java/org/apache/lucene/store/FileSwitchDirectory.java
===================================================================
--- src/java/org/apache/lucene/store/FileSwitchDirectory.java	(revision 0)
+++ src/java/org/apache/lucene/store/FileSwitchDirectory.java	(revision 0)
@@ -0,0 +1,127 @@
+package org.apache.lucene.store;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Files with the given extensions are placed in the real directory;
+ */
+public class FileSwitchDirectory extends Directory {
+  private Directory otherDir;
+  private Directory realDir;
+  private Set fileExtensions;
+  private boolean doClose;
+
+  public FileSwitchDirectory(Set fileExtensions, Directory realDir, Directory otherDir, boolean doClose) {
+    this.fileExtensions = fileExtensions;
+    this.realDir = realDir;
+    this.otherDir = otherDir;
+    this.doClose = doClose;
+    this.lockFactory = realDir.getLockFactory();
+  }
+  
+  public void close() throws IOException {
+    if (doClose) {
+      otherDir.close();
+      realDir.close();
+    }
+  }
+  
+  public String[] listAll() throws IOException {
+    List list = new ArrayList();
+    String[] ramFiles = otherDir.listAll();
+    for (int x = 0; x < ramFiles.length; x++) {
+      list.add(ramFiles[x]);
+    }
+    String[] fsFiles = realDir.listAll();
+    for (int x = 0; x < fsFiles.length; x++) {
+      list.add(fsFiles[x]);
+    }
+    return (String[]) list.toArray(new String[0]);
+  }
+  
+  public String[] list() throws IOException {
+    List list = new ArrayList();
+    String[] ramFiles = otherDir.list();
+    for (int x = 0; x < ramFiles.length; x++) {
+      list.add(ramFiles[x]);
+    }
+    String[] fsFiles = realDir.list();
+    for (int x = 0; x < fsFiles.length; x++) {
+      list.add(fsFiles[x]);
+    }
+    return (String[]) list.toArray(new String[0]);
+  }
+
+  public static String getExtension(String name) {
+    int i = name.lastIndexOf('.');
+    if (i == -1) {
+      return "";
+    }
+    return name.substring(i+1, name.length());
+  }
+
+  private Directory getDirectory(String name) {
+    String ext = getExtension(name);
+    if (fileExtensions.contains(ext)) {
+      return realDir;
+    } else {
+      return otherDir;
+    }
+  }
+
+  public boolean fileExists(String name) throws IOException {
+    return getDirectory(name).fileExists(name);
+  }
+
+  public long fileModified(String name) throws IOException {
+    return getDirectory(name).fileModified(name);
+  }
+
+  public void touchFile(String name) throws IOException {
+    getDirectory(name).touchFile(name);
+  }
+
+  public void deleteFile(String name) throws IOException {
+    getDirectory(name).deleteFile(name);
+  }
+
+  public void renameFile(String from, String to) throws IOException {
+    getDirectory(from).renameFile(from, to);
+  }
+
+  public long fileLength(String name) throws IOException {
+    return getDirectory(name).fileLength(name);
+  }
+
+  public IndexOutput createOutput(String name) throws IOException {
+    return getDirectory(name).createOutput(name);
+  }
+
+  public void sync(String name) throws IOException {
+    getDirectory(name).sync(name);
+  }
+
+  public IndexInput openInput(String name) throws IOException {
+    return getDirectory(name).openInput(name);
+  }
+}
Index: src/test/org/apache/lucene/index/TestIndexWriterReader.java
===================================================================
--- src/test/org/apache/lucene/index/TestIndexWriterReader.java	(revision 769601)
+++ src/test/org/apache/lucene/index/TestIndexWriterReader.java	(working copy)
@@ -537,7 +537,6 @@
 
   public static void createIndexNoClose(boolean multiSegment, String indexName,
       IndexWriter w) throws IOException {
-    w.setMergePolicy(new LogDocMergePolicy());
     for (int i = 0; i < 100; i++) {
       w.addDocument(createDocument(i, indexName, 4));
     }
Index: src/test/org/apache/lucene/store/TestFileSwitchDirectory.java
===================================================================
--- src/test/org/apache/lucene/store/TestFileSwitchDirectory.java	(revision 0)
+++ src/test/org/apache/lucene/store/TestFileSwitchDirectory.java	(revision 0)
@@ -0,0 +1,64 @@
+package org.apache.lucene.store;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.lucene.analysis.WhitespaceAnalyzer;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.TestIndexWriterReader;
+import org.apache.lucene.util.LuceneTestCase;
+
+public class TestFileSwitchDirectory extends LuceneTestCase {
+  /**
+   * Test if writing doc stores to disk and everything else to ram works.
+   * @throws IOException
+   */
+  public void testBasic() throws IOException {
+    Set fileExtensions = new HashSet();
+    fileExtensions.add("fdt");
+    fileExtensions.add("fdx");
+    
+    Directory fsDirectory = new MockRAMDirectory();
+    RAMDirectory ramDirectory = new MockRAMDirectory();
+    
+    FileSwitchDirectory fsd = new FileSwitchDirectory(fileExtensions, fsDirectory, ramDirectory, true);
+    IndexWriter writer = new IndexWriter(fsd, new WhitespaceAnalyzer(),
+        IndexWriter.MaxFieldLength.LIMITED);
+    writer.setUseCompoundFile(false);
+    TestIndexWriterReader.createIndexNoClose(true, "ram", writer);
+    IndexReader reader = writer.getReader();
+    assertEquals(100, reader.maxDoc());
+    writer.commit();
+    // we should see fdx,fdt files here
+    String[] fsFiles = fsDirectory.listAll();
+    assertTrue(fsFiles.length > 0);
+    for (int x=0; x < fsFiles.length; x++) {
+      String ext = FileSwitchDirectory.getExtension(fsFiles[x]);
+      assertTrue(fileExtensions.contains(ext));
+    }
+    reader.close();
+    writer.close();
+    
+    fsDirectory.close();
+    ramDirectory.close();
+  }
+}
