public function getResults($repository, $pattern, $language = null, $max = 15)
    {
        $queryResults = $this->findRecords($repository, $pattern, $language);

        $results = array();
        foreach ($queryResults as $record) {
            $admin = $this->getFirstAdminPerClass(get_class($record));
            if (!$admin) {
                $admin = $this->getFirstAdminPerClass(get_parent_class($record));
            }
            $resultRecord = $this->createResultRecord($record, $admin);
            $results[] = $resultRecord;
        }


        // TODO do this sort in DQL. Unfortunately, doctrine is not too handy with this, so
        // I'll keep it like this for a second. Note the the "setMaxResults()" should be reverted to $max
        // and the slice can be removed
        usort(
            $results,
            function ($a, $b) use ($pattern) {
                $percentA = 0;
                $percentB = 0;
                similar_text($a['label'], $pattern, $percentA);
                similar_text($b['label'], $pattern, $percentB);

                return $percentB - $percentA;
            }
        );

        return array_slice($results, 0, $max);
    }