Closing the IndexSearcher is best only after a deleteDocuments with a reader or changes with a writer.
For performance reasons, it is better to not close the IndexSearcher if not needed Regarsd Ard > > > sorry, the subject should be "Should the IndexSearcher be > closed after > every search completed" > ~~~~~ > >Hi, > > > >Should the IndexSearcher instance be closed after very > search completed. > > > >I wrote a sample, but I have not closed the singleton instatnce of > >IndexSearcher unless IndexReader#isCurrent() return false. > > > >Now the sample runs well, but I saw almost other samples > would close the > >IndexSearcher instance on the end of very search. > > > >Should I do it like them? > > > >By the way, I use the constructor IndexSearcher(Directory > directory), so > >should I call the method IndexSearcher.close()? > > > > > >------------------------------------ > >the Code sample: > >------------------------------------ > >public IndexSearcher getIndexSearcher() throws IOException { > > > > if (this.indexSearcher == null) { > > return new IndexSearcher(getIndexDirectory()); > > } else { > > IndexReader ir = indexSearcher.getIndexReader(); > > if(!ir.isCurrent()){ > > this.indexSearcher.close(); > > this.indexSearcher=new IndexSearcher > >(getIndexDirectory()); > > ir=indexSearcher.getIndexReader(); > > if(ir.hasDeletions()){ > > if (this.indexWriter != null) { > > this.indexWriter.optimize(); > > } > > } > > } > > return this.indexSearcher; > > } > >} > > > > > >Best regards > >Anson > > > >--------------------------------------------------------------------- > >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] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]