@@ -289,7 +289,7 @@ struct BasicSearch {
289289
290290 // negate -(*subquery*): explicitly compute result complement. Needs further optimizations
291291 IndexResult Search (const AstNegateNode& node, string_view active_field) {
292- vector<DocId> matched = SearchGeneric (*node.node , active_field).Take ();
292+ auto matched = SearchGeneric (*node.node , active_field).Take (). first ;
293293 vector<DocId> all = indices_->GetAllDocs ();
294294
295295 // To negate a result, we have to find the complement of matched to all documents,
@@ -358,7 +358,7 @@ struct BasicSearch {
358358 knn_distances_ = vec_index->Knn (knn.vec .first .get (), knn.limit , knn.ef_runtime );
359359 else
360360 knn_distances_ =
361- vec_index->Knn (knn.vec .first .get (), knn.limit , knn.ef_runtime , sub_results.Take ());
361+ vec_index->Knn (knn.vec .first .get (), knn.limit , knn.ef_runtime , sub_results.Take (). first );
362362 }
363363
364364 // [KNN limit @field vec]: Compute distance from `vec` to all vectors keep closest `limit`
@@ -410,7 +410,6 @@ struct BasicSearch {
410410
411411 // Top level results don't need to be sorted, because they will be scored, sorted by fields or
412412 // used by knn
413-
414413 DCHECK (top_level || holds_alternative<AstKnnNode>(node.Variant ()) ||
415414 holds_alternative<AstGeoNode>(node.Variant ()) ||
416415 visit ([](auto * set) { return is_sorted (set->begin (), set->end ()); }, result.Borrowed ()));
@@ -421,16 +420,15 @@ struct BasicSearch {
421420 return result;
422421 }
423422
424- SearchResult Search (const AstNode& query) {
423+ SearchResult Search (const AstNode& query, size_t cuttoff_limit ) {
425424 IndexResult result = SearchGeneric (query, " " , true );
426425
427426 // Extract profile if enabled
428427 optional<AlgorithmProfile> profile =
429428 profile_builder_ ? make_optional (profile_builder_->Take ()) : nullopt ;
430429
431- auto out = result.Take ();
432- const size_t total = out.size ();
433- return SearchResult{total, std::move (out), std::move (knn_scores_), std::move (profile),
430+ auto [out, total_size] = result.Take (cuttoff_limit);
431+ return SearchResult{total_size, std::move (out), std::move (knn_scores_), std::move (profile),
434432 std::move (error_)};
435433 }
436434
@@ -659,11 +657,11 @@ bool SearchAlgorithm::Init(string_view query, const QueryParams* params,
659657 return true ;
660658}
661659
662- SearchResult SearchAlgorithm::Search (const FieldIndices* index) const {
660+ SearchResult SearchAlgorithm::Search (const FieldIndices* index, size_t cuttoff_limit ) const {
663661 auto bs = BasicSearch{index};
664662 if (profiling_enabled_)
665663 bs.EnableProfiling ();
666- return bs.Search (*query_);
664+ return bs.Search (*query_, cuttoff_limit );
667665}
668666
669667optional<KnnScoreSortOption> SearchAlgorithm::GetKnnScoreSortOption () const {
0 commit comments