Get number of pending changes on IndexWriter
We have home grown search service based on Lucene. One particular question I'm faced some time ago was getting number of pending changes on IndexWriter
. If the pending changes counter is zero there is no need to commit to the index, reopen IndexReader
, IndexSearcher
and so on. Also we have s开发者_JAVA百科ome application level logic that is linked to IndexReader.commit()
call and it's better not to call it if there is no actual changes in commit point.
I have access to all the places where methods IndexReader.updateDocument()
and IndexReader.remove()
are called, so I simply can write my own counter of pending changes. But I'm intrested may be there is already exists one in the Lucene API itself? API check doesn't give me enough information on the topic.
You can use IndexWriter.numRAMDocs
to get number of documents added, but I think there is no public API to get the current count of buffered deletes.
IndexWriter.ramSizeInBytes
might also be useful here. It tells you how much RAM is currently in-use, so this will increase as you add or delete docs (but decrease when a flush takes place).
Note that IndexReader.isCurrent
is only usable if you commit the changes from the IndexWriter
, ie if you have pending changes but have not committed (or closed) the writer then IndexReader.isCurrent
will still return true.
See IndexReader.isCurrent().
精彩评论