mirror of
https://github.com/typesense/typesense.git
synced 2025-05-19 13:12:22 +08:00
Tweak override windowing naming scheme.
This commit is contained in:
parent
6729b72b1a
commit
460abfa69e
@ -113,8 +113,8 @@ struct override_t {
|
||||
std::string replace_query;
|
||||
|
||||
// epoch seconds
|
||||
int64_t window_start_ts = -1;
|
||||
int64_t window_end_ts = -1;
|
||||
int64_t effective_from_ts = -1;
|
||||
int64_t effective_to_ts = -1;
|
||||
|
||||
override_t() = default;
|
||||
|
||||
@ -269,12 +269,12 @@ struct override_t {
|
||||
override.stop_processing = override_json["stop_processing"].get<bool>();
|
||||
}
|
||||
|
||||
if(override_json.count("window_start_ts") != 0) {
|
||||
override.window_start_ts = override_json["window_start_ts"].get<int64_t>();
|
||||
if(override_json.count("effective_from_ts") != 0) {
|
||||
override.effective_from_ts = override_json["effective_from_ts"].get<int64_t>();
|
||||
}
|
||||
|
||||
if(override_json.count("window_end_ts") != 0) {
|
||||
override.window_end_ts = override_json["window_end_ts"].get<int64_t>();
|
||||
if(override_json.count("effective_to_ts") != 0) {
|
||||
override.effective_to_ts = override_json["effective_to_ts"].get<int64_t>();
|
||||
}
|
||||
|
||||
// we have to also detect if it is a dynamic query rule
|
||||
@ -333,12 +333,12 @@ struct override_t {
|
||||
override["replace_query"] = replace_query;
|
||||
}
|
||||
|
||||
if(window_start_ts != -1) {
|
||||
override["window_start_ts"] = window_start_ts;
|
||||
if(effective_from_ts != -1) {
|
||||
override["effective_from_ts"] = effective_from_ts;
|
||||
}
|
||||
|
||||
if(window_end_ts != -1) {
|
||||
override["window_end_ts"] = window_end_ts;
|
||||
if(effective_to_ts != -1) {
|
||||
override["effective_to_ts"] = effective_to_ts;
|
||||
}
|
||||
|
||||
override["remove_matched_tokens"] = remove_matched_tokens;
|
||||
|
@ -452,11 +452,11 @@ void Collection::curate_results(string& actual_query, bool enable_overrides, boo
|
||||
const auto& override = override_kv.second;
|
||||
|
||||
auto now_epoch = int64_t(std::time(0));
|
||||
if(override.window_start_ts != -1 && now_epoch < override.window_start_ts) {
|
||||
if(override.effective_from_ts != -1 && now_epoch < override.effective_from_ts) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(override.window_end_ts != -1 && now_epoch > override.window_end_ts) {
|
||||
if(override.effective_to_ts != -1 && now_epoch > override.effective_to_ts) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -881,7 +881,7 @@ TEST_F(CollectionOverrideTest, WindowForRule) {
|
||||
ASSERT_EQ("0", results["hits"][0]["document"]["id"].get<std::string>());
|
||||
|
||||
// rule must not match when window_start is set into the future
|
||||
override_json["window_start_ts"] = 35677971263; // year 3100, here we come! ;)
|
||||
override_json["effective_from_ts"] = 35677971263; // year 3100, here we come! ;)
|
||||
op = override_t::parse(override_json, "rule-1", override_rule);
|
||||
ASSERT_TRUE(op.ok());
|
||||
coll1->add_override(override_rule);
|
||||
@ -891,8 +891,8 @@ TEST_F(CollectionOverrideTest, WindowForRule) {
|
||||
ASSERT_EQ(0, results["hits"].size());
|
||||
|
||||
// rule must not match when window_end is set into the past
|
||||
override_json["window_start_ts"] = -1;
|
||||
override_json["window_end_ts"] = 965388863;
|
||||
override_json["effective_from_ts"] = -1;
|
||||
override_json["effective_to_ts"] = 965388863;
|
||||
op = override_t::parse(override_json, "rule-1", override_rule);
|
||||
ASSERT_TRUE(op.ok());
|
||||
coll1->add_override(override_rule);
|
||||
@ -902,8 +902,8 @@ TEST_F(CollectionOverrideTest, WindowForRule) {
|
||||
ASSERT_EQ(0, results["hits"].size());
|
||||
|
||||
// resetting both should bring the override back in action
|
||||
override_json["window_start_ts"] = 965388863;
|
||||
override_json["window_end_ts"] = 35677971263;
|
||||
override_json["effective_from_ts"] = 965388863;
|
||||
override_json["effective_to_ts"] = 35677971263;
|
||||
op = override_t::parse(override_json, "rule-1", override_rule);
|
||||
ASSERT_TRUE(op.ok());
|
||||
coll1->add_override(override_rule);
|
||||
|
Loading…
x
Reference in New Issue
Block a user