Merge pull request #4268 from BrokenEagle/universal-array-parameters

Add ability to search for multiple name values on the same field
This commit is contained in:
evazion
2020-01-20 16:35:45 -06:00
committed by GitHub
5 changed files with 18 additions and 16 deletions

View File

@@ -174,6 +174,12 @@ class ApplicationRecord < ActiveRecord::Base
where_regex(attr, params[:"#{attr}_regex"])
elsif params[:"#{attr}_not_regex"].present?
where_not_regex(attr, params[:"#{attr}_not_regex"])
elsif params[:"#{attr}_array"].present?
where(attr => params[:"#{attr}_array"])
elsif params[:"#{attr}_comma"].present?
where(attr => params[:"#{attr}_comma"].split(','))
elsif params[:"#{attr}_space"].present?
where(attr => params[:"#{attr}_space"].split(' '))
else
all
end
@@ -218,6 +224,10 @@ class ApplicationRecord < ActiveRecord::Base
items = items.map(&:to_i) if type == :integer
relation = relation.where_array_includes_all(name, items)
elsif params[:"#{name}_include_any_array"]
relation = relation.where_array_includes_any(name, params[:"#{name}_include_any_array"])
elsif params[:"#{name}_include_all_array"]
relation = relation.where_array_includes_all(name, params[:"#{name}_include_all_array"])
end
if params[:"#{name.to_s.singularize}_count"]

View File

@@ -478,7 +478,7 @@ class Artist < ApplicationRecord
def search(params)
q = super
q = q.search_attributes(params, :is_active, :is_banned, :creator, :name, :group_name)
q = q.search_attributes(params, :is_active, :is_banned, :creator, :name, :group_name, :other_names)
if params[:any_other_name_like]
q = q.any_other_name_like(params[:any_other_name_like])

View File

@@ -816,7 +816,7 @@ class Tag < ApplicationRecord
def search(params)
q = super
q = q.search_attributes(params, :is_locked, :category, :post_count)
q = q.search_attributes(params, :is_locked, :category, :post_count, :name)
if params[:fuzzy_name_matches].present?
q = q.fuzzy_name_matches(params[:fuzzy_name_matches])
@@ -826,8 +826,8 @@ class Tag < ApplicationRecord
q = q.name_matches(params[:name_matches])
end
if params[:name].present?
q = q.where("tags.name": normalize_name(params[:name]).split(","))
if params[:name_normalize].present?
q = q.where("tags.name": normalize_name(params[:name_normalize]).split(","))
end
if params[:hide_empty].blank? || params[:hide_empty].to_s.truthy?

View File

@@ -119,20 +119,12 @@ class TagRelationship < ApplicationRecord
def search(params)
q = super
q = q.search_attributes(params, :creator, :approver, :forum_topic_id, :forum_post_id)
q = q.search_attributes(params, :creator, :approver, :forum_topic_id, :forum_post_id, :antecedent_name, :consequent_name)
if params[:name_matches].present?
q = q.name_matches(params[:name_matches])
end
if params[:antecedent_name].present?
q = q.where(antecedent_name: params[:antecedent_name].split)
end
if params[:consequent_name].present?
q = q.where(consequent_name: params[:consequent_name].split)
end
if params[:status].present?
q = q.status_matches(params[:status])
end

View File

@@ -72,11 +72,11 @@ class WikiPage < ApplicationRecord
def search(params = {})
q = super
q = q.search_attributes(params, :is_locked, :is_deleted, :body)
q = q.search_attributes(params, :is_locked, :is_deleted, :body, :title, :other_names)
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index, ts_config: "danbooru")
if params[:title].present?
q = q.where_like(:title, normalize_title(params[:title]))
if params[:title_normalize].present?
q = q.where_like(:title, normalize_title(params[:title_normalize]))
end
if params[:other_names_match].present?