Fix #4343: Presence of metatags shouldn't prevent rendering of the excerpt.

On the post index page, show the wiki excerpt if the search includes a
single tag, even if the tag is negated or the search includes other
metatags.

If the search includes a single pool: or ordpool: metatag, show the pool
excerpt even if the search includes other metatags.
This commit is contained in:
evazion
2020-04-30 18:17:02 -05:00
parent 8b5763652d
commit 3d3f9ce46c
3 changed files with 101 additions and 10 deletions

View File

@@ -823,8 +823,8 @@ class PostQueryBuilder
scan_query.select { |term| term.type == :metatag }
end
def select_metatags(metatag)
metatags.select { |term| term.name == metatag.to_s.downcase }
def select_metatags(*names)
metatags.select { |term| term.name.in?(names.map(&:to_s)) }
end
def find_metatag(metatag)
@@ -835,6 +835,10 @@ class PostQueryBuilder
metatags.any? { |term| term.name.in?(metatag_names.map(&:to_s).map(&:downcase)) }
end
def has_single_tag?
tags.size == 1 && !tags.first.wildcard
end
def is_metatag?(name, value = nil)
if value.nil?
is_single_term? && has_metatag?(name)

View File

@@ -27,7 +27,7 @@ module PostSets
end
def tag
return nil unless query.is_simple_tag?
return nil unless query.has_single_tag?
@tag ||= Tag.find_by(name: query.tags.first.name)
end
@@ -38,15 +38,17 @@ module PostSets
end
def pool
return nil unless query.is_metatag?(:pool) || query.is_metatag?(:ordpool)
name = query.find_metatag(:pool) || query.find_metatag(:ordpool)
pool_names = query.select_metatags(:pool, :ordpool).map(&:value)
name = pool_names.first
return nil unless pool_names.size == 1
@pool ||= Pool.find_by_name(name)
end
def favgroup
return nil unless query.is_metatag?(:favgroup)
name = query.find_metatag(:favgroup)
favgroup_names = query.select_metatags(:favgroup, :ordfavgroup).map(&:value)
name = favgroup_names.first
return nil unless favgroup_names.size == 1
@favgroup ||= FavoriteGroup.visible(CurrentUser.user).find_by_name_or_id(name, CurrentUser.user)
end