diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-06-29 13:25:14 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-06-29 13:25:14 +0000 |
commit | bebddbcd7632f5af6568780ab31bf9eb0393ac02 (patch) | |
tree | 4aba2b70a366f33aaccd8e8172a127388d253e2a /app/models | |
parent | 0f5e70a8246de623ddafdc17c5d9ea5cb866b21a (diff) | |
parent | 199425cee601733ef4f33ec5b76f5afe948cba61 (diff) | |
download | gitlab-ce-bebddbcd7632f5af6568780ab31bf9eb0393ac02.tar.gz |
Merge branch '26125-match-username-on-search' into 'master'
Inserts exact matches of username and email to the top of the user search list
Closes #26125
See merge request !12525
Diffstat (limited to 'app/models')
-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 |