In my case, every document inserted into lucene index has its unique ID. When adding a new document into lucene index, if the document has existed in index, the document should not be inserted into index. How to implement this strategy?
I think I should first search the document with docId, if lucene can't find the document, then I insert it. However, because I have 3 threads sharing the only indexWriter to index, I guess there's should be some wrong cases. For example: thread 1 and thread 2 are handling two documents with same docId, if thread1 searched the docId and found nothing, it would insert the document into the index, but thread2 may insert its document into index after thread1 reading the index. As a result, there exist two documents in the index. How can I avoid this?
1
votes
1 Answers
5
votes