Better guards for top_k truncation.

This commit is contained in:
Kishore Nallan 2023-08-21 12:29:40 +05:30
parent 32a85a472f
commit f8e6468a7b
2 changed files with 6 additions and 1 deletions

View File

@ -4953,9 +4953,13 @@ void Collection::hide_credential(nlohmann::json& json, const std::string& creden
}
}
Option<bool> Collection::truncate_after_top_k(const string &field_name, size_t k) {
std::shared_lock slock(mutex);
std::vector<uint32_t> seq_ids;
auto op = index->seq_ids_outside_top_k(field_name, k, seq_ids);
slock.unlock();
if(!op.ok()) {
return op;
}

View File

@ -6315,9 +6315,10 @@ size_t Index::num_seq_ids() const {
Option<bool> Index::seq_ids_outside_top_k(const std::string& field_name, size_t k,
std::vector<uint32_t>& outside_seq_ids) {
std::shared_lock lock(mutex);
auto field_it = numerical_index.find(field_name);
if(field_it == sort_index.end()) {
if(field_it == numerical_index.end()) {
return Option<bool>(400, "Field not found in numerical index.");
}