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 by reference.

Harpreet Sangar1fbfa34672b4
diff --git a/include/collection.h b/include/collection.h
index 8d77cfde..55855a28 100644
--- a/include/collection.h
+++ b/include/collection.h
@@ -463,6 +463,8 @@ public:
Option<bool> validate_reference_filter(const std::string& filter_query) const;
+ Option<bool> validate_reference_filter(const std::string& filter_query) const;
+
Option<nlohmann::json> get(const std::string & id) const;
Option<std::string> remove(const std::string & id, bool remove_from_store = true);
diff --git a/src/collection.cpp b/src/collection.cpp
index 8ced0cae..b1c24216 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -2580,6 +2580,22 @@ 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/test/collection_join_test.cpp b/test/collection_join_test.cpp
index 9db121aa..0cedd216 100644
--- a/test/collection_join_test.cpp
+++ b/test/collection_join_test.cpp
@@ -284,6 +284,9 @@ 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(