FIX: username search logic was stemming and not ordering right

This commit is contained in:
Sam
2014-07-05 09:11:41 +10:00
parent 5bcfb6ee38
commit cf60bed719
3 changed files with 20 additions and 12 deletions

View File

@@ -14,15 +14,12 @@ class UserSearch
if @term.present?
if SiteSetting.enable_names?
users = users.where("username_lower LIKE :term_like OR
TO_TSVECTOR('simple', name) @@
TO_TSQUERY('simple',
REGEXP_REPLACE(
REGEXP_REPLACE(
CAST(PLAINTO_TSQUERY(:term) AS TEXT)
,'\''(?: |$)', ':*''', 'g'),
'''', '', 'g')
)", term: @term, term_like: @term_like)
query = Search.ts_query(@term, "simple")
users = users.includes(:user_search_data)
.references(:user_search_data)
.where("username_lower LIKE :term_like OR user_search_data.search_data @@ #{query}",
term: @term, term_like: @term_like)
.order(User.sql_fragment("CASE WHEN username_lower LIKE ? THEN 0 ELSE 1 END ASC", @term_like))
else
users = users.where("username_lower LIKE :term_like", term_like: @term_like)
end