about summary refs log tree commit diff
path: root/app/models/tag.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-07-30 20:29:50 +0200
committerGitHub <noreply@github.com>2019-07-30 20:29:50 +0200
commit92de439c04785530ce15f55cae18590136c75216 (patch)
tree1700bc07eb1750671049e6d5f96126200ad9ceea /app/models/tag.rb
parentff789a751a1c730e4d808410411196b76caff39c (diff)
Change hashtag search to only return results that have trended in the past (#11448)
* Change hashtag search to only return results that have trended in the past

A way to eliminate typos and other one-off "junk" results

* Fix excluding exact matches that don't have a score

* Fix tests
Diffstat (limited to 'app/models/tag.rb')
-rw-r--r--app/models/tag.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/app/models/tag.rb b/app/models/tag.rb
index a2d6078f4..c7f0af86d 100644
--- a/app/models/tag.rb
+++ b/app/models/tag.rb
@@ -76,9 +76,11 @@ 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))
+      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)