lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <>
Subject Re: indexReader close method
Date Mon, 06 Dec 2004 20:31:45 GMT

: Do you know why I can't close the IndexReader  explicitly under some
: circumstances and why, when I do manage to close it I can still call
: methods on the reader?

1) I tried to create a test case that demonstrated your bug based on the
code outline you provided, and i couldn't (see below).  that implies to me
that somethine else is going on.  If you can create a completely self
contained program that demonstrates your bug and mail it to the list that
would help us help you.

2) the documentation for IndexReader.close() says...

	Closes files associated with this index. Also saves any new deletions to
	disk. No other methods should be called after this has been called.

...note the word "should".  it doesn't say what the other methods will do
if you try to call them, just that you shouldn't try.  In some cases they
may generate exceptions, in other cases they may just be able to return
you data based on state internal to the object which is unaffected by the
fact that the files have all been closed.


    public static void main(String argv[]) throws IOException {

        /* create a directory */
        String d = System.getProperty("", "tmp")
            + System.getProperty("file.separator")
            + "index-dir-" + (new Random()).nextInt(1000);
        Directory trash = FSDirectory.getDirectory(d, true);

        /* build index */
        Document doc;
        IndexWriter w = new IndexWriter(d, new SimpleAnalyzer(), true);
        doc = new Document();
        doc.add(Field.Text("words", "apple emu"));

        /* search index */
        IndexReader r =;
        IndexSearcher s = new IndexSearcher(r);
        Hits h = TermQuery(new Term("words", "apple")));


        System.out.println("Reader? - " + r.maxDoc());


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message