@@ -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`
@@ -405,7 +405,6 @@ struct BasicSearch {
405405
406406 // Top level results don't need to be sorted, because they will be scored, sorted by fields or
407407 // used by knn
408-
409408 DCHECK (top_level || holds_alternative<AstKnnNode>(node.Variant ()) ||
410409 holds_alternative<AstGeoNode>(node.Variant ()) ||
411410 visit ([](auto * set) { return is_sorted (set->begin (), set->end ()); }, result.Borrowed ()));
@@ -416,16 +415,15 @@ struct BasicSearch {
416415 return result;
417416 }
418417
419- SearchResult Search (const AstNode& query) {
418+ SearchResult Search (const AstNode& query, size_t cuttoff_limit ) {
420419 IndexResult result = SearchGeneric (query, " " , true );
421420
422421 // Extract profile if enabled
423422 optional<AlgorithmProfile> profile =
424423 profile_builder_ ? make_optional (profile_builder_->Take ()) : nullopt ;
425424
426- auto out = result.Take ();
427- const size_t total = out.size ();
428- return SearchResult{total, std::move (out), std::move (knn_scores_), std::move (profile),
425+ auto [out, total_size] = result.Take (cuttoff_limit);
426+ return SearchResult{total_size, std::move (out), std::move (knn_scores_), std::move (profile),
429427 std::move (error_)};
430428 }
431429
@@ -654,11 +652,11 @@ bool SearchAlgorithm::Init(string_view query, const QueryParams* params,
654652 return true ;
655653}
656654
657- SearchResult SearchAlgorithm::Search (const FieldIndices* index) const {
655+ SearchResult SearchAlgorithm::Search (const FieldIndices* index, size_t cuttoff_limit ) const {
658656 auto bs = BasicSearch{index};
659657 if (profiling_enabled_)
660658 bs.EnableProfiling ();
661- return bs.Search (*query_);
659+ return bs.Search (*query_, cuttoff_limit );
662660}
663661
664662optional<KnnScoreSortOption> SearchAlgorithm::GetKnnScoreSortOption () const {
0 commit comments