search: switch to new tag search parser in a few places.
This commit is contained in:
@@ -43,7 +43,7 @@ class PostNavbarComponent < ApplicationComponent
|
||||
end
|
||||
|
||||
def query
|
||||
@query ||= PostQueryBuilder.new(search)
|
||||
@query ||= PostQuery.new(search)
|
||||
end
|
||||
|
||||
memoize :favgroups
|
||||
|
||||
@@ -116,10 +116,10 @@ class BulkUpdateRequestProcessor
|
||||
end
|
||||
|
||||
when :mass_update
|
||||
lhs = PostQueryBuilder.new(args[0])
|
||||
rhs = PostQueryBuilder.new(args[1])
|
||||
lhs = PostQuery.new(args[0])
|
||||
rhs = PostQuery.new(args[1])
|
||||
|
||||
if lhs.is_simple_tag? && rhs.is_simple_tag?
|
||||
if lhs.is_single_tag? && rhs.is_single_tag?
|
||||
errors.add(:base, "Can't mass update #{args[0]} -> #{args[1]} (use an alias or a rename instead for tag moves)")
|
||||
end
|
||||
|
||||
@@ -236,9 +236,8 @@ class BulkUpdateRequestProcessor
|
||||
when :mass_update
|
||||
"mass update {{#{args[0]}}} -> {{#{args[1]}}}"
|
||||
when :nuke
|
||||
query = PostQueryBuilder.new(args[0])
|
||||
|
||||
if query.is_simple_tag?
|
||||
if PostQuery.new(args[0]).is_single_tag?
|
||||
"nuke [[#{args[0]}]]"
|
||||
else
|
||||
"nuke {{#{args[0]}}}"
|
||||
@@ -255,7 +254,7 @@ class BulkUpdateRequestProcessor
|
||||
def self.nuke(tag_name)
|
||||
# Reject existing implications from any other tag to the one we're nuking
|
||||
# otherwise the tag won't be removed from posts that have those other tags
|
||||
if PostQueryBuilder.new(tag_name).is_simple_tag?
|
||||
if PostQuery.new(tag_name).is_single_tag?
|
||||
TagImplication.active.where(consequent_name: tag_name).each { |ti| ti.reject!(User.system) }
|
||||
TagImplication.active.where(antecedent_name: tag_name).each { |ti| ti.reject!(User.system) }
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ class PostQuery
|
||||
extend Memoist
|
||||
|
||||
attr_reader :search, :parser, :ast
|
||||
delegate :tag_names, to: :ast
|
||||
delegate :tag_names, :metatags, to: :ast
|
||||
|
||||
def initialize(search)
|
||||
@search = search
|
||||
@@ -16,5 +16,21 @@ class PostQuery
|
||||
Tag.where(name: tag_names)
|
||||
end
|
||||
|
||||
def is_single_tag?
|
||||
ast.tag?
|
||||
end
|
||||
|
||||
def select_metatags(*names)
|
||||
metatags.select { |metatag| metatag.name.in?(names.map(&:to_s).map(&:downcase)) }
|
||||
end
|
||||
|
||||
def has_metatag?(*names)
|
||||
select_metatags(*names).present?
|
||||
end
|
||||
|
||||
def find_metatag(*names)
|
||||
select_metatags(*names).first&.value
|
||||
end
|
||||
|
||||
memoize :tags
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user