diff --git a/app/logical/post_query.rb b/app/logical/post_query.rb index cccd729d8..f1dc0b237 100644 --- a/app/logical/post_query.rb +++ b/app/logical/post_query.rb @@ -111,12 +111,12 @@ class PostQuery ast.none? end - # True if the search is a single metatag search for the given metatag. + # True if the search is a single, non-negated metatag search for the given metatag. Assumes the query has been normalized. def is_metatag?(name, value = nil) if value.nil? - is_single_term? && has_metatag?(name) + metatag? && has_metatag?(name) else - is_single_term? && find_metatag(name) == value.to_s + metatag? && find_metatag(name) == value.to_s end end diff --git a/test/unit/post_query_builder_test.rb b/test/unit/post_query_builder_test.rb index 66fe4603a..db88135e4 100644 --- a/test/unit/post_query_builder_test.rb +++ b/test/unit/post_query_builder_test.rb @@ -1480,14 +1480,21 @@ class PostQueryBuilderTest < ActiveSupport::TestCase assert_fast_count(3, "pool:#{pool.id}") assert_fast_count(3, "pool:#{pool.name}") + assert_fast_count(3, "ordpool:#{pool.id}") + assert_fast_count(3, "ordpool:#{pool.name}") + + assert_fast_count(Post.count, "-pool:#{pool.id}") + assert_fast_count(Post.count, "-pool:#{pool.name}") end should "return the correct favorite count for a fav: search" do fav = create(:favorite) - fav.user.update!(favorite_count: 1) + User.where(id: fav.user).update_all(favorite_count: 42) # XXX favorite_count is readonly; update it this way to bypass the readonly check. - assert_fast_count(1, "fav:#{fav.user.name}") - assert_fast_count(1, "ordfav:#{fav.user.name}") + assert_fast_count(42, "fav:#{fav.user.name}") + assert_fast_count(42, "ordfav:#{fav.user.name}") + + assert_fast_count(1, "-fav:#{fav.user.name}") end should "return the correct favorite count for a fav: search for a user with private favorites" do