Skip to content

Commit

Permalink
Fix account search not returning followed accounts first (mastodon#22956
Browse files Browse the repository at this point in the history
)

* Make autosuggest for mentions return followed accounts first

This makes it so that (when elasticsearch is disabled) when a user types '@foo' in the compose box, they are first going to get accounts they follow ordered by the ranking algorithm, and then second they will get accounts they do not follow, also ordered by the ranking algorithm.

This makes behavior more consistent with user expectation and also with results when elasticsearch is enabled.

* Fix ranking order to correct direction

* One more fixup per @Gargron suggestion

* Tweak to ranking to no longer include following modifier
  • Loading branch information
dariusk authored and Nonexistent committed Jan 12, 2023
1 parent ee47c86 commit 84726dc
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/models/account.rb
Expand Up @@ -513,7 +513,8 @@ def advanced_search_for_sql_template(following)
<<-SQL.squish
SELECT
accounts.*,
(count(f.id) + 1) * #{BOOST} * ts_rank_cd(#{TEXTSEARCH}, to_tsquery('simple', :tsquery), 32) AS rank
#{BOOST} * ts_rank_cd(#{TEXTSEARCH}, to_tsquery('simple', :tsquery), 32) AS rank,
count(f.id) AS followed
FROM accounts
LEFT OUTER JOIN follows AS f ON (accounts.id = f.account_id AND f.target_account_id = :id) OR (accounts.id = f.target_account_id AND f.account_id = :id)
LEFT JOIN users ON accounts.id = users.account_id
Expand All @@ -523,7 +524,7 @@ def advanced_search_for_sql_template(following)
AND accounts.moved_to_account_id IS NULL
AND (accounts.domain IS NOT NULL OR (users.approved = TRUE AND users.confirmed_at IS NOT NULL))
GROUP BY accounts.id, s.id
ORDER BY rank DESC
ORDER BY followed DESC, rank DESC
LIMIT :limit OFFSET :offset
SQL
end
Expand Down

0 comments on commit 84726dc

Please sign in to comment.