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
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
update flag for logging events to store (#1846)
Krunal Gandhi3494155b7a4c
diff --git a/include/analytics_manager.h b/include/analytics_manager.hindex 84f7c751..099176e9 100644--- a/include/analytics_manager.h+++ b/include/analytics_manager.h@@ -11,7 +11,7 @@struct event_type_collection {std::string event_type;std::string collection;- bool log_to_file = false;+ bool log_to_store = false;std::string analytic_rule;};@@ -23,21 +23,21 @@ struct event_t {std::string doc_id;std::string name;std::vector<std::pair<std::string, std::string>> data;- bool log_to_file;+ bool log_to_store;event_t() = delete;~event_t() = default;event_t(const std::string& q, const std::string& type, uint64_t ts, const std::string& uid, const std::string& id,- const std::string& event_name, bool should_log_to_file, const std::vector<std::pair<std::string, std::string>> datavec) {+ const std::string& event_name, bool should_log_to_store, const std::vector<std::pair<std::string, std::string>> datavec) {query = q;event_type = type;timestamp = ts;user_id = uid;doc_id = id;name = event_name;- log_to_file = should_log_to_file;+ log_to_store = should_log_to_store;data = datavec;}diff --git a/src/analytics_manager.cpp b/src/analytics_manager.cppindex 5e5d9395..f2b8ac91 100644--- a/src/analytics_manager.cpp+++ b/src/analytics_manager.cpp@@ -219,17 +219,17 @@ Option<bool> AnalyticsManager::create_index(nlohmann::json &payload, bool upsert//store event name to their weights//which can be used to keep counter events separate from non counter events- bool log_to_file = false;- if(event.contains("log_to_file")) {- log_to_file = event["log_to_file"].get<bool>();+ bool log_to_store = false;+ if(event.contains("log_to_store")) {+ log_to_store = event["log_to_store"].get<bool>();- if(log_to_file && !analytics_store) {+ if(log_to_store && !analytics_store) {remove_index(suggestion_config_name);return Option<bool>(400, "Event can't be logged when analytics-db is not defined.");}}event_weight_map[event["name"]] = event["weight"];- event_type_collection ec{event["type"], suggestion_collection, log_to_file, suggestion_config_name};+ event_type_collection ec{event["type"], suggestion_collection, log_to_store, suggestion_config_name};event_collection_map.emplace(event["name"], ec);}counter_events.emplace(suggestion_collection, counter_event_t{counter_field, {}, event_weight_map});@@ -470,7 +470,7 @@ Option<bool> AnalyticsManager::add_event(const std::string& client_ip, const std}event_t event(query, event_type, now_ts_useconds, user_id, doc_id,- event_name, event_collection_map[event_name].log_to_file, custom_data);+ event_name, event_collection_map[event_name].log_to_store, custom_data);events_vec.emplace_back(event);if (!counter_events.empty()) {@@ -658,7 +658,7 @@ void AnalyticsManager::persist_events(ReplicationState *raft_server, uint64_t prfor (auto &events_collection_it: query_collection_events) {const auto& collection = events_collection_it.first;for (const auto &event: events_collection_it.second) {- if (event.log_to_file) {+ if (event.log_to_store) {nlohmann::json event_data;event.to_json(event_data, collection);payload.push_back(event_data);diff --git a/test/analytics_manager_test.cpp b/test/analytics_manager_test.cppindex d970cff5..2834035b 100644--- a/test/analytics_manager_test.cpp+++ b/test/analytics_manager_test.cpp@@ -910,7 +910,7 @@ TEST_F(AnalyticsManagerTest, PopularityScore) {"source": {"collections": ["products"],"events": [{"type": "click", "weight": 1, "name": "CLK1"}, {"type": "conversion", "weight": 5, "name": "CNV1"} ],- "log_to_file": true+ "log_to_store": true},"destination": {"collection": "products",@@ -1209,7 +1209,7 @@ TEST_F(AnalyticsManagerTest, PopularityScoreValidation) {"params": {"source": {"collections": ["books"],- "events": [{"type": "click", "name" : "CLK4"}, {"type": "conversion", "name": "CNV4", "log_to_file" : true} ]+ "events": [{"type": "click", "name" : "CLK4"}, {"type": "conversion", "name": "CNV4", "log_to_store" : true} ]},"destination": {"collection": "books",@@ -1228,7 +1228,7 @@ TEST_F(AnalyticsManagerTest, PopularityScoreValidation) {"params": {"source": {"collections": ["books"],- "events": [{"type": "click", "weight": 1, "name" : "CLK4"}, {"type": "conversion", "weight": 5, "name": "CNV4", "log_to_file" : true} ]+ "events": [{"type": "click", "weight": 1, "name" : "CLK4"}, {"type": "conversion", "weight": 5, "name": "CNV4", "log_to_store" : true} ]},"destination": {"collection": "books",