Get the result suggestions for the passed pattern

@param string $repository
@param string $pattern
@param null|string $language
@param int $max
@return array
190616
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);
    }
29996
public function listRepositories(string $sort = AbstractApi::SORT_CREATED,
                                     string $direction = AbstractApi::DIRECTION_DESC, string $username = null): array
    {
        if (null !== $username) {
            return $this->getApi()->request($this->getApi()->sprintf('/users/:username/starred?:args', $username,
                http_build_query(['sort' => $sort, 'direction' => $direction])));
        }

        return $this->getApi()->request($this->getApi()->sprintf('/user/starred?:args',
            http_build_query(['sort' => $sort, 'direction' => $direction])));
    }
328718
public function searchRepositories(string $q, string $sort = null,
                                       string $order = AbstractApi::DIRECTION_DESC): array
    {
        return $this->getApi()->request($this->getApi()->sprintf('/search/repositories?:args',
            http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order])));
    }
234116
public static function for(string $pattern, string $subject)
    {
        $matches = [];

        try {
            $result = preg_match($pattern, $subject, $matches);
        } catch (Exception $exception) {
            throw RegexFailed::match($pattern, $subject, $exception->getMessage());
        }

        if ($result === false) {
            throw RegexFailed::match($pattern, $subject, static::lastPregError());
        }

        return new static($pattern, $subject, $result, $matches);
    }
967981
public static function getCachePathByRepository(Repository $repository)
    {
        $path = path('cache') . 'framework/pckg_database_repository_' . str_replace(
                ['\\', '/'],
                '_',
                (get_class(app()) . '_' . get_class(env()))
            ) . '_' . $repository->getName() . '_' . ($repository->getConnection()->uniqueName ?? '') . '.cache';

        return $path;
    }
1345872
private function getOptionByRegExpr(string $pattern): array
    {
        $purgedArgs = $this->getRawArgs(true);
        return preg_grep("/" . $pattern . "/", $purgedArgs);
    }
944170
public function all($username, $repository, $pullRequest, array $params = [])
    {
        return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/requested_reviewers', $params);
    }
987845
protected function getModuleInformation(Repository $repository, $module)
    {
        return [
            '#'           => $module['order'],
            'location'    => $repository->location,
            'name'        => isset($module['name']) ? $module['name'] : '',
            'slug'        => $module['slug'],
            'description' => isset($module['description']) ? $module['description'] : '',
            'status'      => (modules($repository->location)->isEnabled($module['slug'])) ? 'Enabled' : 'Disabled',
        ];
    }
27824
protected function _getContainedAssociations($repository, $contains)
    {
        $associationCollection = $repository->associations();
        $associations = [];

        foreach ($contains as $contain => $nestedContains) {
            if (is_string($nestedContains)) {
                $contain = $nestedContains;
                $nestedContains = [];
            }

            $association = $associationCollection->get($contain);
            if ($association === null) {
                continue;
            }

            $associationKey = strtolower($association->getName());

            $associations[$associationKey] = [
                'association' => $association,
                'children' => []
            ];

            if (!empty($nestedContains)) {
                $associations[$associationKey]['children'] = $this->_getContainedAssociations($association->getTarget(), $nestedContains);
            }
        }

        return $associations;
    }
423806
public function getFiles(string $location, string $pattern = null, Finder $finder = null): array
    {
        $finder = $finder ?? new Finder();
        $finder->files()->in($location);

        if (!empty($pattern)) {
            $finder->name($pattern);
        }

        $result = [];
        foreach ($finder->getIterator() as $file) {
            $result[] = $this->normalizePath((string)$file);
        }

        return $result;
    }
792118
private function resolveRepositoryName($repository)
    {
        if ($repository === null) {
            $aliases = array_keys($this->repositories);
            $repository = array_shift($aliases);
        }

        return $repository;
    }
186354
public function getKeys($pattern = null)
    {
        $keys = $this->get('__stored_keys__', []);
        if (is_null($pattern)) {
            return $keys;
        }

        $matches = [];
        $pattern = $this->_normalizePattern($pattern);
        foreach ($keys as $key) {
            if (preg_match($pattern, $key)) {
                $matches[] = $key;
            }
        }

        return $matches;
    }
778780
public function getOne($repository, $id)
    {
        $repoConfig = $this->repos[$repository];
        /** @var $q \Doctrine\ORM\QueryBuilder */
        return $this->doctrine
            ->getRepository($repoConfig['repository'])
            ->find($id);
    }
776974
public function matches($pattern, $translation = null)
	{
		return $this->pattern === $pattern and (!$translation or $translation === $this->translation);
	}
469776
public function insert(Repository $repository = null)
    {
        if (!$repository) {
            $repository = $this->getRepository();
        }

        $repository = $repository->aliased('write');

        $insert = $this->getQuery()->transformToInsert();

        $prepare = $repository->prepareQuery($insert);

        return $repository->executePrepared($prepare);
    }
585297
public function getRepositoryEntities($repository)
    {
        if (!isset($this->_repository_entities[$repository])) {
            $this->_repository_entities[$repository] =
                $this->getService('anahita:domain.entityset', array('repository' => $this));
        }

        return $this->_repository_entities[$repository];
    }
1257251
protected function getDatabaseTranslations(LocaleInterface $locale)
    {
        $messages   = [];
        $collection = $this->repository->matching(new Criteria());
        
        $collection->map(function (DictionaryInterface $dictionary) use ($locale, &$messages) {
            $messages[$dictionary->getIdentifier()] = $dictionary->translate($locale->getCode())->getValue();
        });
        
        return $messages;
    }