From c06f1438d348f8f6a7fdcb787ea78b43f82b5a67 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Sun, 10 Feb 2013 23:47:04 +1100 Subject: [PATCH] ilike is slow in theory, unless some sophisticated index is in place --- app/models/user_search.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/user_search.rb b/app/models/user_search.rb index 7b27ccf08..bf0682686 100644 --- a/app/models/user_search.rb +++ b/app/models/user_search.rb @@ -13,7 +13,7 @@ class UserSearch end if term.present? - sql.where("username ilike :term_like or + sql.where("username_lower like :term_like or to_tsvector('simple', name) @@ to_tsquery('simple', regexp_replace( @@ -21,7 +21,7 @@ class UserSearch cast(plainto_tsquery(:term) as text) ,'\''(?: |$)', ':*''', 'g'), '''', '', 'g') - )", term: term, term_like: "#{term}%") + )", term: term, term_like: "#{term.downcase}%") sql.order_by "case when username_lower = :term then 0 else 1 end asc" end