Change `language:` to attempt to match to a known value in search (#26663)
parent
0e1bff178e
commit
bba76e7267
|
@ -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…
Reference in New Issue