add Note#for_creator, Pool#name_matches
This commit is contained in:
@@ -32,6 +32,10 @@ class Note < ActiveRecord::Base
|
|||||||
joins(:post).where("posts.tag_index @@ to_tsquery('danbooru', E?)", query.to_escaped_for_tsquery_split)
|
joins(:post).where("posts.tag_index @@ to_tsquery('danbooru', E?)", query.to_escaped_for_tsquery_split)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def for_creator(user_id)
|
||||||
|
where("creator_id = ?", user_id)
|
||||||
|
end
|
||||||
|
|
||||||
def creator_name(name)
|
def creator_name(name)
|
||||||
where("creator_id = (select _.id from users _ where lower(_.name) = ?)", name.mb_chars.downcase)
|
where("creator_id = (select _.id from users _ where lower(_.name) = ?)", name.mb_chars.downcase)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -38,14 +38,18 @@ class Pool < ActiveRecord::Base
|
|||||||
order("(case category when 'series' then 0 else 1 end), name")
|
order("(case category when 'series' then 0 else 1 end), name")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def name_matches(name)
|
||||||
|
name = name.tr(" ", "_")
|
||||||
|
name = "*#{name}*" unless name =~ /\*/
|
||||||
|
where("name ilike ? escape E'\\\\'", name.to_escaped_for_sql_like)
|
||||||
|
end
|
||||||
|
|
||||||
def search(params)
|
def search(params)
|
||||||
q = scoped
|
q = scoped
|
||||||
params = {} if params.blank?
|
params = {} if params.blank?
|
||||||
|
|
||||||
if params[:name_matches].present?
|
if params[:name_matches].present?
|
||||||
name_matches = params[:name_matches].tr(" ", "_")
|
q = q.name_matches(params[:name_matches])
|
||||||
name_matches = "*#{name_matches}*" unless name_matches =~ /\*/
|
|
||||||
q = q.where("name ilike ? escape E'\\\\'", name_matches.to_escaped_for_sql_like)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:description_matches].present?
|
if params[:description_matches].present?
|
||||||
|
|||||||
Reference in New Issue
Block a user