diff options
author | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-06-28 16:05:02 +0100 |
---|---|---|
committer | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-06-29 10:02:41 +0100 |
commit | 199425cee601733ef4f33ec5b76f5afe948cba61 (patch) | |
tree | 447b57a0f98a85a1cc4c17209f199ba35f0ea615 /app/models/user.rb | |
parent | 4f620eb9e73df40007a2b34caf0e64da01f95668 (diff) | |
download | gitlab-ce-199425cee601733ef4f33ec5b76f5afe948cba61.tar.gz |
Inserts exact matches of username, email and name to the top of the user search list26125-match-username-on-search
Diffstat (limited to 'app/models/user.rb')
-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 |