Making bahavior of close() more consistent.

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150307 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Christoph Goller 2004-04-21 17:26:28 +00:00
parent 9798fac712
commit 96e1b41127
1 changed files with 16 additions and 4 deletions

View File

@ -32,25 +32,37 @@ import org.apache.lucene.util.PriorityQueue;
*/
public class IndexSearcher extends Searcher {
IndexReader reader;
private boolean closeReader;
/** Creates a searcher searching the index in the named directory. */
public IndexSearcher(String path) throws IOException {
this(IndexReader.open(path));
this(IndexReader.open(path), true);
}
/** Creates a searcher searching the index in the provided directory. */
public IndexSearcher(Directory directory) throws IOException {
this(IndexReader.open(directory));
this(IndexReader.open(directory), true);
}
/** Creates a searcher searching the provided index. */
public IndexSearcher(IndexReader r) {
this(r, false);
}
private IndexSearcher(IndexReader r, boolean closeReader) {
reader = r;
this.closeReader = closeReader;
}
// inherit javadoc
/**
* Note that the underlying IndexReader is not closed, if
* IndexSearcher was constructed with IndexSearcher(IndexReader r).
* If the IndexReader was supplied implicitly by specifying a directory, then
* the IndexReader gets closed.
*/
public void close() throws IOException {
reader.close();
if(closeReader)
reader.close();
}
// inherit javadoc