LUCENE-1672: Deprecate all String/File ctors/opens in IndexReader/IndexWriter/IndexSearcher

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@782469 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2009-06-07 21:52:41 +00:00
parent a93e2c41b0
commit 406454d30b
21 changed files with 91 additions and 58 deletions

View File

@ -185,6 +185,12 @@ API Changes
iterator has exhausted. Otherwise it should return the current doc ID. iterator has exhausted. Otherwise it should return the current doc ID.
(Shai Erera via Mike McCandless) (Shai Erera via Mike McCandless)
19. LUCENE-1672: All ctors/opens and other methods using String/File to
specify the directory in IndexReader, IndexWriter, and IndexSearcher
were deprecated. You should instantiate the Directory manually before
and pass it to these classes (LUCENE-1451, LUCENE-1658).
(Uwe Schindler)
Bug fixes Bug fixes
1. LUCENE-1415: MultiPhraseQuery has incorrect hashCode() and equals() 1. LUCENE-1415: MultiPhraseQuery has incorrect hashCode() and equals()

View File

@ -128,7 +128,7 @@ public class PerfRunData {
FileUtils.fullyDelete(indexDir); FileUtils.fullyDelete(indexDir);
} }
indexDir.mkdirs(); indexDir.mkdirs();
directory = FSDirectory.getDirectory(indexDir); directory = FSDirectory.open(indexDir);
} else { } else {
directory = new RAMDirectory(); directory = new RAMDirectory();
} }

View File

