diff --git a/src/server/search/doc_index.cc b/src/server/search/doc_index.cc index 21ca8378142d..f61be1ed1912 100644 --- a/src/server/search/doc_index.cc +++ b/src/server/search/doc_index.cc @@ -57,7 +57,16 @@ const absl::flat_hash_map kSchemaTy {"VECTOR"sv, search::SchemaField::VECTOR}}; size_t GetProbabilisticBound(size_t hits, size_t requested, optional agg) { - auto intlog2 = [](size_t x) { return int(log2(x)); }; // TODO: replace with loop or builting_clz + auto intlog2 = [](size_t x) { + size_t l = 0; + while (x >>= 1) + ++l; + return l; + }; + + if (hits == 0 || requested == 0) + return 0; + size_t shards = shard_set->size(); // Estimate how much every shard has with at least 99% prob @@ -225,7 +234,6 @@ bool ShardDocIndex::Matches(string_view key, unsigned obj_code) const { io::Result ShardDocIndex::Search( const OpArgs& op_args, const SearchParams& params, search::SearchAlgorithm* search_algo) const { size_t requested_count = params.limit_offset + params.limit_total; - auto search_results = search_algo->Search(&indices_, requested_count); if (!search_results.error.empty()) return nonstd::make_unexpected(facade::ErrorReply(std::move(search_results.error))); @@ -237,7 +245,7 @@ io::Result ShardDocIndex::Search( // result hits as they likely won't be needed. The `cutoff_bound` indicates how much entries it's // reasonable to serialize directly, for the rest only id's are stored. In the 1% case they are // either serialized on another hop or the query is fully repeated without this optimization. - size_t cuttoff_bound = return_count; + size_t cuttoff_bound = requested_count; if (params.enable_cutoff && !params.IdsOnly()) { cuttoff_bound = GetProbabilisticBound(search_results.pre_aggregation_total, requested_count, search_algo->HasAggregation()); diff --git a/src/server/search/doc_index.h b/src/server/search/doc_index.h index 847a7ef3b98d..862a125a9863 100644 --- a/src/server/search/doc_index.h +++ b/src/server/search/doc_index.h @@ -33,8 +33,8 @@ struct DocResult { SearchDocData values; }; - // Reference to a document that matched the query, but it's serialization was the document was - // considered unlikely to be contained in the reply. + // Reference to a document that matched the query, but it's serialization was skipped as the + // document was considered unlikely to be contained in the reply. struct DocReference { ShardId shard_id; search::DocId doc_id;