4

I am a Lucene.net novice and trying to adapt the search code from here which essentially creates a new Analyzer, IndexSearcher and IndexWriter objects in every method and only the FSDirectory object is being reused.

Question: Is there a recommended best practice here for reusing these objects?

Previous results for Lucene.Net optimization are from years ago, and from personal experience the Lucene.Net library has changed: downloading examples and compiling them with 3.0.3 does not work without changing the code.

alizx
  • 1,148
  • 2
  • 15
  • 27
Kumar
  • 10,997
  • 13
  • 84
  • 134
  • I would advise against the example code on the CodeProject link, as their 'best practices' have caused [problems in previous cases](http://stackoverflow.com/questions/15013032/why-is-lucene-net-indexer-throwing-a-system-io-ioexception-was-unhandled). – rae1 Mar 03 '13 at 19:54

2 Answers2

2

How about BestPractices, from the official wiki?

groverboy
  • 1,133
  • 8
  • 20
  • that's java-lucene docs, per the guys on the lucene java list, that's not the right place for .net version – Kumar Feb 27 '13 at 04:52
  • 2
    Your question is also tagged `lucene`, not only `lucene.net`. Even so these best practices apply to all Lucene implementations. Did you actually read them? – groverboy Feb 27 '13 at 05:44
2

In our project, we reuse the Analyzer and inject it with a pre-defined Version to the IndexWriter and the IndexReader. It is recommended that the Analyzer be the same when indexing and when searching, so at least the pattern applies for it.

Since, the last two are wrappers for actual Lucene index access, you will need to instantiate an index stream every time you use them, and it would make little sense to reuse them as they will block concurrent calls (both reads and writes).

There are some 'best practices' and patterns in this project that you can take advantage on.

rae1
  • 6,066
  • 4
  • 27
  • 48