DEV: Support both tag: as an alias for tags: filter for /filter (#21353)

We already support `category:` as an alias for `categories` so it makes
sense to support `tag:` as an alias for `tags:`.
This commit is contained in:
Alan Guo Xiang Tan 2023-05-03 14:51:04 +08:00 committed by GitHub
parent f47a4e61ad
commit b4cf990a51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -9,7 +9,7 @@ class TopicsFilter
@topic_notification_levels = Set.new
end
FILTER_ALIASES = { "categories" => "category" }
FILTER_ALIASES = { "categories" => "category", "tags" => "tag" }
private_constant :FILTER_ALIASES
def filter_from_query_string(query_string)
@ -74,7 +74,7 @@ class TopicsFilter
filter_by_number_of_posters(max: filter_values)
when "status"
filter_values.each { |status| @scope = filter_status(status: status) }
when "tags"
when "tag"
filter_tags(values: key_prefixes.zip(filter_values))
when "views-min"
filter_by_number_of_views(min: filter_values)

View File

@ -663,6 +663,17 @@ RSpec.describe TopicsFilter do
)
end
describe "when query string is `tag:tag1+tag2`" do
it "should only return topics that are tagged with all of the specified tags" do
expect(
TopicsFilter
.new(guardian: Guardian.new)
.filter_from_query_string("tag:#{tag.name}+#{tag2.name}")
.pluck(:id),
).to contain_exactly(topic_with_tag_and_tag2.id)
end
end
it "should only return topics that are tagged with all of the specified tags when query string is `tags:tag1+tag2`" do
expect(
TopicsFilter