diff options
author | multiple creatures <dev@multiple-creature.party> | 2019-10-01 00:22:01 -0500 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2019-10-01 00:37:34 -0500 |
commit | 4a8e63023248f71e3dba13de7b39182c826387a8 (patch) | |
tree | e11e74b3c90d9613c21309eea903b63ece7fd7dd /app | |
parent | 80c51b1ec560299a01848308c32fb4e3c8d647d9 (diff) |
prefixing a search with `@@` interprets it as an advanced query (in postgresql `tsquery` format)
Diffstat (limited to 'app')
-rw-r--r-- | app/models/status.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/app/models/status.rb b/app/models/status.rb index afd25c808..01ef7c7ea 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -347,11 +347,18 @@ class Status < ApplicationRecord .or(Status.where(account_id: mutual_account_ids, visibility: [:private, :local, :unlisted])) .or(Status.where(id: account.mentions.select(:status_id))) end + sql = 'tsv @@ plainto_tsquery(?)' + if term.start_with?('@@') + sql = 'tsv @@ to_tsquery(?)' + term = term[2..-1].lstrip + end return none if term.blank? pattern = sanitize_sql_like(term) pattern = "#{pattern}" - query = query.without_reblogs.where("tsv @@ plainto_tsquery('english', ?)", pattern).offset(offset).limit(limit) + query = query.without_reblogs.where(sql, pattern).offset(offset).limit(limit) apply_timeline_filters(query, account, true) + rescue ActiveRecord::StatementInvalid + raise Mastodon::ValidationError, 'Your advanced search query has invalid syntax.' end def selectable_visibilities |