|
[
Permlink
| « Hide
]
Yonik Seeley added a comment - 11/Jan/08 08:34 PM
How about just using maxDoc() - numDocs()?
This is an option, however it will result in two calls to maxDoc() (once by maxDoc() and another by numDocs()).
Like I wrote, it's more of a convenience method and having a complete and clear API. This way, users of Lucene won't need to ask themselves how to obtain this number - they'll have an explicit API for that. A very simple patch that implements numDeletedDocs in all the necessary readers.
Shai Erera made changes - 12/Jan/08 05:27 AM
I think maxDoc() is a cheap call, so calling it twice won't be a performance killer, esp. since this is not something you'd call frequently, I imagine.
However, I do agree about numDeletedDocs() being nice for hiding implementation details.
Otis Gospodnetic made changes - 14/Jan/08 06:55 PM
Otis is this one ready to go in?
I think so - applies and compiles.
Hmm – this breaks back compat (adds new abstract method to IndexReader).
Why don't we fallback to default impl, in IndexReader, of maxDoc() - numDocs()? Patch is much less invasive, and, we don't break back compat? maxDoc() is indeed cheap. What if we implement numDeletedDocs() in IndexReader, instead of defining it abstract?
Those that extend IndexReader (outside the scope of the attached patch) can then choose to override the implementation or not. The purpose of the patch is to add an explicit method which developers can use, rather than understand the logic on maxDoc() - numDocs(). Not all extended classes implement it this way BTW. SegmentReader just calls deletedDocs.count(), rather then calling the two separate methods.
Right, that's exactly what I'm thinking, with this body: public int numDeletedDocs() { return maxDoc() - numDocs(); } Then I think no classes need to override it (perf cost of calling 2 methods is tiny)? I agree with the body, that's what I had in mind.
As for extending classes, I agree that calling two methods has little performance overhead, but it just looks cleaner (for SegmentReader for example). Anyway, I don't have a strong opinion on whether we should override or not. I'll be fine with either.
Sending CHANGES.txt
Sending src/java/org/apache/lucene/index/IndexReader.java Transmitting file data .. Committed revision 695510.
Otis Gospodnetic made changes - 15/Sep/08 03:33 PM
Michael McCandless made changes - 11/Oct/08 12:49 PM
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||