Skip to content

Commit d05a5cd

Browse files
committed
tag search should order matches by their length
Ensures full and near-full matches are sorted to the top of the list
1 parent 4deef91 commit d05a5cd

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

app/models/tag.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def self.search(term)
4949

5050
# Select from the union of the above queries, select only the tag columns such that we can distinct them
5151
from(Arel.sql("((#{q1.to_sql}) UNION (#{q2.to_sql})) tags"))
52-
.order(Arel.sql(sanitize_sql_array(['name LIKE ? DESC, name', value])))
52+
.order(Arel.sql(sanitize_sql_array(['name LIKE ? DESC, char_length(name), name', value])))
5353
.select(Tag.column_names.map { |c| "tags.#{c}" })
5454
.distinct
5555
end

0 commit comments

Comments
 (0)