ahlag commented on issue #17049:
URL: https://github.com/apache/lucene/issues/17049#issuecomment-7072680503

   I looked through the code and found that this behavior isn't limited to the 
two classes mentioned in the issue. Sparse `iterator()` shares the underlying 
`IndexedDISI` across ~12 classes, including `lucene95`, `lucene104`, and 
several backward codecs.
   
   Since changing all of them would be a fairly large diff, I agree that 
documenting the contract makes sense.
   
   I'd suggest adding this to the `iterator()` Javadoc:
   
   ```java
   /**
    * Create an iterator over the documents that have a vector in this instance.
    *
    * <p>The returned iterator may be a view over state held by this instance, 
like {@link
    * org.apache.lucene.search.Scorer#iterator()}: calling this method several 
times can return
    * iterators that share one position, so advancing one advances the others, 
and an iterator
    * returned after another one was advanced is not positioned on {@code -1}. 
Sparse fields, where
    * not every document has a vector, behave this way. To get an independent 
iterator positioned on
    * {@code -1}, call this method on a new {@link #copy()}.
    */
   ```
   
   I'd also add a test in `BaseKnnVectorsFormatTestCase` to verify that 
`copy().iterator()` starts at `-1` and visits all documents with vectors, 
covering all formats.
   
   Happy to open a PR for this. Would that be helpful? Also, should this have a 
CHANGES entry, and if so, for which version?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to