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.

Fixes #1272
This commit is contained in:
Darius Kazemi 2023-01-05 12:48:06 -08:00
parent b761fbac34
commit 7d12ca1fa5
1 changed files with 9 additions and 2 deletions

View File

@ -512,12 +512,19 @@ class Account < ApplicationRecord
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
LEFT JOIN account_stats AS s ON accounts.id = s.account_id
LEFT JOIN (
SELECT target_account_id
FROM follows
WHERE account_id = :id
UNION ALL
SELECT :id
) AS first_degree ON accounts.id = first_degree.target_account_id
WHERE to_tsquery('simple', :tsquery) @@ #{TEXTSEARCH}
AND accounts.suspended_at IS NULL
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
GROUP BY accounts.id, s.id, first_degree.target_account_id
ORDER BY first_degree.target_account_id, rank ASC
LIMIT :limit OFFSET :offset
SQL
end