Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve shard routing and search index expression test coverage. #55

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,30 @@ class GraphQL
end
end

context "when `time_of_day` filtering is used" do
it "targets all indices since it filters only on the time but rollover uses full DateTime values" do
parts = search_index_expression_parts_for({"created_at" => {
"time_of_day" => {"gt" => "12:30:00Z"}
}})

expect(parts).to target_all_widget_indices
end

it "targets all indices when it is negated since matching documents could live in any index" do
parts = search_index_expression_parts_for({"created_at" => {
"not" => {"time_of_day" => {"gt" => "12:30:00Z"}}
}})

expect(parts).to target_all_widget_indices

parts = search_index_expression_parts_for({"not" => {
"created_at" => {"time_of_day" => {"gt" => "12:30:00Z"}}
}})

expect(parts).to target_all_widget_indices
end
end

context "when `not` is used" do
it "excludes indices targeted by a filter without both an upper and lower bound" do
parts = search_index_expression_parts_for({"created_at" => {"not" => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,18 @@ def shard_routing_for(route_with_field_paths, filter_or_filters)
})).to search_all_shards
end

it "correctly identifies shards when combined with an `equal_to_any_of` on the same field" do
expect(shard_routing_for(["name"], {"name" => {
"equal_to_any_of" => ["def", "ghi", "jkl"],
"not" => {
"any_of" => [
{"equal_to_any_of" => ["abc", "def"]},
{"equal_to_any_of" => ["def", "ghi"]}
]
}
}})).to search_shards_identified_by "jkl"
end

it "searches all shards when the query filters with `equal_to_any_of: []`" do
expect(shard_routing_for(["name"], {
"name" => {
Expand All @@ -362,7 +374,7 @@ def shard_routing_for(route_with_field_paths, filter_or_filters)
})).to search_all_shards
end

it "searches all shards when set to nil`" do
it "searches all shards when set to nil" do
expect(shard_routing_for(["name"], {
"name" => {"not" => nil}
})).to search_all_shards
Expand Down
Loading