/artists: add more search options for other names, group name.

Add these search params:

* /artists?search[<field>]=
* /artists?search[<field>_eq]=
* /artists?search[<field>_not_eq]=
* /artists?search[<field>_like]=
* /artists?search[<field>_not_like]=
* /artists?search[<field>_ilike]=
* /artists?search[<field>_not_ilike]=
* /artists?search[<field>_regex]=
* /artists?search[<field>_not_regex]=

where `<field>` can be `name`, `group_name`, or `other_names`.

Remove these search params:

* /artists?search[name_matches]=
* /artists?search[other_names_match]=
* /artists?search[group_name_matches]=

`/artists?search[<field>_like]=` effectively does the same thing that
these searches did.
This commit is contained in:
evazion
2018-09-21 18:53:14 -05:00
parent f917b83d6f
commit a4608daf38
2 changed files with 14 additions and 39 deletions

View File

@@ -455,24 +455,6 @@ class Artist < ApplicationRecord
end
module SearchMethods
def other_names_match(string)
if string =~ /\*/ && CurrentUser.is_builder?
where("artists.other_names ILIKE ? ESCAPE E'\\\\'", string.to_escaped_for_sql_like)
else
where("artists.other_names_index @@ to_tsquery('danbooru', E?)", Artist.normalize_name(string).to_escaped_for_tsquery)
end
end
def group_name_matches(name)
stripped_name = normalize_name(name).to_escaped_for_sql_like
where("artists.group_name LIKE ? ESCAPE E'\\\\'", stripped_name)
end
def name_matches(name)
stripped_name = normalize_name(name).to_escaped_for_sql_like
where("artists.name LIKE ? ESCAPE E'\\\\'", stripped_name)
end
def named(name)
where(name: normalize_name(name))
end
@@ -487,21 +469,12 @@ class Artist < ApplicationRecord
end
end
def search(params)
q = super
if params[:name_matches].present?
q = q.name_matches(params[:name_matches])
end
if params[:other_names_match].present?
q = q.other_names_match(params[:other_names_match])
end
if params[:group_name_matches].present?
q = q.group_name_matches(params[:group_name_matches])
end
q = q.search_text_attribute(:name, params)
q = q.search_text_attribute(:other_names, params)
q = q.search_text_attribute(:group_name, params)
if params[:any_name_matches].present?
q = q.any_name_matches(params[:any_name_matches])