views:

429

answers:

2

Before calling AddDocument() on IndexWriter, is it ok if i call IndexReader.IsLocked(myDirectory) and if it returns true then call, IndexReader.Unlock(myDirectory)?? Please suggest. ie...

if(IndexReader.IsLocked(myDirectory)) { IndexReader.Unlock(myDirectory); }

writer = new IndexWriter(myDirectory, _analyzer, true); writer.AddDocument(doc);

I keep getting "Lock obtain timed out." errors in my code. To overcome this error,I plan to this approach if it is ok.

Thanks for reading.

+1  A: 

Getting the "Lock obtain timed out" error is a warning sign that something is wrong with the way you handle your index. If you have more than one IndexWriter writing to the index, forcing unlock would likely cause your index to get corrupted.

However, in my experience it's easy to get those errors when you're working on the code, since the occasional crashes and interrupted debug sessions can leave you index locked, even though no process is writing to it anymore.

If that is the case, it would be OK to unlock the index at the start of the process. Don't call it every time before calling addDocument, just once when creating the IndexWriter.

In any case, make sure you close all IndexWriters properly before exiting the process.

itsadok
thanks for ur valuable inputs...am a newbie to Lucene...just wanted to know the things i need to take care of when I'm exposing Lucene search API through a web application where concurrent users could be updating Lucene index at the same time....
Steve Chapman
Hi itsadok,Can you please answer this one??http://stackoverflow.com/questions/1052086/spatialquery-for-location-based-search-using-luceneThanks.
A: 

Important point to remember with Lucene, only one thread should be updating the index... so there are concurrent users on the website, but one only user should be updating.

If you do not handle that properly, you will run into problems... You can have multiple reads/queries but not writes

Aaron Saunders
thanks for ur comments...can you please also look into this one?http://stackoverflow.com/questions/899542/problem-using-same-instance-of-indexsearcher-for-multiple-requests
Steve Chapman