Fix #5177: ordfav with commentary search raises exception.

This commit is contained in:
evazion
2022-05-20 22:59:02 -05:00
parent 0fe9356bf6
commit 9867514a78
2 changed files with 14 additions and 3 deletions

View File

@@ -242,9 +242,15 @@ class PostQueryBuilder
in :not
children.first.negate_relation
in :and
children.reduce(&:and)
joins = children.flat_map(&:joins_values)
orders = children.flat_map(&:order_values)
nodes = children.map { |child| child.joins(joins).order(orders) }
nodes.reduce(&:and)
in :or
children.reduce(&:or)
joins = children.flat_map(&:joins_values)
orders = children.flat_map(&:order_values)
nodes = children.map { |child| child.joins(joins).order(orders) }
nodes.reduce(&:or)
end
end
end

View File

@@ -2,7 +2,7 @@ require 'test_helper'
class PostQueryBuilderTest < ActiveSupport::TestCase
def assert_tag_match(posts, query, current_user: CurrentUser.user, tag_limit: nil, **options)
assert_equal(posts.map(&:id), Post.user_tag_match(query, current_user, tag_limit: tag_limit, **options).pluck(:id))
assert_equal(posts.map(&:id), Post.user_tag_match(query, current_user, tag_limit: tag_limit, **options).pluck("posts.id"))
end
def assert_search_error(query, current_user: CurrentUser.user, **options)
@@ -284,6 +284,11 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
assert_tag_match([post2, post1], "ordfav:#{CurrentUser.user.name}")
assert_tag_match([], "ordfav:does_not_exist")
assert_tag_match([post2, post1], "ordfav:#{CurrentUser.user.name} commentary:false")
assert_tag_match([post2, post1], "ordfav:#{CurrentUser.user.name} favcount:>0")
assert_tag_match([post2, post1], "ordfav:#{CurrentUser.user.name} comments:0")
assert_tag_match([post2, post1], "ordfav:#{CurrentUser.user.name} -has:comments")
end
should "return posts for the pool:<name> metatag" do