From 6866c3489471b61c2c1a76163e08c5f099b33b65 Mon Sep 17 00:00:00 2001 From: Vyr Cossont Date: Fri, 26 Feb 2021 17:06:54 -0800 Subject: [PATCH] Add SEARCH_ALL_VISIBLE_TOOTS env flag Context: https://docs.joinmastodon.org/user/network/#search Vanilla Mastodon intentionally refuses to search outside a user's own toots, favs, bookmarks, and mentions. This flag makes that restricted search behavior a per-instance choice, defaulting to the same behavior as vanilla Mastodon if the flag is absent. --- .env.production.sample | 3 +++ app/services/search_service.rb | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.env.production.sample b/.env.production.sample index 65f3f9d1f..878a55f32 100644 --- a/.env.production.sample +++ b/.env.production.sample @@ -276,3 +276,6 @@ MAX_POLL_OPTION_CHARS=100 # Units are in bytes MAX_EMOJI_SIZE=51200 MAX_REMOTE_EMOJI_SIZE=204800 +# Search all visible toots +# Only relevant when elasticsearch is installed +# SEARCH_ALL_VISIBLE_TOOTS=true diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 1a76cbb38..5d1aa4b80 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -1,6 +1,9 @@ # frozen_string_literal: true class SearchService < BaseService + + SEARCH_ALL_VISIBLE_TOOTS = ENV['SEARCH_ALL_VISIBLE_TOOTS'] == 'true' + def call(query, account, limit, options = {}) @query = query&.strip @account = account @@ -35,7 +38,9 @@ class SearchService < BaseService end def perform_statuses_search! - definition = parsed_query.apply(StatusesIndex.filter(term: { searchable_by: @account.id })) + statuses_index = StatusesIndex + statuses_index = statuses_index.filter(term: { searchable_by: @account.id }) unless SEARCH_ALL_VISIBLE_TOOTS + definition = parsed_query.apply(statuses_index) if @options[:account_id].present? definition = definition.filter(term: { account_id: @options[:account_id] })