diff --git a/CHANGES.txt b/CHANGES.txt index 19ef764734d..481ef06716b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -95,13 +95,14 @@ $Id$ 18. Added a public, extensible scoring API. For details, see the javadoc for org.apache.lucene.search.Similarity. - + 19. Fixed return of Hits.id() from float to int. (Terry Steichen via Peter). 20. Added getFieldNames() to IndexReader and Segment(s)Reader classes. (Peter Mularien via otis) 21. Added getFields(String) and getValues(String) methods. + Contributed by Rasik Pandey on 2002-10-09 (Rasik Pandey via otis) 22. Revised internal search APIs. Changes include: @@ -142,9 +143,12 @@ $Id$ Caution: These are extensive changes and they have not yet been tested extensively. Bug reports are appreciated. + (cutting) + + 23. Added convenience RAMDirectory constructors taking File and String + arguments, for easy FSDirectory to RAMDirectory conversion. - Contributed by Rasik Pandey on 2002-10-09 1.2 RC6 1. Changed QueryParser.jj to have "?" be a special character which diff --git a/src/java/org/apache/lucene/store/RAMDirectory.java b/src/java/org/apache/lucene/store/RAMDirectory.java index 57c9e4de284..12b5a58ad73 100644 --- a/src/java/org/apache/lucene/store/RAMDirectory.java +++ b/src/java/org/apache/lucene/store/RAMDirectory.java @@ -55,6 +55,7 @@ package org.apache.lucene.store; */ import java.io.IOException; +import java.io.File; import java.util.Vector; import java.util.Hashtable; import java.util.Enumeration; @@ -63,7 +64,11 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.store.InputStream; import org.apache.lucene.store.OutputStream; -/** A memory-resident {@link Directory} implementation. */ +/** + * A memory-resident {@link Directory} implementation. + * + * @version $Id$ + */ public final class RAMDirectory extends Directory { Hashtable files = new Hashtable(); @@ -78,16 +83,16 @@ public final class RAMDirectory extends Directory { *

* This should be used only with indices that can fit into memory. * - * @param d a Directory value + * @param dir a Directory value * @exception IOException if an error occurs */ - public RAMDirectory(Directory d) throws IOException { - final String[] ar = d.list(); + public RAMDirectory(Directory dir) throws IOException { + final String[] ar = dir.list(); for (int i = 0; i < ar.length; i++) { // make place on ram disk OutputStream os = createFile(ar[i]); // read current file - InputStream is = d.openFile(ar[i]); + InputStream is = dir.openFile(ar[i]); // and copy to ram disk int len = (int) is.length(); byte[] buf = new byte[len]; @@ -99,6 +104,24 @@ public final class RAMDirectory extends Directory { } } + /** + * Creates a new RAMDirectory instance from the {@link FSDirectory}. + * + * @param dir a File specifying the index directory + */ + public RAMDirectory(File dir) throws IOException { + this(FSDirectory.getDirectory(dir, false)); + } + + /** + * Creates a new RAMDirectory instance from the {@link FSDirectory}. + * + * @param dir a String specifying the full index directory path + */ + public RAMDirectory(String dir) throws IOException { + this(FSDirectory.getDirectory(dir, false)); + } + /** Returns an array of strings, one for each file in the directory. */ public final String[] list() { String[] result = new String[files.size()];