diff --git a/Gemfile b/Gemfile index c97f80bd..56a8a659 100644 --- a/Gemfile +++ b/Gemfile @@ -47,7 +47,6 @@ gem 'rack-attack' gem 'rack-cors', require: 'rack/cors' gem 'sidekiq' gem 'rails-settings-cached' -gem 'pg_search' gem 'simple-navigation' gem 'statsd-instrument' gem 'ruby-oembed', require: 'oembed' diff --git a/Gemfile.lock b/Gemfile.lock index 8ab50773..c8a5991d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -254,10 +254,6 @@ GEM parser (2.3.1.2) ast (~> 2.2) pg (0.18.4) - pg_search (1.0.6) - activerecord (>= 3.1) - activesupport (>= 3.1) - arel pghero (1.6.2) activerecord powerpack (0.1.1) @@ -491,7 +487,6 @@ DEPENDENCIES paperclip (~> 5.1) paperclip-av-transcoder pg - pg_search pghero pry-rails puma diff --git a/app/models/account.rb b/app/models/account.rb index 1eb886ee..978dc2d7 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -2,7 +2,6 @@ class Account < ApplicationRecord include Targetable - include PgSearch MENTION_RE = /(?:^|[^\/\w])@([a-z0-9_]+(?:@[a-z0-9\.\-]+[a-z0-9]+)?)/i IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif'].freeze @@ -56,9 +55,6 @@ class Account < ApplicationRecord # PuSH subscriptions has_many :subscriptions, dependent: :destroy - pg_search_scope :search_for, against: { display_name: 'A', username: 'B', domain: 'C' }, - using: { tsearch: { prefix: true } } - scope :remote, -> { where.not(domain: nil) } scope :local, -> { where(domain: nil) } scope :without_followers, -> { where('(select count(f.id) from follows as f where f.target_account_id = accounts.id) = 0') } @@ -212,6 +208,42 @@ SQL Account.find_by_sql([sql, account.id, account.id, limit]) end + def search_for(terms, limit = 10) + textsearch = '(setweight(to_tsvector(\'simple\', accounts.display_name), \'A\') || setweight(to_tsvector(\'simple\', accounts.username), \'B\') || setweight(to_tsvector(\'simple\', coalesce(accounts.domain, \'\')), \'C\'))' + query = 'to_tsquery(\'simple\', \'\'\' \' || ? || \' \'\'\' || \':*\')' + + sql = <