mirror of https://github.com/apache/lucene.git
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:
parent
9798fac712
commit
96e1b41127
|
@ -32,24 +32,36 @@ 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) {
|
||||
reader = r;
|
||||
this(r, false);
|
||||
}
|
||||
|
||||
// inherit javadoc
|
||||
private IndexSearcher(IndexReader r, boolean closeReader) {
|
||||
reader = r;
|
||||
this.closeReader = closeReader;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
if(closeReader)
|
||||
reader.close();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue