Reference include_fields.

This commit is contained in:
Harpreet Sangar 2023-02-09 11:50:58 +05:30
parent 0059f8d3fb
commit 0c8edf941f
2 changed files with 20 additions and 7 deletions

View File

@ -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;

View File

@ -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);