Re: Closed IndexWriter reuse

2005-01-21 Thread Oscar Picasso
> --- Otis Gospodnetic <[EMAIL PROTECTED]> wrote:
> 
> > No, you can't add documents to an index once you close the IndexWriter.
> > You can re-open the IndexWriter and add more documents, of course.
> > 
> > Otis

After my previous post I have made some further tests with multithreading and
effectively it randomly throw NullPointerExceptions and Lock exceptions when
reusing a closed IndexWriter.

My example was bad because based on a very simple single thread.

But wouldn't it be safer if IndexWriter rose immediatly an Exception when
trying to use its modifying methods after is has been closed?



__ 
Do you Yahoo!? 
Yahoo! Mail - 250MB free storage. Do more. Manage less. 
http://info.mail.yahoo.com/mail_250

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Closed IndexWriter reuse

2005-01-21 Thread Oscar Picasso
--- Otis Gospodnetic <[EMAIL PROTECTED]> wrote:

> No, you can't add documents to an index once you close the IndexWriter.
> You can re-open the IndexWriter and add more documents, of course.
> 
> Otis

That's what I expected at first, but:
1- It's a disappointment, because such a 'feature' would have made IndexeWriter
management much easier. You would open an IndexWriter at startup and reuse it
during all the life of the application, just flushing on a regular base using
the close() method and without worrying if other objects are currently using
the writer.

2- When you say you can't add, do you mean it's impossible or that you
shouldn't because for example it could corrupt the index?
Maybe I'm wrong, but I think it's possible. Let's look at the follwoing code:
"


public static void main(String[] args) throws IOException
{
final IndexWriter writer1 = new IndexWriter("/tmp/test-reuse", new
StandardAnalyzer(), true);

// First write with the writer
Document doc = new Document();
doc.add(new Field("name", "John", Field.Store.YES, 
Field.Index.UN_TOKENIZED));
writer1.addDocument(doc);
System.out.println("1  After first write, before closing the writer 
---");
Searcher searcher = new IndexSearcher("/tmp/test-reuse");
Query query = new TermQuery(new Term("name", "John"));
Hits hits = searcher.search(query);
System.out.println("===> hits: " + hits.length());
System.out.println();

// CLOSING THE WRITER ONCE
writer1.close();
System.out.println("2  After first write, after closing the writer 
---");
searcher = new IndexSearcher("/tmp/test-reuse");
hits = searcher.search(query);
System.out.println("===> hits: " + hits.length());
System.out.println();

// Second write, THE WRITER HAS ALREADY BEEN CLOSED ONCE
writer1.addDocument(doc);
System.out.println("3  After second write, the writer has been 
closed once
---");
hits = searcher.search(query);
System.out.println("===> hits: " + hits.length());
System.out.println();

// Closing the writer again
writer1.close();
System.out.println("4  After second write, the writer has been 
closed
twice ---");
searcher = new IndexSearcher("/tmp/test-reuse");
hits = searcher.search(query);
System.out.println("===> hits: " + hits.length());

}

== Results ==
1  After first write, before closing the writer ---
===> hits: 0

2  After first write, after closing the writer ---
===> hits: 1

3  After second write, the writer has been closed once ---
===> hits: 1

4  After second write, the writer has been closed twice ---
===> hits: 2


As your can see, not only does the code above execute without complain but it
also gives the right results.

Thanks for your comments.



__ 
Do you Yahoo!? 
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Closed IndexWriter reuse

2005-01-20 Thread Otis Gospodnetic
No, you can't add documents to an index once you close the IndexWriter.
You can re-open the IndexWriter and add more documents, of course.

Otis

--- Oscar Picasso <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> Is it safe to add documents to an IndexWriter that has been closed? 
> 
> From what I have seen, the close method flush the changes, closes the
> files but
> it creates new files allowing to add new documents.
> 
> Am I right?
> 
> Thanks.
> 
> 
>   
> __ 
> Do you Yahoo!? 
> Yahoo! Mail - Easier than ever with enhanced search. Learn more.
> http://info.mail.yahoo.com/mail_250
> 
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Closed IndexWriter reuse

2005-01-20 Thread Oscar Picasso
Hi,

Is it safe to add documents to an IndexWriter that has been closed? 

>From what I have seen, the close method flush the changes, closes the files but
it creates new files allowing to add new documents.

Am I right?

Thanks.



__ 
Do you Yahoo!? 
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]