From 09218d4c0152013750dd1c127d3c8267dc45f880 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 12 Nov 2016 14:33:21 +0100 Subject: Use full-text search for autosuggestions --- app/models/account.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'app/models') diff --git a/app/models/account.rb b/app/models/account.rb index 4fb0baebe..19300f48b 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -1,5 +1,6 @@ class Account < ApplicationRecord include Targetable + include PgSearch MENTION_RE = /(?:^|[^\/\w])@([a-z0-9_]+(?:@[a-z0-9\.\-]+)?)/i IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif'].freeze @@ -42,6 +43,8 @@ class Account < ApplicationRecord has_many :media_attachments, dependent: :destroy + pg_search_scope :search_for, against: %i(username domain), 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') } -- cgit