about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorDarius Kazemi <darius@meedan.com>2023-01-05 22:35:52 -0800
committerGitHub <noreply@github.com>2023-01-06 07:35:52 +0100
commit264655c53a8e86646adc60b5d83f762ab87ecee4 (patch)
tree726a5e3211e0b422a4228a54219d6dc21c42cb5f /app
parentd11d15748cd24342a133221edb3022022b585119 (diff)
Fix account search not returning followed accounts first (#22956)
* 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
Diffstat (limited to 'app')
-rw-r--r--app/models/account.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index a7bda15d3..b27fc748f 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -513,7 +513,8 @@ class Account < ApplicationRecord
         <<-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
@@ -523,7 +524,7 @@ class Account < ApplicationRecord
             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