Issue Details (XML | Word | Printable)

Key: LUCENE-1131
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Otis Gospodnetic
Reporter: Shai Erera
Votes: 1
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Lucene - Java

Add numDeletedDocs to IndexReader

Created: 11/Jan/08 08:07 PM   Updated: 11/Oct/08 12:49 PM
Return to search
Component/s: None
Affects Version/s: None
Fix Version/s: 2.4

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works LUCENE-1131.patch 2008-01-12 05:27 AM Shai Erera 6 kB

Lucene Fields: New
Resolution Date: 15/Sep/08 03:33 PM


 Description  « Hide
Add numDeletedDocs to IndexReader. Basically, the implementation is as simple as doing:
public int numDeletedDocs() {
return deletedDocs == null ? 0 : deletedDocs.count();
}
in SegmentReader.
Patch to follow to include in all IndexReader extensions.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Yonik Seeley added a comment - 11/Jan/08 08:34 PM
How about just using maxDoc() - numDocs()?

Shai Erera added a comment - 11/Jan/08 08:38 PM
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.

Shai Erera added a comment - 12/Jan/08 05:27 AM
A very simple patch that implements numDeletedDocs in all the necessary readers.

Shai Erera made changes - 12/Jan/08 05:27 AM
Field Original Value New Value
Attachment LUCENE-1131.patch [ 12373026 ]
Otis Gospodnetic added a comment - 14/Jan/08 06:54 PM
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
Assignee Otis Gospodnetic [ otis ]
Michael McCandless added a comment - 03/Sep/08 09:43 PM
Otis is this one ready to go in?

Otis Gospodnetic added a comment - 04/Sep/08 03:19 PM
I think so - applies and compiles.

Michael McCandless added a comment - 07/Sep/08 10:43 AM
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.


Shai Erera added a comment - 07/Sep/08 12:30 PM
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.


Michael McCandless added a comment - 07/Sep/08 06:57 PM

What if we implement numDeletedDocs() in IndexReader, instead of defining it abstract?

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)?


Shai Erera added a comment - 08/Sep/08 10:54 AM
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.


Repository Revision Date User Message
ASF #695510 Mon Sep 15 15:33:15 UTC 2008 otis LUCENE-1131 - Added numDeletedDocs() to IndexReader
Files Changed
MODIFY /lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java
MODIFY /lucene/java/trunk/CHANGES.txt

Otis Gospodnetic added a comment - 15/Sep/08 03:33 PM
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
Resolution Fixed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Michael McCandless made changes - 11/Oct/08 12:49 PM
Status Resolved [ 5 ] Closed [ 6 ]