cacheActorService = $cacheActorService; $this->hashtagService = $hashtagService; $this->configService = $configService; $this->logger = $logger; } /** * @param string $search * * @return Person[] */ public function searchUri(string $search): array { $type = $this->getTypeFromSearch($search); if ($search !== '' && $type & self::SEARCH_URI) { try { return [$this->cacheActorService->getFromId($search)]; } catch (Exception $e) { } } return []; } /** * @param string $search * * @return Person[] */ public function searchAccounts(string $search): array { $type = $this->getTypeFromSearch($search); if ($search === '' || !$type & self::SEARCH_ACCOUNTS) { return []; } $search = ltrim($search, '@'); try { // search and cache eventual exact account first $this->cacheActorService->getFromAccount($search); } catch (Exception $e) { } return $this->cacheActorService->searchCachedAccounts($search); } /** * @param string $search * * @return array */ public function searchHashtags(string $search): array { $result = []; $type = $this->getTypeFromSearch($search); if ($search === '' || !$type & self::SEARCH_HASHTAGS) { return $result; } if (substr($search, 0, 1) === '#') { $search = substr($search, 1); } return $this->hashtagService->searchHashtags($search, true); } /** * @param string $search * * @return array */ public function searchStreamContent(string $search): array { $result = []; $type = $this->getTypeFromSearch($search); if ($search === '' || !$type & self::SEARCH_CONTENT) { return $result; } // TODO : search using FullTextSearch ? return $result; } /** * @param string $search * * @return int */ private function getTypeFromSearch(string $search): int { $char = substr($search, 0, 1); switch ($char) { case '@': return self::SEARCH_ACCOUNTS; case '#': return self::SEARCH_HASHTAGS; default: if (substr($search, 0, 4) === 'http') { return self::SEARCH_URI; } return self::SEARCH_ALL; } } }