diff options
author | Thibaut Girka <thib@sitedethib.com> | 2019-08-05 13:13:28 +0200 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2019-08-05 13:13:28 +0200 |
commit | e50554391aa726afe18ae1c0bc7ccbf69d7b4aec (patch) | |
tree | b0cbd7b46a733f386c458a6f2f818a899f418b21 /app/models/tag.rb | |
parent | ff0ceb28b3f1b19a6851a482f8203e434e50f167 (diff) | |
parent | 6201bfdfba7626c2b6bc5154dda1f41ee8c3ae71 (diff) |
Merge branch 'master' into glitch-soc/merge-upstream
Diffstat (limited to 'app/models/tag.rb')
-rw-r--r-- | app/models/tag.rb | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/app/models/tag.rb b/app/models/tag.rb index 46e3a3ec0..c7f0af86d 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 @@ -75,10 +76,12 @@ class Tag < ApplicationRecord end def search_for(term, limit = 5, offset = 0) - pattern = sanitize_sql_like(normalize(term.strip)) + '%' + normalized_term = normalize(term.strip).mb_chars.downcase.to_s + pattern = sanitize_sql_like(normalized_term) + '%' - Tag.where(arel_table[:name].lower.matches(pattern.mb_chars.downcase.to_s)) - .order(:name) + Tag.where(arel_table[:name].lower.matches(pattern)) + .where(arel_table[:score].gt(0).or(arel_table[:name].lower.eq(normalized_term))) + .order(Arel.sql('length(name) ASC, score DESC, name ASC')) .limit(limit) .offset(offset) end |