[COMPONENT][Search] Add way of searching for only notes or poeple with a given language

This commit is contained in:
Hugo Sales 2021-12-09 17:11:12 +00:00
parent f547fd3bb9
commit 3405312a5b
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -97,11 +97,17 @@ class Search extends Component
*/
public function onSearchCreateExpression(ExpressionBuilder $eb, string $term, ?string $language, &$note_expr, &$actor_expr): bool
{
if (Formatting::startsWith($term, ['lang', 'language'])) {
$search_term = str_contains($term, ':') ? explode(':', $term)[1] : $term;
if (Formatting::startsWith($term, ['lang', 'language'])) {
$note_expr = $eb->startsWith('language.locale', $search_term);
$actor_expr = $eb->startsWith('language.locale', $search_term);
return Event::stop;
} elseif (Formatting::startsWith($term, ['note-lang', 'note-language', 'note_lang', 'note_language', 'post_lang', 'post_language', 'post-lang', 'post-language'])) {
$note_expr = $eb->startsWith('language.locale', $search_term);
return Event::stop;
} elseif (Formatting::startsWith($term, ['actor-lang', 'actor-language', 'actor_lang', 'actor_language', 'people_lang', 'people_language', 'people-lang', 'people-language'])) {
$actor_expr = $eb->startsWith('language.locale', $search_term);
return Event::stop;
}
return Event::next;
}