Add scope:classic filter

main
Vyr Cossont 2 years ago
parent 30faf1f6da
commit d1797b437f

@ -13,11 +13,11 @@ class SearchQueryTransformer < Parslet::Transform
@order_clauses = grouped.fetch(:order, [])
end
def apply(search)
def apply(search, account)
should_clauses.each { |clause| search = search.query.should(clause_to_query(clause)) }
must_clauses.each { |clause| search = search.query.must(clause_to_query(clause)) }
must_not_clauses.each { |clause| search = search.query.must_not(clause_to_query(clause)) }
filter_clauses.each { |clause| search = search.filter(**clause_to_filter(clause)) }
filter_clauses.each { |clause| search = search.filter(**clause_to_filter(clause, account)) }
if order_clauses.empty?
# Default to most recent results first.
search = search.order(created_at: :desc)
@ -42,10 +42,10 @@ class SearchQueryTransformer < Parslet::Transform
end
end
def clause_to_filter(clause)
def clause_to_filter(clause, account)
case clause
when PrefixClause
{ clause.query => { clause.filter => clause.term } }
{ clause.query => { clause.filter => clause.term == :account_id_placeholder ? account.id : clause.term } }
else
raise "Unexpected clause type: #{clause}"
end
@ -136,6 +136,11 @@ class SearchQueryTransformer < Parslet::Transform
account = Account.find_remote!(username, domain)
@term = account.id
when 'scope'
raise Mastodon::SyntaxError unless operator.nil?
raise Mastodon::SyntaxError unless term == 'classic'
@filter = 'searchable_by'
@term = :account_id_placeholder
when 'sort'
raise Mastodon::SyntaxError unless operator.nil?

@ -42,7 +42,7 @@ class SearchService < BaseService
when :public_or_unlisted
statuses_index = statuses_index.filter.or(terms: { visibility: ['public', 'unlisted'] })
end
definition = parsed_query.apply(statuses_index)
definition = parsed_query.apply(statuses_index, @account)
if @options[:account_id].present?
definition = definition.filter(term: { account_id: @options[:account_id] })

Loading…
Cancel
Save