diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/models/user.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 6dd1b1415d6..35e0d021c47 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -299,11 +299,20 @@ class User < ActiveRecord::Base table = arel_table pattern = "%#{query}%" + order = <<~SQL + CASE + WHEN users.name = %{query} THEN 0 + WHEN users.username = %{query} THEN 1 + WHEN users.email = %{query} THEN 2 + ELSE 3 + END + SQL + where( table[:name].matches(pattern) .or(table[:email].matches(pattern)) .or(table[:username].matches(pattern)) - ) + ).reorder(order % { query: ActiveRecord::Base.connection.quote(query) }, id: :desc) end # searches user by given pattern |