user = $user; $this->users = new Users; $this->clubs = new Clubs; $this->videos = new Videos; } function fastSearch(string $query, string $type = "users", callable $resolve, callable $reject) { if($query == "" || strlen($query) < 3) $reject(12, "No input or input < 3"); $repo; $sort; switch($type) { default: case "users": $repo = (new Users); $sort = "rating DESC"; break; case "groups": $repo = (new Clubs); $sort = "id ASC"; break; case "videos": $repo = (new Videos); $sort = "created ASC"; break; } $res = $repo->find($query, ["doNotSearchMe" => $this->user->getId(), "doNotShowDeleted" => true, "doNotShowPrivate" => true], $sort); $results = array_slice(iterator_to_array($res), 0, 7); $items = []; $count = 0; foreach($results as $res) { if(!$res->canBeViewedBy($this->user)) continue; $items[] = [ "id" => $res->getId(), "name" => $type == "users" ? $res->getCanonicalName() : $res->getName(), "avatar" => $type != "videos" ? $res->getAvatarUrl() : $res->getThumbnailURL(), "url" => $type != "videos" ? $res->getUrl() : "/video".$res->getPrettyId(), "description" => ovk_proc_strtr($res->getDescription() ?? "...", 40) ]; $count+=1; } if($count < 1) { $reject(2, "No results"); } $arr = [ "count" => $count, "items" => $items ]; $resolve($arr); } }