Removed account search_for in Account.rb model

• Removed:
- account search_for in Account.rb model
This commit is contained in:
Developer 2021-02-28 20:19:58 -05:00
parent 35276edde1
commit fa8b6a3377
1 changed files with 39 additions and 37 deletions

View File

@ -374,51 +374,53 @@ class Account < ApplicationRecord
end end
def search_for(terms, limit = 10, offset = 0, options = {}) def search_for(terms, limit = 10, offset = 0, options = {})
textsearch, query = generate_query_for_search(terms) return []
@onlyVerified = options[:onlyVerified] || false # textsearch, query = generate_query_for_search(terms)
# @onlyVerified = options[:onlyVerified] || false
sql = <<-SQL.squish # sql = <<-SQL.squish
SELECT # SELECT
accounts.*, # accounts.*,
ts_rank_cd(#{textsearch}, #{query}, 32) AS rank # ts_rank_cd(#{textsearch}, #{query}, 32) AS rank
FROM accounts # FROM accounts
WHERE #{query} @@ #{textsearch} # WHERE #{query} @@ #{textsearch}
AND accounts.suspended_at IS NULL # AND accounts.suspended_at IS NULL
AND accounts.moved_to_account_id IS NULL # AND accounts.moved_to_account_id IS NULL
AND accounts.domain IS NULL # AND accounts.domain IS NULL
ORDER BY accounts.is_verified DESC # ORDER BY accounts.is_verified DESC
LIMIT ? OFFSET ? # LIMIT ? OFFSET ?
SQL # SQL
records = find_by_sql([sql, limit, offset]) # records = find_by_sql([sql, limit, offset])
ActiveRecord::Associations::Preloader.new.preload(records, :account_stat) # ActiveRecord::Associations::Preloader.new.preload(records, :account_stat)
records # records
end end
def advanced_search_for(terms, account, limit = 10, offset = 0, options = {}) def advanced_search_for(terms, account, limit = 10, offset = 0, options = {})
textsearch, query = generate_query_for_search(terms) return []
@onlyVerified = options[:onlyVerified] || false # textsearch, query = generate_query_for_search(terms)
# @onlyVerified = options[:onlyVerified] || false
sql = <<-SQL.squish # sql = <<-SQL.squish
SELECT # SELECT
accounts.*, # accounts.*,
(count(f.id) + 1) * ts_rank_cd(#{textsearch}, #{query}, 32) AS rank, # (count(f.id) + 1) * ts_rank_cd(#{textsearch}, #{query}, 32) AS rank,
(count(f.id) + 1) AS fc # (count(f.id) + 1) AS fc
FROM accounts # FROM accounts
LEFT OUTER JOIN follows AS f ON (accounts.id = f.account_id AND f.target_account_id = ?) OR (accounts.id = f.target_account_id AND f.account_id = ?) # LEFT OUTER JOIN follows AS f ON (accounts.id = f.account_id AND f.target_account_id = ?) OR (accounts.id = f.target_account_id AND f.account_id = ?)
WHERE #{query} @@ #{textsearch} # WHERE #{query} @@ #{textsearch}
AND accounts.suspended_at IS NULL # AND accounts.suspended_at IS NULL
AND accounts.moved_to_account_id IS NULL # AND accounts.moved_to_account_id IS NULL
AND accounts.domain IS NULL # AND accounts.domain IS NULL
GROUP BY accounts.id # GROUP BY accounts.id
ORDER BY accounts.is_verified DESC, fc DESC, rank DESC # ORDER BY accounts.is_verified DESC, fc DESC, rank DESC
LIMIT ? OFFSET ? # LIMIT ? OFFSET ?
SQL # SQL
records = find_by_sql([sql, account.id, account.id, limit, offset]) # records = find_by_sql([sql, account.id, account.id, limit, offset])
ActiveRecord::Associations::Preloader.new.preload(records, :account_stat) # ActiveRecord::Associations::Preloader.new.preload(records, :account_stat)
records # records
end end
private private