From dd5e02ad5d79e4fc2163a9bcd009859e9c2a4466 Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Sat, 13 Apr 2019 23:17:51 -0500 Subject: Use PostgreSQL FTS for searches. --- app/models/status.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'app/models') diff --git a/app/models/status.rb b/app/models/status.rb index 45db988e3..7679fd60f 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -298,6 +298,23 @@ class Status < ApplicationRecord after_find :limit_domain_visibility class << self + def search_for(term, limit = 33, account = nil) + pattern = sanitize_sql_like(term) + pattern = "#{pattern}" + Status.unscoped { + scope = Status.where("tsv @@ plainto_tsquery('english', ?)", pattern) + query = scope.where(visibility: :public) + if account.present? + query = query + .or(scope.where(account: account)) + .or(scope.where(account: account.following, visibility: [:unlisted, :private])) + .or(scope.where(id: account.mentions.select(:status_id))) + end + query = query.where(reblog_of_id: nil).order(id: :desc).limit(limit) + apply_timeline_filters(query, account, true) + } + end + def selectable_visibilities visibilities.keys - %w(direct limited) end -- cgit