diff --git a/.env.production.sample b/.env.production.sample index da4c7fe4c8..f4afcd729e 100644 --- a/.env.production.sample +++ b/.env.production.sample @@ -283,6 +283,11 @@ MAX_POLL_OPTION_CHARS=100 # Customize the number of hashtags shown in 'Explore' # MAX_TRENDING_TAGS=10 +# Search all visible toots +# (Normally searches only a user's own toots, favs, bookmarks, and mentions) +# Only relevant when elasticsearch is installed +# SEARCH_ALL_VISIBLE_TOOTS=true + # Maximum custom emoji file sizes # If undefined or smaller than MAX_EMOJI_SIZE, the value # of MAX_EMOJI_SIZE will be used for MAX_REMOTE_EMOJI_SIZE diff --git a/app/chewy/statuses_index.rb b/app/chewy/statuses_index.rb index 6dd4fb18b0..a80c6eca23 100644 --- a/app/chewy/statuses_index.rb +++ b/app/chewy/statuses_index.rb @@ -71,5 +71,6 @@ class StatusesIndex < Chewy::Index end field :searchable_by, type: 'long', value: ->(status, crutches) { status.searchable_by(crutches) } + field :searchable_by_anyone, type: 'boolean', value: ->(status) { status.public_visibility? or status.unlisted_visibility? } end end diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 1a76cbb388..158192bae1 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,11 @@ class SearchService < BaseService end def perform_statuses_search! - definition = parsed_query.apply(StatusesIndex.filter(term: { searchable_by: @account.id })) + statuses_index = StatusesIndex.filter(term: { searchable_by: @account.id }) + if SEARCH_ALL_VISIBLE_TOOTS + statuses_index = statuses_index.or.filter(term: { searchable_by_anyone: true }) + end + definition = parsed_query.apply(statuses_index) if @options[:account_id].present? definition = definition.filter(term: { account_id: @options[:account_id] })