search: support repeated parent: metatags.
Support using the parent: metatag twice in the same search ("parent:1 parent:2").
This commit is contained in:
@@ -200,6 +200,16 @@ class PostQueryBuilder
|
|||||||
relation
|
relation
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def parent_matches(parent)
|
||||||
|
if parent.downcase == "none"
|
||||||
|
Post.where(parent: nil)
|
||||||
|
elsif parent.downcase == "any"
|
||||||
|
Post.where.not(parent: nil)
|
||||||
|
elsif parent
|
||||||
|
Post.where(id: parent).or(Post.where(parent: parent))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def commentary_matches(query)
|
def commentary_matches(query)
|
||||||
case query
|
case query
|
||||||
when "none", "false"
|
when "none", "false"
|
||||||
@@ -480,20 +490,12 @@ class PostQueryBuilder
|
|||||||
relation = relation.where("posts.id <> ?", q[:post_id_negated])
|
relation = relation.where("posts.id <> ?", q[:post_id_negated])
|
||||||
end
|
end
|
||||||
|
|
||||||
if q[:parent] == "none"
|
q[:parent].to_a.each do |parent|
|
||||||
relation = relation.where("posts.parent_id IS NULL")
|
relation = relation.merge(parent_matches(parent))
|
||||||
elsif q[:parent] == "any"
|
|
||||||
relation = relation.where("posts.parent_id IS NOT NULL")
|
|
||||||
elsif q[:parent]
|
|
||||||
relation = relation.where("(posts.id = ? or posts.parent_id = ?)", q[:parent].to_i, q[:parent].to_i)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if q[:parent_neg_ids]
|
q[:parent_neg].to_a.each do |parent_neg|
|
||||||
neg_ids = q[:parent_neg_ids].map(&:to_i)
|
relation = relation.merge(parent_matches(parent_neg).negate)
|
||||||
neg_ids.delete(0)
|
|
||||||
if neg_ids.present?
|
|
||||||
relation = relation.where("posts.id not in (?) and (posts.parent_id is null or posts.parent_id not in (?))", neg_ids, neg_ids)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if q[:child] == "none"
|
if q[:child] == "none"
|
||||||
@@ -997,17 +999,12 @@ class PostQueryBuilder
|
|||||||
q["#{TagCategory.short_name_mapping[$1]}_tag_count".to_sym] = parse_helper(g2)
|
q["#{TagCategory.short_name_mapping[$1]}_tag_count".to_sym] = parse_helper(g2)
|
||||||
|
|
||||||
when "parent"
|
when "parent"
|
||||||
q[:parent] = g2.downcase
|
q[:parent] ||= []
|
||||||
|
q[:parent] << g2
|
||||||
|
|
||||||
when "-parent"
|
when "-parent"
|
||||||
if g2.downcase == "none"
|
q[:parent_neg] ||= []
|
||||||
q[:parent] = "any"
|
q[:parent_neg] << g2
|
||||||
elsif g2.downcase == "any"
|
|
||||||
q[:parent] = "none"
|
|
||||||
else
|
|
||||||
q[:parent_neg_ids] ||= []
|
|
||||||
q[:parent_neg_ids] << g2.downcase
|
|
||||||
end
|
|
||||||
|
|
||||||
when "child"
|
when "child"
|
||||||
q[:child] = g2.downcase
|
q[:child] = g2.downcase
|
||||||
|
|||||||
@@ -227,9 +227,18 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
assert_tag_match([parent], "parent:none")
|
assert_tag_match([parent], "parent:none")
|
||||||
assert_tag_match([child], "-parent:none")
|
assert_tag_match([child], "-parent:none")
|
||||||
|
|
||||||
|
assert_tag_match([child], "parent:any")
|
||||||
|
assert_tag_match([parent], "-parent:any")
|
||||||
|
|
||||||
assert_tag_match([child, parent], "parent:#{parent.id}")
|
assert_tag_match([child, parent], "parent:#{parent.id}")
|
||||||
assert_tag_match([child], "parent:#{child.id}")
|
assert_tag_match([child], "parent:#{child.id}")
|
||||||
|
|
||||||
|
assert_tag_match([], "-parent:#{parent.id}")
|
||||||
|
assert_tag_match([], "-parent:#{child.id}")
|
||||||
|
|
||||||
|
assert_tag_match([child], "parent:#{parent.id} parent:#{child.id}")
|
||||||
|
|
||||||
assert_tag_match([child], "child:none")
|
assert_tag_match([child], "child:none")
|
||||||
assert_tag_match([parent], "child:any")
|
assert_tag_match([parent], "child:any")
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user