mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
If a search for a translation is exactly the value, prioritize it
This commit is contained in:
@ -20,10 +20,17 @@ 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|
|
||||||
|
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)
|
(x[:id].size + x[:value].size) <=> (y[:id].size + y[:value].size)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
render_serialized(results[0..50], SiteTextSerializer, root: 'site_texts', rest_serializer: true, extras: extras)
|
render_serialized(results[0..50], SiteTextSerializer, root: 'site_texts', rest_serializer: true, extras: extras)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user