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

Reference `include_fields`.

Harpreet Sangar0c8edf941f01
diff --git a/include/collection.h b/include/collection.h
index 38e91d1f..f0c16236 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<std::string> get_reference_field(const std::string & collection_name) 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;
diff --git a/src/collection.cpp b/src/collection.cpp
index c3ef5a49..6c61a24c 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -2580,9 +2580,7 @@ Option<bool> Collection::validate_reference_filter(const std::string& filter_que
return Option<bool>(true);
}
-Option<bool> Collection::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<std::string> Collection::get_reference_field(const std::string & collection_name) const {
std::shared_lock lock(mutex);
std::string reference_field_name;
@@ -2595,10 +2593,23 @@ Option<bool> Collection::get_reference_filter_ids(const std::string & filter_que
}
if (reference_field_name.empty()) {
- return Option<bool>(400, "Could not find any field in `" + name + "` referencing the collection `"
- + collection_name + "`.");
+ return Option<std::string>(400, "Could not find any field in `" + name + "` referencing the collection `"
+ + collection_name + "`.");
+ }
+
+ return Option(reference_field_name);
+}
+
+Option<bool> Collection::get_reference_filter_ids(const std::string & filter_query,
+ const std::string & collection_name,
+ std::pair<uint32_t, uint32_t*>& reference_index_ids) const {
+ auto reference_field_op = get_reference_field(collection_name);
+ if (!reference_field_op.ok()) {
+ return Option<bool>(reference_field_op.code(), reference_field_op.error());
}
+ 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,
@@ -2608,8 +2619,8 @@ Option<bool> Collection::get_reference_filter_ids(const std::string & filter_que
}
// Reference helper field has the sequence id of other collection's documents.
- reference_field_name += REFERENCE_HELPER_FIELD_SUFFIX;
- index->do_reference_filtering_with_lock(reference_index_ids, filter_tree_root, reference_field_name);
+ auto field_name = reference_field_op.get() + REFERENCE_HELPER_FIELD_SUFFIX;
+ index->do_reference_filtering_with_lock(reference_index_ids, filter_tree_root, field_name);
delete filter_tree_root;
return Option<bool>(true);