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
store rule type in suggestion config
krunala2fd6e07bbf5
diff --git a/include/analytics_manager.h b/include/analytics_manager.hindex 08c44010..0aaa43dc 100644--- a/include/analytics_manager.h+++ b/include/analytics_manager.h@@ -119,10 +119,11 @@ private:std::string suggestion_collection;std::vector<std::string> query_collections;size_t limit;+ std::string rule_type;void to_json(nlohmann::json& obj) const {obj["name"] = name;- obj["type"] = POPULAR_QUERIES_TYPE;+ obj["type"] = rule_type;obj["params"] = nlohmann::json::object();obj["params"]["limit"] = limit;obj["params"]["source"]["collections"] = query_collections;diff --git a/src/analytics_manager.cpp b/src/analytics_manager.cppindex 6db4978b..dc820b40 100644--- a/src/analytics_manager.cpp+++ b/src/analytics_manager.cpp@@ -99,6 +99,7 @@ Option<bool> AnalyticsManager::create_queries_index(nlohmann::json &payload, boosuggestion_config.name = suggestion_config_name;suggestion_config.suggestion_collection = suggestion_collection;suggestion_config.limit = limit;+ suggestion_config.rule_type = payload["type"];if(payload["type"] == POPULAR_QUERIES_TYPE) {if (!upsert && popular_queries.count(suggestion_collection) != 0) {diff --git a/test/analytics_manager_test.cpp b/test/analytics_manager_test.cppindex 750cbbf8..0e247ce3 100644--- a/test/analytics_manager_test.cpp+++ b/test/analytics_manager_test.cpp@@ -941,4 +941,70 @@ TEST_F(AnalyticsManagerTest, PopularityScoreValidation) {create_op = analyticsManager.create_rule(analytics_rule, false, true);ASSERT_FALSE(create_op.ok());ASSERT_EQ("counter_field `popularity_score` not found in destination collection.", create_op.error());+}++TEST_F(AnalyticsManagerTest, SuggestionConfigRule) {+ nlohmann::json titles_schema = R"({+ "name": "titles",+ "fields": [+ {"name": "title", "type": "string"}+ ]+ })"_json;++ Collection* titles_coll = collectionManager.create_collection(titles_schema).get();+++ // create a collection to store suggestions+ nlohmann::json suggestions_schema = R"({+ "name": "top_queries",+ "fields": [+ {"name": "q", "type": "string" },+ {"name": "count", "type": "int32" }+ ]+ })"_json;++ Collection* suggestions_coll = collectionManager.create_collection(suggestions_schema).get();++ //add popular quries rule+ nlohmann::json analytics_rule = R"({+ "name": "top_search_queries",+ "type": "popular_queries",+ "params": {+ "limit": 100,+ "source": {+ "collections": ["titles"]+ },+ "destination": {+ "collection": "top_queries"+ }+ }+ })"_json;++ auto create_op = analyticsManager.create_rule(analytics_rule, false, true);+ ASSERT_TRUE(create_op.ok());++ //add nohits rule+ analytics_rule = R"({+ "name": "search_queries",+ "type": "nohits_queries",+ "params": {+ "limit": 100,+ "source": {+ "collections": ["titles"]+ },+ "destination": {+ "collection": "top_queries"+ }+ }+ })"_json;++ create_op = analyticsManager.create_rule(analytics_rule, false, true);+ ASSERT_TRUE(create_op.ok());++ auto rules = analyticsManager.list_rules().get()["rules"];+ ASSERT_EQ(2, rules.size());+ ASSERT_EQ("search_queries", rules[0]["name"]);+ ASSERT_EQ("nohits_queries", rules[0]["type"]);+ ASSERT_EQ("top_search_queries", rules[1]["name"]);+ ASSERT_EQ("popular_queries", rules[1]["type"]);}\ No newline at end of file