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.
main
Vyr Cossont 2 years ago
parent 1a7aa37b60
commit 60654e8111

@ -283,6 +283,11 @@ MAX_POLL_OPTION_CHARS=100
# Customize the number of hashtags shown in 'Explore' # Customize the number of hashtags shown in 'Explore'
# MAX_TRENDING_TAGS=10 # 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 # Maximum custom emoji file sizes
# If undefined or smaller than MAX_EMOJI_SIZE, the value # If undefined or smaller than MAX_EMOJI_SIZE, the value
# of MAX_EMOJI_SIZE will be used for MAX_REMOTE_EMOJI_SIZE # of MAX_EMOJI_SIZE will be used for MAX_REMOTE_EMOJI_SIZE

@ -71,5 +71,6 @@ class StatusesIndex < Chewy::Index
end end
field :searchable_by, type: 'long', value: ->(status, crutches) { status.searchable_by(crutches) } 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
end end

@ -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,11 @@ 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.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? if @options[:account_id].present?
definition = definition.filter(term: { account_id: @options[:account_id] }) definition = definition.filter(term: { account_id: @options[:account_id] })

Loading…
Cancel
Save