search: refactor scan_query callers to use split_query.
Refactor to use split_query instead of scan_query to split a query on spaces. Preparation for refactoring scan_query into something smarter.
This commit is contained in:
@@ -25,7 +25,7 @@ module PostsHelper
|
|||||||
return unless post_search_counts_enabled?
|
return unless post_search_counts_enabled?
|
||||||
return unless params[:action] == "index" && params[:page].nil? && params[:tags].present?
|
return unless params[:action] == "index" && params[:page].nil? && params[:tags].present?
|
||||||
|
|
||||||
tags = PostQueryBuilder.scan_query(params[:tags]).sort.join(" ")
|
tags = PostQueryBuilder.normalize_query(params[:tags])
|
||||||
sig = generate_reportbooru_signature("ps-#{tags}")
|
sig = generate_reportbooru_signature("ps-#{tags}")
|
||||||
render "posts/partials/index/search_count", sig: sig
|
render "posts/partials/index/search_count", sig: sig
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ class TagBatchChangeJob < ApplicationJob
|
|||||||
def perform(antecedent, consequent, updater, updater_ip_addr)
|
def perform(antecedent, consequent, updater, updater_ip_addr)
|
||||||
raise Error.new("antecedent is missing") if antecedent.blank?
|
raise Error.new("antecedent is missing") if antecedent.blank?
|
||||||
|
|
||||||
normalized_antecedent = TagAlias.to_aliased(PostQueryBuilder.scan_query(antecedent.mb_chars.downcase))
|
normalized_antecedent = TagAlias.to_aliased(PostQueryBuilder.split_query(antecedent.mb_chars.downcase))
|
||||||
normalized_consequent = TagAlias.to_aliased(PostQueryBuilder.scan_query(consequent.mb_chars.downcase))
|
normalized_consequent = TagAlias.to_aliased(PostQueryBuilder.split_query(consequent.mb_chars.downcase))
|
||||||
|
|
||||||
CurrentUser.without_safe_mode do
|
CurrentUser.without_safe_mode do
|
||||||
CurrentUser.scoped(updater, updater_ip_addr) do
|
CurrentUser.scoped(updater, updater_ip_addr) do
|
||||||
@@ -30,7 +30,7 @@ class TagBatchChangeJob < ApplicationJob
|
|||||||
end
|
end
|
||||||
|
|
||||||
def migrate_saved_searches(normalized_antecedent, normalized_consequent)
|
def migrate_saved_searches(normalized_antecedent, normalized_consequent)
|
||||||
tags = PostQueryBuilder.scan_query(normalized_antecedent.join(" "), strip_metatags: true)
|
tags = PostQueryBuilder.split_query(normalized_antecedent.join(" "))
|
||||||
|
|
||||||
# https://www.postgresql.org/docs/current/static/functions-array.html
|
# https://www.postgresql.org/docs/current/static/functions-array.html
|
||||||
saved_searches = SavedSearch.where("string_to_array(query, ' ') @> ARRAY[?]", tags)
|
saved_searches = SavedSearch.where("string_to_array(query, ' ') @> ARRAY[?]", tags)
|
||||||
@@ -53,7 +53,7 @@ class TagBatchChangeJob < ApplicationJob
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
repl = user.blacklisted_tags.split(/\r\n|\r|\n/).map do |line|
|
repl = user.blacklisted_tags.split(/\r\n|\r|\n/).map do |line|
|
||||||
list = PostQueryBuilder.scan_query(line)
|
list = PostQueryBuilder.split_query(line)
|
||||||
|
|
||||||
if (list & query).size != query.size
|
if (list & query).size != query.size
|
||||||
next line
|
next line
|
||||||
|
|||||||
@@ -88,8 +88,8 @@ class AliasAndImplicationImporter
|
|||||||
all
|
all
|
||||||
|
|
||||||
when :mass_update
|
when :mass_update
|
||||||
all += PostQueryBuilder.scan_query(token[1])
|
all += PostQueryBuilder.split_query(token[1])
|
||||||
all += PostQueryBuilder.scan_query(token[2])
|
all += PostQueryBuilder.split_query(token[2])
|
||||||
all
|
all
|
||||||
|
|
||||||
when :change_category
|
when :change_category
|
||||||
|
|||||||
@@ -760,6 +760,10 @@ class PostQueryBuilder
|
|||||||
list
|
list
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def split_query(query)
|
||||||
|
scan_query(query)
|
||||||
|
end
|
||||||
|
|
||||||
def normalize_query(query, normalize_aliases: true, sort: true)
|
def normalize_query(query, normalize_aliases: true, sort: true)
|
||||||
tags = scan_query(query.to_s)
|
tags = scan_query(query.to_s)
|
||||||
tags = tags.map { |t| Tag.normalize_name(t) }
|
tags = tags.map { |t| Tag.normalize_name(t) }
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ module PostSets
|
|||||||
attr_reader :tag_array, :page, :raw, :random, :post_count, :format
|
attr_reader :tag_array, :page, :raw, :random, :post_count, :format
|
||||||
|
|
||||||
def initialize(tags, page = 1, per_page = nil, raw: false, random: false, format: "html")
|
def initialize(tags, page = 1, per_page = nil, raw: false, random: false, format: "html")
|
||||||
@tag_array = PostQueryBuilder.scan_query(tags)
|
@tag_array = PostQueryBuilder.split_query(tags)
|
||||||
@page = page
|
@page = page
|
||||||
@per_page = per_page
|
@per_page = per_page
|
||||||
@raw = raw.to_s.truthy?
|
@raw = raw.to_s.truthy?
|
||||||
|
|||||||
@@ -527,11 +527,11 @@ class Post < ApplicationRecord
|
|||||||
|
|
||||||
module TagMethods
|
module TagMethods
|
||||||
def tag_array
|
def tag_array
|
||||||
@tag_array ||= PostQueryBuilder.scan_query(tag_string)
|
@tag_array ||= PostQueryBuilder.split_query(tag_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_array_was
|
def tag_array_was
|
||||||
@tag_array_was ||= PostQueryBuilder.scan_query(tag_string_in_database.presence || tag_string_before_last_save || "")
|
@tag_array_was ||= PostQueryBuilder.split_query(tag_string_in_database.presence || tag_string_before_last_save || "")
|
||||||
end
|
end
|
||||||
|
|
||||||
def tags
|
def tags
|
||||||
@@ -595,7 +595,7 @@ class Post < ApplicationRecord
|
|||||||
# then try to merge the tag changes together.
|
# then try to merge the tag changes together.
|
||||||
current_tags = tag_array_was
|
current_tags = tag_array_was
|
||||||
new_tags = tag_array
|
new_tags = tag_array
|
||||||
old_tags = PostQueryBuilder.scan_query(old_tag_string)
|
old_tags = PostQueryBuilder.split_query(old_tag_string)
|
||||||
|
|
||||||
kept_tags = current_tags & new_tags
|
kept_tags = current_tags & new_tags
|
||||||
@removed_tags = old_tags - kept_tags
|
@removed_tags = old_tags - kept_tags
|
||||||
@@ -632,7 +632,7 @@ class Post < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def normalize_tags
|
def normalize_tags
|
||||||
normalized_tags = PostQueryBuilder.scan_query(tag_string)
|
normalized_tags = PostQueryBuilder.split_query(tag_string)
|
||||||
normalized_tags = apply_casesensitive_metatags(normalized_tags)
|
normalized_tags = apply_casesensitive_metatags(normalized_tags)
|
||||||
normalized_tags = normalized_tags.map(&:downcase)
|
normalized_tags = normalized_tags.map(&:downcase)
|
||||||
normalized_tags = filter_metatags(normalized_tags)
|
normalized_tags = filter_metatags(normalized_tags)
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ class Tag < ApplicationRecord
|
|||||||
def has_metatag?(tags, *metatags)
|
def has_metatag?(tags, *metatags)
|
||||||
return nil if tags.blank?
|
return nil if tags.blank?
|
||||||
|
|
||||||
tags = PostQueryBuilder.scan_query(tags.to_str) if tags.respond_to?(:to_str)
|
tags = PostQueryBuilder.split_query(tags.to_str) if tags.respond_to?(:to_str)
|
||||||
tags.grep(/\A(?:#{metatags.map(&:to_s).join("|")}):(.+)\z/i) { $1 }.first
|
tags.grep(/\A(?:#{metatags.map(&:to_s).join("|")}):(.+)\z/i) { $1 }.first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user