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.
This commit is contained in:
Vyr Cossont 2021-02-26 17:06:54 -08:00 committed by Kay Faraday
parent c9e5626ead
commit 6866c34894
2 changed files with 9 additions and 1 deletions

View File

@ -276,3 +276,6 @@ MAX_POLL_OPTION_CHARS=100
# Units are in bytes # Units are in bytes
MAX_EMOJI_SIZE=51200 MAX_EMOJI_SIZE=51200
MAX_REMOTE_EMOJI_SIZE=204800 MAX_REMOTE_EMOJI_SIZE=204800
# Search all visible toots
# Only relevant when elasticsearch is installed
# SEARCH_ALL_VISIBLE_TOOTS=true

View File

@ -1,6 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
class SearchService < BaseService class SearchService < BaseService
SEARCH_ALL_VISIBLE_TOOTS = ENV['SEARCH_ALL_VISIBLE_TOOTS'] == 'true'
def call(query, account, limit, options = {}) def call(query, account, limit, options = {})
@query = query&.strip @query = query&.strip
@account = account @account = account
@ -35,7 +38,9 @@ class SearchService < BaseService
end end
def perform_statuses_search! 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? if @options[:account_id].present?
definition = definition.filter(term: { account_id: @options[:account_id] }) definition = definition.filter(term: { account_id: @options[:account_id] })