Hi,
> We're writing a web application, which naturally needs > - "IndexSearcher" when users use our search screen > - "IndexWriter" in a background process that periodically updates and > optimizes our index. > Note our writer is exclusive - no other applications/threads ever write to our > index files. > > What's the common practice in terms of resource creation and sharing? > Specifically: > > 1) Should I have a single IndexSearcher to serve all (concurrent) users? > I saw such a recommendation in a tutorial, but discovered that an open > IndexSearcher prevents 'optimize' from merging my files... so should I close it > just before optimization? Or should I open an individual (short-lived) > IndexSearcher for each search request? You can leave the IndexWriter and IndexSearcher all the time. The only important thing, changes made by IndexWriter's commit() method are only seen by IndexSearcher, when the underlying IndexReader is reopened (e.g. by using IndexReader.reopen()) - please note that this only works with direct access to the IndexReaders, so I would recommend using the constructors of IndexSearcher that take IndexReaders (the Directory ones are only for easy beginner's use). See the Lucene In Action 2 for a good example of a Searcher manager. > 2) Our tests also imply that IndexWriter.optimize() takes effect only after > you close() that writer - which is a shame, because I hoped to keep using the > same writer (I hear it's expensive to instantiate). I doing something wrong? This is wrong, see above. As the IndexReader/Searcher keeps the used segments from the time it was opened, they can't go away until the "snapshot" view of IndexReader is closed. In general, it's not recommeneded to optimize indexes since 2.9 unless you are doing things like delete all documents. Uwe --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org