diff options
-rw-r--r-- | app/lib/bangtags.rb | 10 | ||||
-rw-r--r-- | app/models/status.rb | 15 |
2 files changed, 7 insertions, 18 deletions
diff --git a/app/lib/bangtags.rb b/app/lib/bangtags.rb index 37a95ae42..681fa4abc 100644 --- a/app/lib/bangtags.rb +++ b/app/lib/bangtags.rb @@ -716,21 +716,15 @@ class Bangtags @status.content_type = 'text/html' barchars = " #{(0x2588..0x258F).to_a.reverse.pack('U*')}" q = cmd[1..-1].join.strip - if q.start_with?('@@') - sql = 'tsv @@ to_tsquery(?)' - q = q[2..-1].lstrip - else - sql = 'tsv @@ plainto_tsquery(?)' - end next if q.blank? begin - data = @account.statuses.where(sql, q) + data = @account.statuses.where('text ILIKE ?', "%#{sanitize_sql_like(q)}%") .reorder(:created_at) .pluck(:created_at) .map { |d| d.strftime('%Y-%m') } .reduce(Hash.new(0)) { |h, v| h.store(v, h[v] + 1); h } rescue ActiveRecord::StatementInvalid - raise Mastodon::ValidationError, 'Your advanced search query has invalid syntax.' + raise Mastodon::ValidationError, 'Invalid query.' end highest = data.values.max avg = "<code>average: #{data.values.sum / data.count}</code>" diff --git a/app/models/status.rb b/app/models/status.rb index 01ef7c7ea..47d5f982e 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -347,18 +347,13 @@ 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(sql, pattern).offset(offset).limit(limit) + return none if term.blank? || term.length < 3 + query = query.without_reblogs + .where('text ILIKE ?', "%#{sanitize_sql_like(term)}%") + .offset(offset).limit(limit) apply_timeline_filters(query, account, true) rescue ActiveRecord::StatementInvalid - raise Mastodon::ValidationError, 'Your advanced search query has invalid syntax.' + raise Mastodon::ValidationError, 'Invalid syntax.' end def selectable_visibilities |