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

Optimize reference filtering.

Harpreet Sangar1d3e05f2cbf6
diff --git a/include/collection.h b/include/collection.h
index f3dbc66a..14693473 100644
--- a/include/collection.h
+++ b/include/collection.h
@@ -463,7 +463,9 @@ public:
Option<bool> validate_reference_filter(const std::string& filter_query) const;
- Option<bool> validate_reference_filter(const std::string& filter_query) const;
+ Option<bool> get_reference_filter_ids(const std::string & filter_query,
+ const std::string & collection_name,
+ std::pair<uint32_t, uint32_t*>& reference_index_ids) const;
Option<nlohmann::json> get(const std::string & id) const;
diff --git a/include/index.h b/include/index.h
index 0ce10daf..29e1292c 100644
--- a/include/index.h
+++ b/include/index.h
@@ -702,6 +702,10 @@ public:
const std::string& collection_name,
const std::string& reference_helper_field_name) const;
+ void do_reference_filtering_with_lock(std::pair<uint32_t, uint32_t*>& reference_index_ids,
+ filter_node_t const* const& filter_tree_root,
+ const std::string& reference_field_name) const;
+
void refresh_schemas(const std::vector<field>& new_fields, const std::vector<field>& del_fields);
// the following methods are not synchronized because their parent calls are synchronized or they are const/static
diff --git a/src/collection.cpp b/src/collection.cpp
index c4a1066a..3766a94d 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -2581,22 +2581,6 @@ Option<bool> Collection::validate_reference_filter(const std::string& filter_que
return Option<bool>(true);
}
-Option<bool> Collection::validate_reference_filter(const std::string& filter_query) const {
- std::shared_lock lock(mutex);
-
- const std::string doc_id_prefix = std::to_string(collection_id) + "_" + DOC_ID_PREFIX + "_";
- filter_node_t* filter_tree_root = nullptr;
- Option<bool> filter_op = filter::parse_filter_query(filter_query, search_schema,
- store, doc_id_prefix, filter_tree_root);
-
- if(!filter_op.ok()) {
- return filter_op;
- }
-
- delete filter_tree_root;
- return Option<bool>(true);
-}
-
bool Collection::facet_value_to_string(const facet &a_facet, const facet_count_t &facet_count,
const nlohmann::json &document, std::string &value) const {
diff --git a/src/index.cpp b/src/index.cpp
index f9ba9f35..840cebfd 100644
--- a/src/index.cpp
+++ b/src/index.cpp
@@ -1497,7 +1497,7 @@ Option<bool> Index::do_filtering(filter_node_t* const root,
const uint32_t& context_ids_length,
const uint32_t* context_ids) const {
// auto begin = std::chrono::high_resolution_clock::now();
- const filter a_filter = root->filter_exp;
+/**/ const filter a_filter = root->filter_exp;
bool is_referenced_filter = !a_filter.referenced_collection_name.empty();
if (is_referenced_filter) {
diff --git a/test/collection_join_test.cpp b/test/collection_join_test.cpp
index 0cedd216..9db121aa 100644
--- a/test/collection_join_test.cpp
+++ b/test/collection_join_test.cpp
@@ -284,9 +284,6 @@ TEST_F(CollectionJoinTest, IndexDocumentHavingReferenceField) {
ASSERT_TRUE(add_doc_op.ok());
ASSERT_EQ(customer_collection->get("0").get().count("reference_id_sequence_id"), 1);
- // Referenced document should be accessible from Customers collection.
- auto sequence_id = collectionManager.get_collection("Products")->get_seq_id_collection_prefix() + "_" +
- customer_collection->get("0").get()["product_id_sequence_id"].get<std::string>();
nlohmann::json document;
// Referenced document's sequence_id must be valid.
auto get_op = collectionManager.get_collection("Products")->get_document_from_store(