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,10 +20,17 @@ class Admin::SiteTextsController < Admin::AdminController
translations.each do |k, v|
results << {id: k, value: v}
end
results.sort! do |x, y|
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
render_serialized(results[0..50], SiteTextSerializer, root: 'site_texts', rest_serializer: true, extras: extras)
end