Added ability to search for URL array parameters
- Also added in different string splitters for the text fields - Removed or renamed parameters covered by the main search function
This commit is contained in:
@@ -174,6 +174,12 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
where_regex(attr, params[:"#{attr}_regex"])
|
where_regex(attr, params[:"#{attr}_regex"])
|
||||||
elsif params[:"#{attr}_not_regex"].present?
|
elsif params[:"#{attr}_not_regex"].present?
|
||||||
where_not_regex(attr, params[:"#{attr}_not_regex"])
|
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
|
else
|
||||||
all
|
all
|
||||||
end
|
end
|
||||||
@@ -218,6 +224,10 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
items = items.map(&:to_i) if type == :integer
|
items = items.map(&:to_i) if type == :integer
|
||||||
|
|
||||||
relation = relation.where_array_includes_all(name, items)
|
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
|
end
|
||||||
|
|
||||||
if params[:"#{name.to_s.singularize}_count"]
|
if params[:"#{name.to_s.singularize}_count"]
|
||||||
|
|||||||
@@ -478,7 +478,7 @@ class Artist < ApplicationRecord
|
|||||||
def search(params)
|
def search(params)
|
||||||
q = super
|
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]
|
if params[:any_other_name_like]
|
||||||
q = q.any_other_name_like(params[:any_other_name_like])
|
q = q.any_other_name_like(params[:any_other_name_like])
|
||||||
|
|||||||
@@ -816,7 +816,7 @@ class Tag < ApplicationRecord
|
|||||||
def search(params)
|
def search(params)
|
||||||
q = super
|
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?
|
if params[:fuzzy_name_matches].present?
|
||||||
q = q.fuzzy_name_matches(params[:fuzzy_name_matches])
|
q = q.fuzzy_name_matches(params[:fuzzy_name_matches])
|
||||||
@@ -826,8 +826,8 @@ class Tag < ApplicationRecord
|
|||||||
q = q.name_matches(params[:name_matches])
|
q = q.name_matches(params[:name_matches])
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:name].present?
|
if params[:name_normalize].present?
|
||||||
q = q.where("tags.name": normalize_name(params[:name]).split(","))
|
q = q.where("tags.name": normalize_name(params[:name_normalize]).split(","))
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:hide_empty].blank? || params[:hide_empty].to_s.truthy?
|
if params[:hide_empty].blank? || params[:hide_empty].to_s.truthy?
|
||||||
|
|||||||
@@ -119,20 +119,12 @@ class TagRelationship < ApplicationRecord
|
|||||||
|
|
||||||
def search(params)
|
def search(params)
|
||||||
q = super
|
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?
|
if params[:name_matches].present?
|
||||||
q = q.name_matches(params[:name_matches])
|
q = q.name_matches(params[:name_matches])
|
||||||
end
|
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?
|
if params[:status].present?
|
||||||
q = q.status_matches(params[:status])
|
q = q.status_matches(params[:status])
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -72,11 +72,11 @@ class WikiPage < ApplicationRecord
|
|||||||
def search(params = {})
|
def search(params = {})
|
||||||
q = super
|
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")
|
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index, ts_config: "danbooru")
|
||||||
|
|
||||||
if params[:title].present?
|
if params[:title_normalize].present?
|
||||||
q = q.where_like(:title, normalize_title(params[:title]))
|
q = q.where_like(:title, normalize_title(params[:title_normalize]))
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:other_names_match].present?
|
if params[:other_names_match].present?
|
||||||
|
|||||||
Reference in New Issue
Block a user