mirror of
https://github.com/typesense/typesense.git
synced 2025-05-19 05:08:43 +08:00
Optimize reference filtering.
This commit is contained in:
parent
72f896dc2e
commit
1d3e05f2cb
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user