You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by "Hiller, Dean x66079" <de...@broadridge.com> on 2011/06/22 21:24:22 UTC

IndexWriter.optimize not using it breaks my test case :(

I read that in a lot of cases IndexWriter.optimize does not have to be called.

I then deleted it and my junit test case broke because results were coming back in the query that were not supposed to be coming back :(.  I think everything is single tested.  Maybe I should write a more raw junit test first? But I thought I would ask what exactly is optimize doing and is Lucene thread safe...I read that it was somewhere(but also read elsewhere it wasn't).

I kind of assumed my IndexWriters are not thread safe, but my IndexSearcher could be running while another thread is using the IndexWriter, right?

(Of course, while my unit test is single threaded and failed with just this one line change, our production system will be multithreaded which is why I ask).

Thanks,
Dean

This message and any attachments are intended only for the use of the addressee and
may contain information that is privileged and confidential. If the reader of the 
message is not the intended recipient or an authorized representative of the
intended recipient, you are hereby notified that any dissemination of this
communication is strictly prohibited. If you have received this communication in
error, please notify us immediately by e-mail and delete the message and any
attachments from your system.


Re: IndexWriter.optimize not using it breaks my test case :(

Posted by Ian Lea <ia...@gmail.com>.
>From the 3.2.0 javadocs:

"Optimize is a fairly costly operation, so you should only do it if
your search performance really requires it. Many search applications
do fine never calling optimize."


See the FAQ and javadocs on searchers and writers for thread safety info.

One thing that optimize does do is clear out deleted documents.  Could
that be relevant to your test failure?  If so, there is an
expungeDeletes() method you could maybe use instead.


--
Ian.

On Wed, Jun 22, 2011 at 8:24 PM, Hiller, Dean  x66079
<de...@broadridge.com> wrote:
> I read that in a lot of cases IndexWriter.optimize does not have to be called.
>
> I then deleted it and my junit test case broke because results were coming back in the query that were not supposed to be coming back :(.  I think everything is single tested.  Maybe I should write a more raw junit test first? But I thought I would ask what exactly is optimize doing and is Lucene thread safe...I read that it was somewhere(but also read elsewhere it wasn't).
>
> I kind of assumed my IndexWriters are not thread safe, but my IndexSearcher could be running while another thread is using the IndexWriter, right?
>
> (Of course, while my unit test is single threaded and failed with just this one line change, our production system will be multithreaded which is why I ask).
>
> Thanks,
> Dean

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org