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

This commit is contained in:
Eugen Rochko 2023-08-30 16:07:26 +02:00 committed by GitHub
parent 0e1bff178e
commit bba76e7267
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -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