diff options
author | multiple creatures <dev@multiple-creature.party> | 2019-11-16 06:04:31 -0600 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2019-11-16 06:04:31 -0600 |
commit | 9de5952f4e92528a1dd664c188d730229493b707 (patch) | |
tree | 22f087d4bc6946f367248e537e55300c71697568 | |
parent | 3b1aed6cf1776e6d2f351a6390ec6a36118ee629 (diff) |
Update database queries to reflect change of search implementation.
-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 |