mirror of
https://github.com/typesense/typesense.git
synced 2025-05-21 14:12:27 +08:00
Tagged overrides must not be picked when no tags are provided.
This commit is contained in:
parent
9802ac1d5e
commit
37f56468dd
@ -824,6 +824,11 @@ bool Collection::does_override_match(const override_t& override, std::string& qu
|
||||
std::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 given
|
||||
for(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,
|
||||
|
@ -3357,7 +3357,7 @@ TEST_F(CollectionOverrideTest, OverrideWithTags) {
|
||||
ASSERT_TRUE(op.ok());
|
||||
coll1->add_override(override1);
|
||||
|
||||
//
|
||||
// single tag
|
||||
nlohmann::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 tag
|
||||
nlohmann::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");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user