From 648cdbc04a21580a89d337edb0f45308aff1b93f Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 30 Jul 2019 13:10:40 +0200 Subject: Add hashtag score for better sorting of autosuggestions (#11427) * Add hashtag score for better sorting of autosuggestions * Do not use `~<~` operator with no text_pattern_ops index --- app/models/tag.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app/models/tag.rb') diff --git a/app/models/tag.rb b/app/models/tag.rb index 46e3a3ec0..a2d6078f4 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -7,6 +7,7 @@ # name :string default(""), not null # created_at :datetime not null # updated_at :datetime not null +# score :integer # class Tag < ApplicationRecord @@ -78,7 +79,7 @@ class Tag < ApplicationRecord pattern = sanitize_sql_like(normalize(term.strip)) + '%' Tag.where(arel_table[:name].lower.matches(pattern.mb_chars.downcase.to_s)) - .order(:name) + .order(Arel.sql('length(name) ASC, score DESC, name ASC')) .limit(limit) .offset(offset) end -- cgit