Add additional search options

This commit is contained in:
BrokenEagle
2020-07-19 03:56:59 +00:00
parent 3eb90105df
commit c9ba41a58e
6 changed files with 24 additions and 4 deletions

View File

@@ -2,9 +2,23 @@ class ArtistCommentaryVersion < ApplicationRecord
belongs_to :post
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)
q = super
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)
end

View File

@@ -9,7 +9,9 @@ class ArtistVersion < ApplicationRecord
def search(params)
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"
q = q.order("artist_versions.name").default_order

View File

@@ -113,6 +113,8 @@ class ForumTopic < ApplicationRecord
case params[:order]
when "sticky"
q = q.sticky_first
when "id"
q = q.order(id: :desc)
else
q = q.apply_default_order(params)
end

View File

@@ -27,6 +27,7 @@ class IpBan < ApplicationRecord
def self.search(params)
q = super
q = q.search_attributes(params, :reason)
q = q.text_attribute_matches(:reason, params[:reason_matches])
if params[:ip_addr].present?
q = q.where("ip_addr = ?", params[:ip_addr])

View File

@@ -84,6 +84,7 @@ class ModerationReport < ApplicationRecord
def self.search(params)
q = super
q = q.search_attributes(params, :reason)
q = q.text_attribute_matches(:reason, params[:reason_matches])
q.apply_default_order(params)
end

View File

@@ -9,9 +9,9 @@ class WikiPageVersion < ApplicationRecord
def search(params)
q = super
q = q.search_attributes(params, :is_locked, :is_deleted)
q = q.text_attribute_matches(:title, params[:title])
q = q.text_attribute_matches(:body, params[:body])
q = q.search_attributes(params, :title, :body, :other_names, :is_locked, :is_deleted)
q = q.text_attribute_matches(:title, params[:title_matches])
q = q.text_attribute_matches(:body, params[:body_matches])
q.apply_default_order(params)
end