Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

`filter_result_iterator_t` shouldn't timeout during update and delete by filter query operations. (#1511)

Harpreet Sangarb0e523caa59e
diff --git a/include/filter_result_iterator.h b/include/filter_result_iterator.h
index 1e89b1b7..f7febbc9 100644
--- a/include/filter_result_iterator.h
+++ b/include/filter_result_iterator.h
@@ -261,10 +261,11 @@ private:
/// Performs OR on the subtrees of operator.
void or_filter_iterators();
- /// Advance all the token iterators that are at seq_id.
+ /// Advances all the token iterators that are at seq_id and finds the next intersection.
void advance_string_filter_token_iterators();
- /// Finds the first match for a filter on string field.
+ /// Finds the first match for a filter on string field. Only used in `init()` and `reset()`. Handles `!` in string
+ /// filter.
void get_string_filter_first_match(const bool& field_is_array);
/// Finds the next match for a filter on string field.
diff --git a/src/core_api.cpp b/src/core_api.cpp
index b2563e7e..8b88f34b 100644
--- a/src/core_api.cpp
+++ b/src/core_api.cpp
@@ -1330,6 +1330,7 @@ bool patch_update_documents(const std::shared_ptr<http_req>& req, const std::sha
req->params[DIRTY_VALUES_PARAM] = ""; // set it empty as default will depend on whether schema is enabled
}
+ search_stop_us = UINT64_MAX; // Filtering shouldn't timeout during update operation.
auto update_op = collection->update_matching_filter(filter_query, req->body, req->params[DIRTY_VALUES_PARAM]);
if(update_op.ok()) {
res->set_200(update_op.get().dump());
@@ -1484,6 +1485,7 @@ bool del_remove_documents(const std::shared_ptr<http_req>& req, const std::share
// destruction of data is managed by req destructor
req->data = deletion_state;
+ search_stop_us = UINT64_MAX; // Filtering shouldn't timeout during delete operation.
filter_result_t filter_result;
auto filter_ids_op = collection->get_filter_ids(simple_filter_query, filter_result);
diff --git a/src/index.cpp b/src/index.cpp
index 0ec2b553..139bf3d0 100644
--- a/src/index.cpp
+++ b/src/index.cpp
@@ -1820,13 +1820,13 @@ Option<bool> Index::do_filtering_with_lock(filter_node_t* const filter_tree_root
return filter_init_op;
}
- if (filter_result_iterator.reference.empty()) {
- filter_result.count = filter_result_iterator.to_filter_id_array(filter_result.docs);
+ filter_result_iterator.compute_result();
+ if (filter_result_iterator.approx_filter_ids_length == 0) {
return Option(true);
}
- filter_result_iterator.compute_result();
- if (filter_result_iterator.approx_filter_ids_length == 0) {
+ if (filter_result_iterator.reference.empty()) {
+ filter_result.count = filter_result_iterator.to_filter_id_array(filter_result.docs);
return Option(true);
}