@ -52,7 +52,7 @@ public class QualityQueriesFinder {
System.err.println("Usage: java QualityQueriesFinder <index-dir>"); System.err.println("Usage: java QualityQueriesFinder <index-dir>");
System.exit(1); System.exit(1);
} }
QualityQueriesFinder qqf = new QualityQueriesFinder(FSDirectory.getDirectory(new File(args[0]))); QualityQueriesFinder qqf = new QualityQueriesFinder(FSDirectory.open(new File(args[0])));
String q[] = qqf.bestQueries("body",20); String q[] = qqf.bestQueries("body",20);
for (int i=0; i<q.length; i++) { for (int i=0; i<q.length; i++) {
System.out.println(newline+formatQueryAsTrecTopic(i,q[i],null,null)); System.out.println(newline+formatQueryAsTrecTopic(i,q[i],null,null));

View File

@ -92,7 +92,7 @@ public class StandardBenchmarker extends AbstractBenchmarker implements Benchmar
try try
{ {
reset(indexDir); reset(indexDir);
params[i].setDirectory(FSDirectory.getDirectory(indexDir)); params[i].setDirectory(FSDirectory.open(indexDir));
params[i].setQueries(qds); params[i].setQueries(qds);
System.out.println(params[i]); System.out.println(params[i]);
runBenchmark(params[i], options); runBenchmark(params[i], options);

View File

@ -82,7 +82,7 @@ public class TestQualityRun extends TestCase {
// validate topics & judgments match each other // validate topics & judgments match each other
judge.validateData(qqs, logger); judge.validateData(qqs, logger);
IndexSearcher searcher = new IndexSearcher(FSDirectory.getDirectory(new File(workDir,"index"))); IndexSearcher searcher = new IndexSearcher(FSDirectory.open(new File(workDir,"index")));
QualityQueryParser qqParser = new SimpleQQParser("title","body"); QualityQueryParser qqParser = new SimpleQQParser("title","body");
QualityBenchmark qrun = new QualityBenchmark(qqs, qqParser, searcher, docNameField); QualityBenchmark qrun = new QualityBenchmark(qqs, qqParser, searcher, docNameField);

View File

@ -47,7 +47,7 @@ import org.apache.lucene.store.RAMDirectory;
public class TestIndicesEquals extends TestCase { public class TestIndicesEquals extends TestCase {
// public void test2() throws Exception { // public void test2() throws Exception {
// FSDirectory fsdir = FSDirectory.getDirectory("/tmp/fatcorpus"); // FSDirectory fsdir = FSDirectory.open(new File("/tmp/fatcorpus"));
// IndexReader ir = IndexReader.open(fsdir); // IndexReader ir = IndexReader.open(fsdir);
// InstantiatedIndex ii = new InstantiatedIndex(ir); // InstantiatedIndex ii = new InstantiatedIndex(ir);
// ir.close(); // ir.close();

View File

@ -17,6 +17,7 @@ package org.apache.lucene.index;
*/ */
import java.io.IOException; import java.io.IOException;
import java.io.File;
import java.util.Date; import java.util.Date;
import org.apache.lucene.search.Similarity; import org.apache.lucene.search.Similarity;
@ -62,7 +63,7 @@ public class FieldNormModifier {
} }
} }
Directory d = FSDirectory.getDirectory(args[0], false); Directory d = FSDirectory.open(new File(args[0]));
FieldNormModifier fnm = new FieldNormModifier(d, s); FieldNormModifier fnm = new FieldNormModifier(d, s);
for (int i = 2; i < args.length; i++) { for (int i = 2; i < args.length; i++) {

View File

@ -41,7 +41,7 @@ public class IndexMergeTool {
Directory[] indexes = new Directory[args.length - 1]; Directory[] indexes = new Directory[args.length - 1];
for (int i = 1; i < args.length; i++) { for (int i = 1; i < args.length; i++) {
indexes[i - 1] = FSDirectory.getDirectory(args[i], false); indexes[i - 1] = FSDirectory.open(new File(args[i]));
} }
System.out.println("Merging..."); System.out.println("Merging...");

View File

@ -65,7 +65,7 @@ public class LengthNormModifier {
} }
File index = new File(args[0]); File index = new File(args[0]);
Directory d = FSDirectory.getDirectory(index,false); Directory d = FSDirectory.open(index);
LengthNormModifier lnm = new LengthNormModifier(d, s); LengthNormModifier lnm = new LengthNormModifier(d, s);

View File

@ -19,6 +19,7 @@ package org.apache.lucene.wordnet;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.io.File;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
@ -68,7 +69,7 @@ public final class SynExpand {
"java org.apache.lucene.wordnet.SynExpand <index path> <query>"); "java org.apache.lucene.wordnet.SynExpand <index path> <query>");
} }
FSDirectory directory = FSDirectory.getDirectory(args[0], false); FSDirectory directory = FSDirectory.open(new File(args[0]));
IndexSearcher searcher = new IndexSearcher(directory); IndexSearcher searcher = new IndexSearcher(directory);
String query = args[1]; String query = args[1];

View File

@ -19,6 +19,7 @@ package org.apache.lucene.wordnet;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.io.File;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
@ -51,7 +52,7 @@ public class SynLookup {
"java org.apache.lucene.wordnet.SynLookup <index path> <word>"); "java org.apache.lucene.wordnet.SynLookup <index path> <word>");
} }
FSDirectory directory = FSDirectory.getDirectory(args[0], false); FSDirectory directory = FSDirectory.open(new File(args[0]));
IndexSearcher searcher = new IndexSearcher(directory); IndexSearcher searcher = new IndexSearcher(directory);
String word = args[1]; String word = args[1];

View File

