Change `language:` to attempt to match to a known value in search (#26663)

th-downstream
Eugen Rochko 1 year ago committed by GitHub
parent 3c1ef9b548
commit d525fd6d87

@ -98,7 +98,7 @@ class SearchQueryTransformer < Parslet::Transform
when 'language'
@filter = :language
@type = :term
@term = term
@term = language_code_from_term(term)
when 'from'
@filter = :account_id
@type = :term
@ -137,6 +137,22 @@ class SearchQueryTransformer < Parslet::Transform
# an ID that does not exist
account&.id || -1
end
def language_code_from_term(term)
language_code = term
return language_code if LanguagesHelper::SUPPORTED_LOCALES.key?(language_code.to_sym)
language_code = term.downcase
return language_code if LanguagesHelper::SUPPORTED_LOCALES.key?(language_code.to_sym)
language_code = term.split(/[_-]/).first.downcase
return language_code if LanguagesHelper::SUPPORTED_LOCALES.key?(language_code.to_sym)
term
end
end
rule(clause: subtree(:clause)) do

Loading…
Cancel
Save