If a search for a translation is exactly the value, prioritize it

This commit is contained in:
Robin Ward 2015-11-30 15:31:30 -05:00
parent de88be2fbc
commit b0b85725ad

View File

@ -20,8 +20,15 @@ class Admin::SiteTextsController < Admin::AdminController
translations.each do |k, v| translations.each do |k, v|
results << {id: k, value: v} results << {id: k, value: v}
end end
results.sort! do |x, y| results.sort! do |x, y|
(x[:id].size + x[:value].size) <=> (y[:id].size + y[:value].size) if x[:value].casecmp(params[:q]) == 0
-1
elsif y[:value].casecmp(params[:q]) == 0
1
else
(x[:id].size + x[:value].size) <=> (y[:id].size + y[:value].size)
end
end end
end end