msokolov commented on code in PR #13285:
URL: https://github.com/apache/lucene/pull/13285#discussion_r1599136370


##########
lucene/core/src/java/org/apache/lucene/search/AbstractVectorSimilarityQuery.java:
##########
@@ -105,13 +116,16 @@ public Scorer scorer(LeafReaderContext context) throws 
IOException {
         LeafReader leafReader = context.reader();
         Bits liveDocs = leafReader.getLiveDocs();
 
+        QueryTimeout queryTimeout = searcher.getTimeout();

Review Comment:
   hmm what if there is no timeout? will `queryTimeout` be null? In that case 
do we still want to create a `TimeLimitingKnnCollectorManager`?



##########
lucene/core/src/java/org/apache/lucene/search/AbstractVectorSimilarityQuery.java:
##########
@@ -144,22 +158,22 @@ protected boolean match(int doc) {
         }
 
         // Perform an approximate search
-        TopDocs results = approximateSearch(context, acceptDocs, cardinality);
+        TopDocs results =
+            approximateSearch(context, acceptDocs, cardinality, 
timeLimitingKnnCollectorManager);
 
-        // If the limit was exhausted
-        if (results.totalHits.relation == 
TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO) {
+        if (results.totalHits.relation == TotalHits.Relation.EQUAL_TO
+            // Return partial results only when timeout is met
+            || (queryTimeout != null && queryTimeout.shouldExit())) {
+          // Return an iterator over the collected results
+          return VectorSimilarityScorer.fromScoreDocs(this, boost, 
results.scoreDocs);
+        } else {
           // Return a lazy-loading iterator
           return VectorSimilarityScorer.fromAcceptDocs(
               this,
               boost,
               createVectorScorer(context),
               new BitSetIterator(acceptDocs, cardinality),
               resultSimilarity);
-        } else if (results.scoreDocs.length == 0) {
-          return null;

Review Comment:
   we don't return `null` any more whenm there are 0 results?



##########
lucene/core/src/java/org/apache/lucene/search/AbstractVectorSimilarityQuery.java:
##########
@@ -144,22 +158,22 @@ protected boolean match(int doc) {
         }
 
         // Perform an approximate search
-        TopDocs results = approximateSearch(context, acceptDocs, cardinality);
+        TopDocs results =
+            approximateSearch(context, acceptDocs, cardinality, 
timeLimitingKnnCollectorManager);
 
-        // If the limit was exhausted
-        if (results.totalHits.relation == 
TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO) {
+        if (results.totalHits.relation == TotalHits.Relation.EQUAL_TO
+            // Return partial results only when timeout is met
+            || (queryTimeout != null && queryTimeout.shouldExit())) {
+          // Return an iterator over the collected results
+          return VectorSimilarityScorer.fromScoreDocs(this, boost, 
results.scoreDocs);
+        } else {
           // Return a lazy-loading iterator
           return VectorSimilarityScorer.fromAcceptDocs(
               this,
               boost,
               createVectorScorer(context),
               new BitSetIterator(acceptDocs, cardinality),
               resultSimilarity);
-        } else if (results.scoreDocs.length == 0) {
-          return null;

Review Comment:
   oh never mind I see this got moved to `VectorSimilarityScorer`



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

Reply via email to