From d1797b437f9a62e72430e01364556f82ac9a92df Mon Sep 17 00:00:00 2001 From: Vyr Cossont Date: Sun, 1 Jan 2023 16:31:40 -0800 Subject: [PATCH] Add scope:classic filter --- app/lib/search_query_transformer.rb | 13 +++++++++---- app/services/search_service.rb | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/lib/search_query_transformer.rb b/app/lib/search_query_transformer.rb index 6fc2b2383e..a6c0c2f2d4 100644 --- a/app/lib/search_query_transformer.rb +++ b/app/lib/search_query_transformer.rb @@ -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? diff --git a/app/services/search_service.rb b/app/services/search_service.rb index a9ed121529..673cf34b82 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -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] })