codaitya commented on a change in pull request #2214:
URL: https://github.com/apache/lucene-solr/pull/2214#discussion_r560719085



##########
File path: lucene/core/src/test/org/apache/lucene/index/TestVectorValues.java
##########
@@ -815,4 +816,47 @@ public void testSearchStrategyIdentifiers() {
     assertEquals(2, VectorValues.SearchStrategy.DOT_PRODUCT_HNSW.ordinal());
     assertEquals(3, VectorValues.SearchStrategy.values().length);
   }
+
+  public void testAdvance() throws Exception {
+    try (Directory dir = newDirectory()) {
+      try (IndexWriter w = new IndexWriter(dir, createIndexWriterConfig())) {
+        int numdocs = 2000;
+        String fieldName = "field";
+        for (int i = 0; i < numdocs; i++) {
+          Document doc = new Document();
+          // randomly add a vector field
+          if (random().nextInt(4) == 3) {
+            doc.add(
+                new VectorField(
+                    fieldName, new float[4], 
VectorValues.SearchStrategy.DOT_PRODUCT_HNSW));
+          }
+          w.addDocument(doc);
+        }
+        w.forceMerge(1);
+        try (IndexReader reader = w.getReader()) {
+          LeafReader r = getOnlyLeafReader(reader);
+          VectorValues vectorValues = r.getVectorValues(fieldName);
+          TreeSet<Integer> vectorDocs = new TreeSet<>();
+          int cur = -1;
+          while (cur != NO_MORE_DOCS) {
+            cur = vectorValues.nextDoc();
+            vectorDocs.add(cur);
+          }
+          vectorValues = r.getVectorValues(fieldName);
+          for (int i = 0; i != NO_MORE_DOCS && i < numdocs; i++) {
+            // randomly advance to i
+            if (random().nextInt(4) == 3) {
+              vectorValues.advance(i);
+              assertEquals((int) vectorDocs.higher(i - 1), 
vectorValues.docID());
+              if (vectorValues.docID() == NO_MORE_DOCS) {
+                break;
+              }
+              // ensure i is always greater than vectorValues.docID()
+              i = vectorValues.docID();

Review comment:
       The intention was that in the next loop iteration `i` wil be 
incremented,  but yes this confusing. I will update




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to