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
Tagged overrides must not be picked when no tags are provided.
Kishore Nallan37f56468dd88
diff --git a/src/collection.cpp b/src/collection.cppindex a7fd1a5f..7ce55121 100644--- a/src/collection.cpp+++ b/src/collection.cpp@@ -824,6 +824,11 @@ bool Collection::does_override_match(const override_t& override, std::string& qustd::string& curated_sort_by,nlohmann::json& override_metadata) const {+ if(!tags_matched && !override.rule.tags.empty()) {+ // only untagged overrides must be considered when no tags are given in the query+ return false;+ }+auto now_epoch = int64_t(std::time(0));if(override.effective_from_ts != -1 && now_epoch < override.effective_from_ts) {return false;@@ -1019,6 +1024,7 @@ void Collection::curate_results(string& actual_query, const string& filter_query}}} else {+ // no override tags givenfor(const auto& override_kv: overrides) {const auto& override = override_kv.second;bool match_found = does_override_match(override, query, excluded_set, actual_query, filter_query,diff --git a/test/collection_override_test.cpp b/test/collection_override_test.cppindex 52ef573a..dd254699 100644--- a/test/collection_override_test.cpp+++ b/test/collection_override_test.cpp@@ -3357,7 +3357,7 @@ TEST_F(CollectionOverrideTest, OverrideWithTags) {ASSERT_TRUE(op.ok());coll1->add_override(override1);- //+ // single tagnlohmann::json override_json2 = R"({"id": "ov-2","rule": {@@ -3373,7 +3373,7 @@ TEST_F(CollectionOverrideTest, OverrideWithTags) {ASSERT_TRUE(op.ok());coll1->add_override(override2);- //+ // no tagnlohmann::json override_json3 = R"({"id": "ov-3","rule": {@@ -3443,6 +3443,20 @@ TEST_F(CollectionOverrideTest, OverrideWithTags) {ASSERT_EQ(1, results["hits"].size());ASSERT_EQ("0", results["hits"][0]["document"]["id"].get<std::string>());+ // query with no tags should only trigger override with no tags+ results = coll1->search("queryA", {"name"}, "",+ {}, sort_fields, {2}, 10, 1, FREQUENCY,+ {false}, Index::DROP_TOKENS_THRESHOLD,+ spp::sparse_hash_set<std::string>(),+ spp::sparse_hash_set<std::string>(), 10, "", 30, 4, "title", 20, {}, {}, {}, 0,+ "<mark>", "</mark>", {}, 1000, true, false, true, "", false, 10000,+ 4, 7, fallback, 4, {off}, 100, 100, 2, 2, false, "", true, 0, max_score, 100, 0,+ 0, HASH, 30000, 2, "", {}, {}, "right_to_left",+ true, true, false, -1, "", "").get();++ ASSERT_EQ(1, results["hits"].size());+ ASSERT_EQ("2", results["hits"][0]["document"]["id"].get<std::string>());+collectionManager.drop_collection("coll1");}@@ -3707,6 +3721,20 @@ TEST_F(CollectionOverrideTest, TagsOnlyRule) {ASSERT_EQ(1, results["hits"].size());ASSERT_EQ("1", results["hits"][0]["document"]["id"].get<std::string>());+ // no override tag passed: rule should not match+ std::string override_tag = "";+ results = coll1->search("foobar", {"name"}, "",+ {}, sort_fields, {2}, 10, 1, FREQUENCY,+ {false}, Index::DROP_TOKENS_THRESHOLD,+ spp::sparse_hash_set<std::string>(),+ spp::sparse_hash_set<std::string>(), 10, "", 30, 4, "title", 20, {}, {}, {}, 0,+ "<mark>", "</mark>", {}, 1000, true, false, true, "", false, 10000,+ 4, 7, fallback, 4, {off}, 100, 100, 2, 2, false, "", true, 0, max_score, 100, 0,+ 0, HASH, 30000, 2, "", {}, {}, "right_to_left",+ true, true, false, -1, "", override_tag).get();++ ASSERT_EQ(0, results["hits"].size());+collectionManager.drop_collection("coll1");}