/** SEARCH **/ public function searchResults($query) { // Search directors $directors = Director::whereRaw('LOWER(name) LIKE \'%' . strtolower($query) . '%\'')->select('name', DB::raw('count(*) as total'))->orderBy('total', 'desc')->groupBy('name')->get()->toArray(); $directors = array_slice($directors, 0, self::MAX_RESULTS / 2); $directors = $this->_parseResults($directors, 'director'); // Search cast $cast = Cast::whereRaw('LOWER(name) LIKE \'%' . strtolower($query) . '%\'')->select('name', DB::raw('count(*) as total'))->orderBy('total', 'desc')->groupBy('name')->get()->toArray(); $cast = array_slice($cast, 0, self::MAX_RESULTS / 2); $cast = $this->_parseResults($cast, 'actor'); // Mix $results = array_merge($directors, $cast); // Limit $results = array_slice($results, 0, self::MAX_RESULTS); return $results; }