benwtrent commented on code in PR #13181: URL: https://github.com/apache/lucene/pull/13181#discussion_r1525282411
########## lucene/core/src/java/org/apache/lucene/search/AbstractKnnVectorQuery.java: ########## @@ -190,12 +190,13 @@ protected TopDocs exactSearch(LeafReaderContext context, DocIdSetIterator accept if (vectorScorer == null) { return NO_RESULTS; } + DocIdSetIterator vectorIterator = vectorScorer.iterator(); HitQueue queue = new HitQueue(k, true); ScoreDoc topDoc = queue.top(); int doc; while ((doc = acceptIterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { - boolean advanced = vectorScorer.advanceExact(doc); - assert advanced; + vectorIterator.advance(doc); + assert vectorIterator.docID() == doc; Review Comment: The iterator already does a filter on the field existing. But I agree, this interaction needs improved. Especially as adding the filter doesn't really seem necessary and could unnecessarily thrash any filter clause caching that exists. The iterator query that is actually created upstream of this code: ```java if (filter != null) { BooleanQuery booleanQuery = new BooleanQuery.Builder() .add(filter, BooleanClause.Occur.FILTER) .add(new FieldExistsQuery(field), BooleanClause.Occur.FILTER) .build(); Query rewritten = indexSearcher.rewrite(booleanQuery); filterWeight = indexSearcher.createWeight(rewritten, ScoreMode.COMPLETE_NO_SCORES, 1f); } else { filterWeight = null; } ``` -- 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: issues-unsubscr...@lucene.apache.org 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