0
0
Fork 0

Use full-text search for autosuggestions

This commit is contained in:
Eugen Rochko 2016-11-12 14:33:21 +01:00
parent cd765f26a9
commit 09218d4c01
14 changed files with 153 additions and 39 deletions

View file

@ -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') }