Model#search: refactor searching for attributes.

This commit is contained in:
evazion
2019-08-29 20:24:52 -05:00
parent 6fc4b63fa8
commit 7b8584e3b0
26 changed files with 90 additions and 212 deletions

View File

@@ -490,8 +490,7 @@ class Artist < ApplicationRecord
def search(params)
q = super
q = q.search_text_attribute(:name, params)
q = q.search_text_attribute(:group_name, params)
q = q.search_attributes(params, :is_active, :is_banned, :creator, :name, :group_name)
if params[:any_other_name_like]
q = q.any_other_name_like(params[:any_other_name_like])
@@ -509,10 +508,6 @@ class Artist < ApplicationRecord
q = q.url_matches(params[:url_matches])
end
q = q.attribute_matches(:is_active, params[:is_active])
q = q.attribute_matches(:is_banned, params[:is_banned])
q = q.search_user_attribute(:creator, params)
if params[:has_tag].to_s.truthy?
q = q.joins(:tag).where("tags.post_count > 0")
elsif params[:has_tag].to_s.falsy?