@ -17,6 +17,8 @@ package org.apache.lucene.demo;
* limitations under the License. * limitations under the License.
*/ */
import java.io.File;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory; import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
@ -37,7 +39,7 @@ public class DeleteFiles {
System.exit(1); System.exit(1);
} }
try { try {
Directory directory = FSDirectory.getDirectory("index"); Directory directory = FSDirectory.open(new File("index"));
IndexReader reader = IndexReader.open(directory); IndexReader reader = IndexReader.open(directory);
Term term = new Term("path", args[0]); Term term = new Term("path", args[0]);

View File

@ -26,6 +26,7 @@ import org.apache.lucene.document.Document;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.IOException; import java.io.IOException;
import java.io.File;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -702,7 +703,7 @@ public class CheckIndex {
System.out.println("\nOpening index @ " + indexPath + "\n"); System.out.println("\nOpening index @ " + indexPath + "\n");
Directory dir = null; Directory dir = null;
try { try {
dir = FSDirectory.getDirectory(indexPath); dir = FSDirectory.open(new File(indexPath));
} catch (Throwable t) { } catch (Throwable t) {
System.out.println("ERROR: could not open directory \"" + indexPath + "\"; exiting"); System.out.println("ERROR: could not open directory \"" + indexPath + "\"; exiting");
t.printStackTrace(System.out); t.printStackTrace(System.out);

View File

@ -456,12 +456,16 @@ class DirectoryReader extends IndexReader implements Cloneable {
DirectoryReader reader = null; DirectoryReader reader = null;
// While trying to reopen, we temporarily mark our /* TODO: Remove this in 3.0 - the directory is then
// closeDirectory as false. This way any exceptions hit * no longer owned by the IndexReader and must not be
// partway while opening the reader, which is expected * closed.
// eg if writer is committing, won't close our * While trying to reopen, we temporarily mark our
// directory. We restore this value below: * closeDirectory as false. This way any exceptions hit
final boolean myCloseDirectory = closeDirectory; * partway while opening the reader, which is expected
* eg if writer is committing, won't close our
* directory. We restore this value below:
*/
final boolean myCloseDirectory = closeDirectory; // @deprectated
closeDirectory = false; closeDirectory = false;
try { try {

View File

@ -97,7 +97,7 @@ public class IndexModifier {
protected Directory directory = null; protected Directory directory = null;
protected Analyzer analyzer = null; protected Analyzer analyzer = null;
protected boolean open = false; protected boolean open = false, closeDir = false;
// Lucene defaults: // Lucene defaults:
protected PrintStream infoStream = null; protected PrintStream infoStream = null;
@ -138,6 +138,7 @@ public class IndexModifier {
*/ */
public IndexModifier(String dirName, Analyzer analyzer, boolean create) throws CorruptIndexException, LockObtainFailedException, IOException { public IndexModifier(String dirName, Analyzer analyzer, boolean create) throws CorruptIndexException, LockObtainFailedException, IOException {
Directory dir = FSDirectory.getDirectory(dirName); Directory dir = FSDirectory.getDirectory(dirName);
this.closeDir = true;
init(dir, analyzer, create); init(dir, analyzer, create);
} }
@ -156,6 +157,7 @@ public class IndexModifier {
*/ */
public IndexModifier(File file, Analyzer analyzer, boolean create) throws CorruptIndexException, LockObtainFailedException, IOException { public IndexModifier(File file, Analyzer analyzer, boolean create) throws CorruptIndexException, LockObtainFailedException, IOException {
Directory dir = FSDirectory.getDirectory(file); Directory dir = FSDirectory.getDirectory(file);
this.closeDir = true;
init(dir, analyzer, create); init(dir, analyzer, create);
} }
@ -578,6 +580,10 @@ public class IndexModifier {
indexReader = null; indexReader = null;
} }
open = false; open = false;
if (closeDir) {
directory.close();
}
closeDir = false;
} }
} }

View File

@ -204,7 +204,8 @@ public abstract class IndexReader implements Cloneable {
* path. * path.
* @throws CorruptIndexException if the index is corrupt * @throws CorruptIndexException if the index is corrupt
* @throws IOException if there is a low-level IO error * @throws IOException if there is a low-level IO error
* @deprecated Use {@link #open(Directory, boolean)} instead * @deprecated This method will be removed in the 3.0 release.
* Use {@link #open(Directory, boolean)} instead
* @param path the path to the index directory */ * @param path the path to the index directory */
public static IndexReader open(String path) throws CorruptIndexException, IOException { public static IndexReader open(String path) throws CorruptIndexException, IOException {
return open(FSDirectory.getDirectory(path), true, null, null, false); return open(FSDirectory.getDirectory(path), true, null, null, false);
@ -220,7 +221,9 @@ public abstract class IndexReader implements Cloneable {
* @param path the path to the index directory * @param path the path to the index directory
* @param readOnly true if this should be a readOnly * @param readOnly true if this should be a readOnly
* reader * reader
* @deprecated Use {@link #open(Directory, boolean)} instead*/ * @deprecated This method will be removed in the 3.0 release.
* Use {@link #open(Directory, boolean)} instead
*/
public static IndexReader open(String path, boolean readOnly) throws CorruptIndexException, IOException { public static IndexReader open(String path, boolean readOnly) throws CorruptIndexException, IOException {
return open(FSDirectory.getDirectory(path), true, null, null, readOnly); return open(FSDirectory.getDirectory(path), true, null, null, readOnly);
} }
@ -230,7 +233,8 @@ public abstract class IndexReader implements Cloneable {
* @param path the path to the index directory * @param path the path to the index directory
* @throws CorruptIndexException if the index is corrupt * @throws CorruptIndexException if the index is corrupt
* @throws IOException if there is a low-level IO error * @throws IOException if there is a low-level IO error
* @deprecated Use {@link #open(Directory, boolean)} instead * @deprecated This method will be removed in the 3.0 release.
* Use {@link #open(Directory, boolean)} instead
*/ */
public static IndexReader open(File path) throws CorruptIndexException, IOException { public static IndexReader open(File path) throws CorruptIndexException, IOException {
return open(FSDirectory.getDirectory(path), true, null, null, false); return open(FSDirectory.getDirectory(path), true, null, null, false);
@ -246,8 +250,9 @@ public abstract class IndexReader implements Cloneable {
* @param path the path to the index directory * @param path the path to the index directory
* @param readOnly true if this should be a readOnly * @param readOnly true if this should be a readOnly
* reader * reader
* @deprecated Use {@link #open(Directory, boolean)} * @deprecated This method will be removed in the 3.0 release.
* instead */ * Use {@link #open(Directory, boolean)} instead
*/
public static IndexReader open(File path, boolean readOnly) throws CorruptIndexException, IOException { public static IndexReader open(File path, boolean readOnly) throws CorruptIndexException, IOException {
return open(FSDirectory.getDirectory(path), true, null, null, readOnly); return open(FSDirectory.getDirectory(path), true, null, null, readOnly);
} }
@ -257,7 +262,8 @@ public abstract class IndexReader implements Cloneable {
* @param directory the index directory * @param directory the index directory
* @throws CorruptIndexException if the index is corrupt * @throws CorruptIndexException if the index is corrupt
* @throws IOException if there is a low-level IO error * @throws IOException if there is a low-level IO error
* @deprecated Use {@link #open(Directory, boolean)} instead * @deprecated This method will be removed in the 3.0 release.
* Use {@link #open(Directory, boolean)} instead
*/ */
public static IndexReader open(final Directory directory) throws CorruptIndexException, IOException { public static IndexReader open(final Directory directory) throws CorruptIndexException, IOException {
return open(directory, false, null, null, false); return open(directory, false, null, null, false);
@ -281,7 +287,8 @@ public abstract class IndexReader implements Cloneable {
* {@link IndexCommit}. * {@link IndexCommit}.
* @param commit the commit point to open * @param commit the commit point to open
* @throws CorruptIndexException if the index is corrupt * @throws CorruptIndexException if the index is corrupt
* @deprecated Use {@link #open(IndexCommit, boolean)} instead * @deprecated This method will be removed in the 3.0 release.
* Use {@link #open(IndexCommit, boolean)} instead
* @throws IOException if there is a low-level IO error * @throws IOException if there is a low-level IO error
*/ */
public static IndexReader open(final IndexCommit commit) throws CorruptIndexException, IOException { public static IndexReader open(final IndexCommit commit) throws CorruptIndexException, IOException {
@ -308,8 +315,8 @@ public abstract class IndexReader implements Cloneable {
* @param deletionPolicy a custom deletion policy (only used * @param deletionPolicy a custom deletion policy (only used
* if you use this reader to perform deletes or to set * if you use this reader to perform deletes or to set
* norms); see {@link IndexWriter} for details. * norms); see {@link IndexWriter} for details.
* @deprecated Use {@link #open(Directory, * @deprecated This method will be removed in the 3.0 release.
* IndexDeletionPolicy, boolean)} instead * Use {@link #open(Directory, IndexDeletionPolicy, boolean)} instead
* @throws CorruptIndexException if the index is corrupt * @throws CorruptIndexException if the index is corrupt
* @throws IOException if there is a low-level IO error * @throws IOException if there is a low-level IO error
*/ */
@ -344,8 +351,8 @@ public abstract class IndexReader implements Cloneable {
* @param deletionPolicy a custom deletion policy (only used * @param deletionPolicy a custom deletion policy (only used
* if you use this reader to perform deletes or to set * if you use this reader to perform deletes or to set
* norms); see {@link IndexWriter} for details. * norms); see {@link IndexWriter} for details.
* @deprecated Use {@link #open(IndexCommit, * @deprecated This method will be removed in the 3.0 release.
* IndexDeletionPolicy, boolean)} instead * Use {@link #open(IndexCommit, IndexDeletionPolicy, boolean)} instead
* @throws CorruptIndexException if the index is corrupt * @throws CorruptIndexException if the index is corrupt
* @throws IOException if there is a low-level IO error * @throws IOException if there is a low-level IO error
*/ */
@ -500,6 +507,8 @@ public abstract class IndexReader implements Cloneable {
* {@link #isCurrent()} instead. * {@link #isCurrent()} instead.
* @throws CorruptIndexException if the index is corrupt * @throws CorruptIndexException if the index is corrupt
* @throws IOException if there is a low-level IO error * @throws IOException if there is a low-level IO error
* @deprecated This method will be removed in the 3.0 release.
* Use {@link #lastModified(Directory)} instead
*/ */
public static long lastModified(String directory) throws CorruptIndexException, IOException { public static long lastModified(String directory) throws CorruptIndexException, IOException {
return lastModified(new File(directory)); return lastModified(new File(directory));
@ -511,13 +520,16 @@ public abstract class IndexReader implements Cloneable {
* {@link #isCurrent()} instead. * {@link #isCurrent()} instead.
* @throws CorruptIndexException if the index is corrupt * @throws CorruptIndexException if the index is corrupt
* @throws IOException if there is a low-level IO error * @throws IOException if there is a low-level IO error
* @deprecated This method will be removed in the 3.0 release.
* Use {@link #lastModified(Directory)} instead
*/ */
public static long lastModified(File fileDirectory) throws CorruptIndexException, IOException { public static long lastModified(File fileDirectory) throws CorruptIndexException, IOException {
return ((Long) new SegmentInfos.FindSegmentsFile(fileDirectory) { Directory dir = FSDirectory.getDirectory(fileDirectory); // use new static method here
public Object doBody(String segmentFileName) { try {
return new Long(FSDirectory.fileModified(fileDirectory, segmentFileName)); return lastModified(dir);
} } finally {
}.run()).longValue(); dir.close();
}
} }
/** /**
@ -544,6 +556,8 @@ public abstract class IndexReader implements Cloneable {
* @return version number. * @return version number.
* @throws CorruptIndexException if the index is corrupt * @throws CorruptIndexException if the index is corrupt
* @throws IOException if there is a low-level IO error * @throws IOException if there is a low-level IO error
* @deprecated This method will be removed in the 3.0 release.
* Use {@link #getCurrentVersion(Directory)} instead
*/ */
public static long getCurrentVersion(String directory) throws CorruptIndexException, IOException { public static long getCurrentVersion(String directory) throws CorruptIndexException, IOException {
return getCurrentVersion(new File(directory)); return getCurrentVersion(new File(directory));
@ -558,7 +572,8 @@ public abstract class IndexReader implements Cloneable {
* @return version number. * @return version number.
* @throws CorruptIndexException if the index is corrupt * @throws CorruptIndexException if the index is corrupt
* @throws IOException if there is a low-level IO error * @throws IOException if there is a low-level IO error
* @deprecated Use {@link #getCurrentVersion(Directory)} instead * @deprecated This method will be removed in the 3.0 release.
* Use {@link #getCurrentVersion(Directory)} instead
*/ */
public static long getCurrentVersion(File directory) throws CorruptIndexException, IOException { public static long getCurrentVersion(File directory) throws CorruptIndexException, IOException {
Directory dir = FSDirectory.getDirectory(directory); Directory dir = FSDirectory.getDirectory(directory);
@ -741,6 +756,8 @@ public abstract class IndexReader implements Cloneable {
* <code>false</code> is returned. * <code>false</code> is returned.
* @param directory the directory to check for an index * @param directory the directory to check for an index
* @return <code>true</code> if an index exists; <code>false</code> otherwise * @return <code>true</code> if an index exists; <code>false</code> otherwise
* @deprecated This method will be removed in the 3.0 release.
* Use {@link #indexExists(Directory)} instead
*/ */
public static boolean indexExists(String directory) { public static boolean indexExists(String directory) {
return indexExists(new File(directory)); return indexExists(new File(directory));
@ -751,6 +768,8 @@ public abstract class IndexReader implements Cloneable {
* If the directory does not exist or if there is no index in it. * If the directory does not exist or if there is no index in it.
* @param directory the directory to check for an index * @param directory the directory to check for an index
* @return <code>true</code> if an index exists; <code>false</code> otherwise * @return <code>true</code> if an index exists; <code>false</code> otherwise
* @deprecated This method will be removed in the 3.0 release.
* Use {@link #indexExists(Directory)} instead
*/ */
public static boolean indexExists(File directory) { public static boolean indexExists(File directory) {
@ -1159,7 +1178,8 @@ public abstract class IndexReader implements Cloneable {
* currently locked. * currently locked.
* @param directory the directory to check for a lock * @param directory the directory to check for a lock
* @throws IOException if there is a low-level IO error * @throws IOException if there is a low-level IO error
* @deprecated Please use {@link IndexWriter#isLocked(Directory)} instead * @deprecated This method will be removed in the 3.0 release.
* Please use {@link IndexWriter#isLocked(Directory)} instead
*/ */
public static boolean isLocked(Directory directory) throws IOException { public static boolean isLocked(Directory directory) throws IOException {
return return
@ -1171,7 +1191,8 @@ public abstract class IndexReader implements Cloneable {
* currently locked. * currently locked.
* @param directory the directory to check for a lock * @param directory the directory to check for a lock
* @throws IOException if there is a low-level IO error * @throws IOException if there is a low-level IO error
* @deprecated Please use {@link IndexWriter#isLocked(Directory)} instead * @deprecated This method will be removed in the 3.0 release.
* Use {@link #isLocked(Directory)} instead
*/ */
public static boolean isLocked(String directory) throws IOException { public static boolean isLocked(String directory) throws IOException {
Directory dir = FSDirectory.getDirectory(directory); Directory dir = FSDirectory.getDirectory(directory);
@ -1186,7 +1207,8 @@ public abstract class IndexReader implements Cloneable {
* Caution: this should only be used by failure recovery code, * Caution: this should only be used by failure recovery code,
* when it is known that no other process nor thread is in fact * when it is known that no other process nor thread is in fact
* currently accessing this index. * currently accessing this index.
* @deprecated Please use {@link IndexWriter#unlock(Directory)} instead * @deprecated This method will be removed in the 3.0 release.
* Please use {@link IndexWriter#unlock(Directory)} instead
*/ */
public static void unlock(Directory directory) throws IOException { public static void unlock(Directory directory) throws IOException {
directory.makeLock(IndexWriter.WRITE_LOCK_NAME).release(); directory.makeLock(IndexWriter.WRITE_LOCK_NAME).release();
@ -1236,7 +1258,7 @@ public abstract class IndexReader implements Cloneable {
File file = new File(filename); File file = new File(filename);
String dirname = file.getAbsoluteFile().getParent(); String dirname = file.getAbsoluteFile().getParent();
filename = file.getName(); filename = file.getName();
dir = FSDirectory.getDirectory(dirname); dir = FSDirectory.open(new File(dirname));
cfr = new CompoundFileReader(dir, filename); cfr = new CompoundFileReader(dir, filename);
String [] files = cfr.list(); String [] files = cfr.list();

View File

@ -17,7 +17,6 @@ package org.apache.lucene.index;
* limitations under the License. * limitations under the License.
*/ */
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IndexInput; import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput; import org.apache.lucene.store.IndexOutput;
@ -523,13 +522,8 @@ final class SegmentInfos extends Vector {
*/ */
public abstract static class FindSegmentsFile { public abstract static class FindSegmentsFile {
File fileDirectory;
Directory directory; Directory directory;
public FindSegmentsFile(File directory) {
this.fileDirectory = directory;
}
public FindSegmentsFile(Directory directory) { public FindSegmentsFile(Directory directory) {
this.directory = directory; this.directory = directory;
} }
@ -582,10 +576,7 @@ final class SegmentInfos extends Vector {
long genA = -1; long genA = -1;
if (directory != null) files = directory.listAll();
files = directory.listAll();
else
files = FSDirectory.listAll(fileDirectory);
if (files != null) if (files != null)
genA = getCurrentSegmentGeneration(files); genA = getCurrentSegmentGeneration(files);
@ -732,10 +723,7 @@ final class SegmentInfos extends Vector {
gen-1); gen-1);
final boolean prevExists; final boolean prevExists;
if (directory != null) prevExists = directory.fileExists(prevSegmentFileName);
prevExists = directory.fileExists(prevSegmentFileName);
else
prevExists = new File(fileDirectory, prevSegmentFileName).exists();
if (prevExists) { if (prevExists) {
message("fallback to prior segment file '" + prevSegmentFileName + "'"); message("fallback to prior segment file '" + prevSegmentFileName + "'");

View File

@ -46,7 +46,7 @@ public class IndexSearcher extends Searcher {
/** Creates a searcher searching the index in the named directory. /** Creates a searcher searching the index in the named directory.
* @throws CorruptIndexException if the index is corrupt * @throws CorruptIndexException if the index is corrupt
* @throws IOException if there is a low-level IO error * @throws IOException if there is a low-level IO error
* @deprecated Use {@link #IndexSearcher(String, boolean)} instead * @deprecated Use {@link #IndexSearcher(Directory, boolean)} instead
*/ */
public IndexSearcher(String path) throws CorruptIndexException, IOException { public IndexSearcher(String path) throws CorruptIndexException, IOException {
this(IndexReader.open(path), true); this(IndexReader.open(path), true);
@ -62,6 +62,7 @@ public class IndexSearcher extends Searcher {
* will be opened readOnly * will be opened readOnly
* @throws CorruptIndexException if the index is corrupt * @throws CorruptIndexException if the index is corrupt
* @throws IOException if there is a low-level IO error * @throws IOException if there is a low-level IO error
* @deprecated Use {@link #IndexSearcher(Directory, boolean)} instead
*/ */
public IndexSearcher(String path, boolean readOnly) throws CorruptIndexException, IOException { public IndexSearcher(String path, boolean readOnly) throws CorruptIndexException, IOException {
this(IndexReader.open(path, readOnly), true); this(IndexReader.open(path, readOnly), true);

View File

@ -40,7 +40,7 @@ to check if the results are what we expect):</p>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#3f7f5f">//&nbsp;Store&nbsp;the&nbsp;index&nbsp;in&nbsp;memory:</font><br /> <font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#3f7f5f">//&nbsp;Store&nbsp;the&nbsp;index&nbsp;in&nbsp;memory:</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">Directory&nbsp;directory&nbsp;=&nbsp;</font><font color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">RAMDirectory</font><font color="#000000">()</font><font color="#000000">;</font><br /> <font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">Directory&nbsp;directory&nbsp;=&nbsp;</font><font color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">RAMDirectory</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#3f7f5f">//&nbsp;To&nbsp;store&nbsp;an&nbsp;index&nbsp;on&nbsp;disk,&nbsp;use&nbsp;this&nbsp;instead:</font><br /> <font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#3f7f5f">//&nbsp;To&nbsp;store&nbsp;an&nbsp;index&nbsp;on&nbsp;disk,&nbsp;use&nbsp;this&nbsp;instead:</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#3f7f5f">//Directory&nbsp;directory&nbsp;=&nbsp;FSDirectory.getDirectory(&#34;/tmp/testindex&#34;);</font><br /> <font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#3f7f5f">//Directory&nbsp;directory&nbsp;=&nbsp;FSDirectory.open(&#34;/tmp/testindex&#34;);</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">IndexWriter&nbsp;iwriter&nbsp;=&nbsp;</font><font color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">IndexWriter</font><font color="#000000">(</font><font color="#000000">directory,&nbsp;analyzer,&nbsp;true,</font><br /> <font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">IndexWriter&nbsp;iwriter&nbsp;=&nbsp;</font><font color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">IndexWriter</font><font color="#000000">(</font><font color="#000000">directory,&nbsp;analyzer,&nbsp;true,</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">IndexWriter.MaxFieldLength</font><font color="#000000">(</font><font color="#990000">25000</font><font color="#000000">))</font><font color="#000000">;</font><br /> <font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">IndexWriter.MaxFieldLength</font><font color="#000000">(</font><font color="#990000">25000</font><font color="#000000">))</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">Document&nbsp;doc&nbsp;=&nbsp;</font><font color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">Document</font><font color="#000000">()</font><font color="#000000">;</font><br /> <font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">Document&nbsp;doc&nbsp;=&nbsp;</font><font color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">Document</font><font color="#000000">()</font><font color="#000000">;</font><br />

View File

@ -49,7 +49,7 @@ public class TestDemo extends LuceneTestCase {
// Store the index in memory: // Store the index in memory:
Directory directory = new RAMDirectory(); Directory directory = new RAMDirectory();
// To store an index on disk, use this instead: // To store an index on disk, use this instead:
//Directory directory = FSDirectory.getDirectory("/tmp/testindex"); //Directory directory = FSDirectory.open(new File("/tmp/testindex"));
IndexWriter iwriter = new IndexWriter(directory, analyzer, true, IndexWriter iwriter = new IndexWriter(directory, analyzer, true,
new IndexWriter.MaxFieldLength(25000)); new IndexWriter.MaxFieldLength(25000));
Document doc = new Document(); Document doc = new Document();

View File

@ -54,7 +54,7 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCase
try { try {
// Sometimes past test leaves the dir // Sometimes past test leaves the dir
_TestUtil.rmDir(dir); _TestUtil.rmDir(dir);
Directory fsDir = FSDirectory.getDirectory(dir); Directory fsDir = FSDirectory.open(dir);
runTest(fsDir); runTest(fsDir);
fsDir.close(); fsDir.close();
} finally { } finally {