Change algorithm of follow recommendations (#28314)
Co-authored-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
b7bdcd4f39
commit
b5ac61b2c5
35 changed files with 297 additions and 292 deletions
67
app/models/account_suggestions/similar_profiles_source.rb
Normal file
67
app/models/account_suggestions/similar_profiles_source.rb
Normal file
|
@ -0,0 +1,67 @@
|
|||
# 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
|
||||
|
||||
def get(account, limit: 10)
|
||||
recently_followed_account_ids = account.active_relationships.recent.limit(5).pluck(:target_account_id)
|
||||
|
||||
if Chewy.enabled? && !recently_followed_account_ids.empty?
|
||||
QueryBuilder.new(recently_followed_account_ids, account).build.limit(limit).hits.pluck('_id').map(&:to_i).zip([key].cycle)
|
||||
else
|
||||
[]
|
||||
end
|
||||
rescue Faraday::ConnectionFailed
|
||||
[]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def key
|
||||
:similar_to_recently_followed
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue