On Fri, Jan 17, 2014 at 4:59 AM, Mindaugas Žakšauskas <min...@gmail.com> wrote: > Hi, > >>> 1 indexWriter.deleteDocuments(query); // same for terms arg >>> 2 if (indexWriter.hasUncommittedChanges()) { >>> 3 indexWriter.commit(); >>> 4 } >> >> hasUncommittedChanges will return true if you deleted (by Term or >> Query), even if that Term or Query matches no documents. > > Mhm, this is surprising (in a negative sense). So is there any way to > know if these deletions have actually affected any documents?
I suppose you could pull an NRT reader and do a search by that Term/Query and see if the totalHits is non-zero? But that is of course costly in general, and this cost is the reason why IW can't tell you. It only buffers up a bunch of deletions and then later applies them in bulk. > How about indexWorker.hasDeletions()? hasDeletions will also return true if you had just deleted by Term or Query that in fact match no documents. > Contracts of these methods are not > documented well enough and I don't feel too confident to make > independent decisions just by looking at the source code :-( Good point; I'll improve the javadocs for hasUncommittedChanges and hasDeletions. Backing up, what is your app doing, that it so strongly relies on knowing whether commit() would do anything? Usually, commit is something you call rarely, for "safety" purposes to ensure if the world comes crashing down, you'll have a known state in the index on restart. Mike McCandless http://blog.mikemccandless.com --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org