apache / apache/lucene

sharpen javadocs for DISI.docID() when unpositioned [LUCENE-4403]

Open
#5,469 1 comment 0 reactions 0 assignees View on GitHub
legacy-jira-priority:Major type:bug
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

Spinoff from #5467.

Currently DISI requires an unpositioned iterator to be -1 or NO_MORE_DOCS. But I think we should refine this: in my opinion NO_MORE_DOCS should mean NO_MORE_DOCS.

So its ok for it to return NO_MORE_DOCS when its unpositioned, but only if it can already determine that its exhausted.

This makes life easier on consumers.

> Separately we cant really test this situation very well as long as the javadocs for nextDoc say, Returns the following:
>
> -1 or NO_MORE_DOCS if nextDoc() or
> advance(int) were not called yet\.
> NO_MORE_DOCS if the iterator has exhausted\.
> Otherwise it should return the doc ID it is currently on\.
>
> This prevents us from being able to easily assert that nobody is calling nextDoc()/advance() after the enum is exhausted, since we cannot differentiate 'exhausted' from 'uninitialized'\.
>
> I think we should clarify the javadocs, such that if nextDoc()/advance() are not called yet, you can still return NO_MORE_DOCS, but only if you somehow know you are exhausted-before-you-start\. NO_MORE_DOCS should mean NO_MORE_DOCS\.
>
> It could also be everyone reads it this way already, and I'm just being super-anal\.

> +1 to sharpen when a DocsEnum can return NO_MORE_DOCS before nextDoc: it should only be if the enum knows it has zero docs\. But I'm not even sure we should allow that \.\.\. why not always make it -1 \.\.\.? We can do that separately\.\.\.

---
Migrated from [LUCENE-4403](https://issues.apache.org/jira/browse/LUCENE-4403) by Robert Muir (@rmuir)
Attachments: [LUCENE-4403.patch](https://apache.github.io/lucene-jira-archive/attachments/LUCENE-4403/LUCENE-4403.patch)

Contributor guide

Open the contributing guide

Research direction

Locate the DISI.docID() and nextDoc()/advance() Javadocs, then read the issue discussion and the referenced LUCENE-4403.patch for the intended wording. Done means the documentation clearly distinguishes an unpositioned iterator from an exhausted one, including when NO_MORE_DOCS is valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.