Add additional search options
This commit is contained in:
@@ -2,9 +2,23 @@ class ArtistCommentaryVersion < ApplicationRecord
|
|||||||
belongs_to :post
|
belongs_to :post
|
||||||
belongs_to_updater
|
belongs_to_updater
|
||||||
|
|
||||||
|
def self.text_matches(query)
|
||||||
|
query = "*#{query}*" unless query =~ /\*/
|
||||||
|
|
||||||
|
where_ilike(:original_title, query)
|
||||||
|
.or(where_ilike(:original_description, query))
|
||||||
|
.or(where_ilike(:translated_title, query))
|
||||||
|
.or(where_ilike(:translated_description, query))
|
||||||
|
end
|
||||||
|
|
||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = super
|
q = super
|
||||||
q = q.search_attributes(params, :original_title, :original_description, :translated_title, :translated_description)
|
q = q.search_attributes(params, :original_title, :original_description, :translated_title, :translated_description)
|
||||||
|
|
||||||
|
if params[:text_matches].present?
|
||||||
|
q = q.text_matches(params[:text_matches])
|
||||||
|
end
|
||||||
|
|
||||||
q.apply_default_order(params)
|
q.apply_default_order(params)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ class ArtistVersion < ApplicationRecord
|
|||||||
def search(params)
|
def search(params)
|
||||||
q = super
|
q = super
|
||||||
|
|
||||||
q = q.search_attributes(params, :is_deleted, :is_banned, :name, :group_name)
|
q = q.search_attributes(params, :is_deleted, :is_banned, :name, :group_name, :urls, :other_names)
|
||||||
|
q = q.text_attribute_matches(:name, params[:name_matches])
|
||||||
|
q = q.text_attribute_matches(:group_name, params[:group_name_matches])
|
||||||
|
|
||||||
if params[:order] == "name"
|
if params[:order] == "name"
|
||||||
q = q.order("artist_versions.name").default_order
|
q = q.order("artist_versions.name").default_order
|
||||||
|
|||||||
@@ -113,6 +113,8 @@ class ForumTopic < ApplicationRecord
|
|||||||
case params[:order]
|
case params[:order]
|
||||||
when "sticky"
|
when "sticky"
|
||||||
q = q.sticky_first
|
q = q.sticky_first
|
||||||
|
when "id"
|
||||||
|
q = q.order(id: :desc)
|
||||||
else
|
else
|
||||||
q = q.apply_default_order(params)
|
q = q.apply_default_order(params)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ class IpBan < ApplicationRecord
|
|||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = super
|
q = super
|
||||||
q = q.search_attributes(params, :reason)
|
q = q.search_attributes(params, :reason)
|
||||||
|
q = q.text_attribute_matches(:reason, params[:reason_matches])
|
||||||
|
|
||||||
if params[:ip_addr].present?
|
if params[:ip_addr].present?
|
||||||
q = q.where("ip_addr = ?", params[:ip_addr])
|
q = q.where("ip_addr = ?", params[:ip_addr])
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ class ModerationReport < ApplicationRecord
|
|||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = super
|
q = super
|
||||||
q = q.search_attributes(params, :reason)
|
q = q.search_attributes(params, :reason)
|
||||||
|
q = q.text_attribute_matches(:reason, params[:reason_matches])
|
||||||
|
|
||||||
q.apply_default_order(params)
|
q.apply_default_order(params)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ class WikiPageVersion < ApplicationRecord
|
|||||||
def search(params)
|
def search(params)
|
||||||
q = super
|
q = super
|
||||||
|
|
||||||
q = q.search_attributes(params, :is_locked, :is_deleted)
|
q = q.search_attributes(params, :title, :body, :other_names, :is_locked, :is_deleted)
|
||||||
q = q.text_attribute_matches(:title, params[:title])
|
q = q.text_attribute_matches(:title, params[:title_matches])
|
||||||
q = q.text_attribute_matches(:body, params[:body])
|
q = q.text_attribute_matches(:body, params[:body_matches])
|
||||||
|
|
||||||
q.apply_default_order(params)
|
q.apply_default_order(params)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user