Add scope:classic filter
This commit is contained in:
parent
30faf1f6da
commit
d1797b437f
2 changed files with 10 additions and 5 deletions
|
@ -13,11 +13,11 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
@order_clauses = grouped.fetch(:order, [])
|
@order_clauses = grouped.fetch(:order, [])
|
||||||
end
|
end
|
||||||
|
|
||||||
def apply(search)
|
def apply(search, account)
|
||||||
should_clauses.each { |clause| search = search.query.should(clause_to_query(clause)) }
|
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_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)) }
|
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?
|
if order_clauses.empty?
|
||||||
# Default to most recent results first.
|
# Default to most recent results first.
|
||||||
search = search.order(created_at: :desc)
|
search = search.order(created_at: :desc)
|
||||||
|
@ -42,10 +42,10 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def clause_to_filter(clause)
|
def clause_to_filter(clause, account)
|
||||||
case clause
|
case clause
|
||||||
when PrefixClause
|
when PrefixClause
|
||||||
{ clause.query => { clause.filter => clause.term } }
|
{ clause.query => { clause.filter => clause.term == :account_id_placeholder ? account.id : clause.term } }
|
||||||
else
|
else
|
||||||
raise "Unexpected clause type: #{clause}"
|
raise "Unexpected clause type: #{clause}"
|
||||||
end
|
end
|
||||||
|
@ -136,6 +136,11 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
account = Account.find_remote!(username, domain)
|
account = Account.find_remote!(username, domain)
|
||||||
|
|
||||||
@term = account.id
|
@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'
|
when 'sort'
|
||||||
raise Mastodon::SyntaxError unless operator.nil?
|
raise Mastodon::SyntaxError unless operator.nil?
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ class SearchService < BaseService
|
||||||
when :public_or_unlisted
|
when :public_or_unlisted
|
||||||
statuses_index = statuses_index.filter.or(terms: { visibility: ['public', 'unlisted'] })
|
statuses_index = statuses_index.filter.or(terms: { visibility: ['public', 'unlisted'] })
|
||||||
end
|
end
|
||||||
definition = parsed_query.apply(statuses_index)
|
definition = parsed_query.apply(statuses_index, @account)
|
||||||
|
|
||||||
if @options[:account_id].present?
|
if @options[:account_id].present?
|
||||||
definition = definition.filter(term: { account_id: @options[:account_id] })
|
definition = definition.filter(term: { account_id: @options[:account_id] })
|
||||||
|
|
Loading…
Reference in a new issue