Skip to content

Commit c06f143

Browse files
committed
ilike is slow in theory, unless some sophisticated index is in place
1 parent af810f3 commit c06f143

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

app/models/user_search.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ def self.search term, topic_id = nil
1313
end
1414

1515
if term.present?
16-
sql.where("username ilike :term_like or
16+
sql.where("username_lower like :term_like or
1717
to_tsvector('simple', name) @@
1818
to_tsquery('simple',
1919
regexp_replace(
2020
regexp_replace(
2121
cast(plainto_tsquery(:term) as text)
2222
,'\''(?: |$)', ':*''', 'g'),
2323
'''', '', 'g')
24-
)", term: term, term_like: "#{term}%")
24+
)", term: term, term_like: "#{term.downcase}%")
2525

2626
sql.order_by "case when username_lower = :term then 0 else 1 end asc"
2727
end

0 commit comments

Comments
 (0)