2023-12-19 19:59:43 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class AccountSuggestions::SimilarProfilesSource < AccountSuggestions::Source
|
|
|
|
class QueryBuilder < AccountSearchService::QueryBuilder
|
|
|
|
def must_clauses
|
|
|
|
[
|
|
|
|
{
|
|
|
|
more_like_this: {
|
|
|
|
fields: %w(text text.stemmed),
|
|
|
|
like: @query.map { |id| { _index: 'accounts', _id: id } },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
term: {
|
|
|
|
properties: 'discoverable',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def must_not_clauses
|
|
|
|
[
|
|
|
|
{
|
|
|
|
terms: {
|
|
|
|
id: following_ids,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
term: {
|
|
|
|
properties: 'bot',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def should_clauses
|
|
|
|
{
|
|
|
|
term: {
|
|
|
|
properties: {
|
|
|
|
value: 'verified',
|
|
|
|
boost: 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-02-20 18:21:49 +09:00
|
|
|
def get(account, limit: DEFAULT_LIMIT)
|
2023-12-19 19:59:43 +09:00
|
|
|
recently_followed_account_ids = account.active_relationships.recent.limit(5).pluck(:target_account_id)
|
|
|
|
|
|
|
|
if Chewy.enabled? && !recently_followed_account_ids.empty?
|
2024-03-04 15:35:20 +09:00
|
|
|
ids_from_es = QueryBuilder.new(recently_followed_account_ids, account).build.limit(limit).hits.pluck('_id').map(&:to_i)
|
|
|
|
base_account_scope(account).where(id: ids_from_es).pluck(:id).zip([key].cycle)
|
2023-12-19 19:59:43 +09:00
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
rescue Faraday::ConnectionFailed
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def key
|
|
|
|
:similar_to_recently_followed
|
|
|
|
end
|
|
|
|
end
|