diff --git a/components/Search/Search.php b/components/Search/Search.php index 86f7072dd1..7c394bf4e1 100644 --- a/components/Search/Search.php +++ b/components/Search/Search.php @@ -27,6 +27,7 @@ use App\Core\Event; use App\Core\Form; use function App\Core\I18n\_m; use App\Core\Modules\Component; +use App\Entity\Actor; use App\Util\Common; use App\Util\Exception\RedirectException; use App\Util\Formatting; @@ -147,6 +148,23 @@ class Search extends Component } else { $note_expr[] = $eb->eq('note.rendered', null); } + } elseif (Formatting::startsWith($term, ['actor-types:', 'actors-incude:', 'actor-filter:'])) { + if (\is_null($actor_expr)) { + $actor_expr = []; + } + foreach ([ + Actor::PERSON => ['person', 'people'], + Actor::GROUP => ['group', 'groups'], + Actor::ORGANIZATION => ['org', 'orgs', 'organization', 'organizations', 'organisation', 'organisations'], + Actor::BUSINESS => ['business', 'businesses'], + Actor::BOT => ['bot', 'bots'], + ] as $type => $match) { + if (array_intersect(explode(',', $include_term), $match) !== []) { + $actor_expr[] = $eb->eq('actor.type', $type); + } else { + $actor_expr[] = $eb->neq('actor.type', $type); + } + } } return Event::next; } diff --git a/components/Search/Util/Parser.php b/components/Search/Util/Parser.php index 5f6c164c77..e14e5f85f2 100644 --- a/components/Search/Util/Parser.php +++ b/components/Search/Util/Parser.php @@ -37,7 +37,6 @@ abstract class Parser foreach ([' ' => 'orX', '|' => 'orX', '&' => 'andX'] as $op => $func) { if ($last_op === $op || $force) { $criteria_arr[] = $eb->{$func}(...$parts); - $note_parts = []; break; } } @@ -81,13 +80,13 @@ abstract class Parser if (\is_null($note_res) && \is_null($actor_res)) { throw new ServerException("No one claimed responsibility for a match term: {$term}"); } - if (!\is_null($note_res)) { + if (!\is_null($note_res) && !empty($note_res)) { if (\is_array($note_res)) { $note_res = $eb->orX(...$note_res); } $note_parts[] = $note_res; } - if (!\is_null($actor_res)) { + if (!\is_null($actor_res) && !empty($note_res)) { if (\is_array($actor_res)) { $actor_res = $ex->orX(...$actor_res); }