list most popular search queries based on searchCount

@param int $max

@return \Symfony\Component\HttpFoundation\Response
482217
public function listMostPopularAction($max = 3)
    {
        $queries = $this->getSearchRepository()->retrieveMostPopular($max);

        return $this->render(
            'GenjFaqBundle:Search:list_most_popular.html.twig',
            array(
                'queries' => $queries,
                'max'     => $max
            )
        );
    }
215093
public function countByScore($min, $max){
        return $this->getConnection()->getSlave()->zCount($this->name, $min, $max);
    }
1168909
public function search(string $query, $limit = 30, $start = 0, $sort = null)
    {
        if ($query == '*.*' && $limit == 30 && $start == 0 && $sort == 'lastupdated desc') {
            $result = $this->fetchFromCache();

            if (null === $result) {
                $result = $this->search->search($query, $limit, $start, $sort);
                $this->saveToCache($result);
            }

            return $result;
        } else {
            return $this->search->search($query, $limit, $start, $sort);
        }
    }
405639
private function _get_collection($keyword, $start, $max, $sort) {
        global $SESSION;

        // The new API doesn't use "page" numbers for browsing through results.
        // It uses a prev and next token in each set that you need to use to
        // request the next page of results.
        $sesspagetoken = 'youtube_'.$this->id.'_nextpagetoken';
        $pagetoken = '';
        if ($start > 1 && isset($SESSION->{$sesspagetoken})) {
            $pagetoken = $SESSION->{$sesspagetoken};
        }

        $list = array();
        $error = null;
        try {
            $this->init_youtube_service(); // About to use the service, ensure it's loaded.
            $response = $this->service->search->listSearch('id,snippet', array(
                'q' => $keyword,
                'maxResults' => $max,
                'order' => $sort,
                'pageToken' => $pagetoken,
                'type' => 'video',
                'videoEmbeddable' => 'true',
            ));

            // Track the next page token for the next request (when a user
            // scrolls down in the file picker for more videos).
            $SESSION->{$sesspagetoken} = $response['nextPageToken'];

            foreach ($response['items'] as $result) {
                $title = $result->snippet->title;
                $source = 'http://www.youtube.com/v/' . $result->id->videoId . '#' . $title;
                $thumb = $result->snippet->getThumbnails()->getDefault();

                $list[] = array(
                    'shorttitle' => $title,
                    'thumbnail_title' => $result->snippet->description,
                    'title' => $title.'.avi', // This is a hack so we accept this file by extension.
                    'thumbnail' => $thumb->url,
                    'thumbnail_width' => (int)$thumb->width,
                    'thumbnail_height' => (int)$thumb->height,
                    'size' => '',
                    'date' => '',
                    'source' => $source,
                );
            }
        } catch (Google_Service_Exception $e) {
            // If we throw the google exception as-is, we may expose the apikey
            // to end users. The full message in the google exception includes
            // the apikey param, so we take just the part pertaining to the
            // actual error.
            $error = $e->getErrors()[0]['message'];
            throw new moodle_exception('apierror', 'repository_youtube', '', $error);
        }

        return $list;
    }
565383
public function sqlHelper($maximumQueryCount = null)
    {
        $sqlHelper = SqlHelper::instantiate($this);

        if (!is_null($maximumQueryCount)) {
            $sqlHelper->setMaximumQueryCount($maximumQueryCount);
        }

        return $sqlHelper;
    }
1024986
public function findUsersOwnersOfMostWorkspaces($max)
    {
        $dql = "
            SELECT CONCAT(CONCAT(u.firstName,' '), u.lastName) AS name, u.username, COUNT(DISTINCT ws.id) AS total
            FROM Claroline\CoreBundle\Entity\Workspace\Workspace ws
            JOIN ws.creator u
            WHERE u.isEnabled = true
            GROUP BY u.id
            ORDER BY total DESC
        ";
        $query = $this->_em->createQuery($dql);

        if ($max > 1) {
            $query->setMaxResults($max);
        }

        return $query->getResult();
    }
688332
public function getTopHunterEntityData($limit = 10)
    {
        $topHunter = $this->gameDataService->getTopJobCharacter(3);

        return $topHunter->setMaxResults($limit)
            ->getQuery()
            ->getResult();
    }
869739
public function findWorkspacesWithMostResources($max, $organizations = null)
    {
        $qb = $this
            ->createQueryBuilder('ws')
            ->select('ws.name, ws.code, COUNT(rs.id) AS total')
            ->leftJoin('Claroline\CoreBundle\Entity\Resource\ResourceNode', 'rs', 'WITH', 'ws = rs.workspace')
            ->groupBy('ws.id')
            ->orderBy('total', 'DESC');

        if (null !== $organizations) {
            $qb->leftJoin('ws.organizations', 'orgas')
                ->andWhere('orgas IN (:organizations)')
                ->setParameter('organizations', $organizations);
        }

        if ($max > 1) {
            $qb->setMaxResults($max);
        }

        return $qb->getQuery()->getResult();
    }
278284
public function getLimit($max = null)
    {
        $limit = $this->getPage('limit') ?: $this->getPage('size') ?: null;

        if ($limit && $max) {
            $limit = min($max, $limit);
        }

        return $limit;
    }
1115745
public function getAllUsers($page, $max = 20, $orderedBy = 'id', $order = null)
    {
        $query = $this->userRepo->findAll(false, $orderedBy, $order);

        return $this->pagerFactory->createPager($query, $page, $max);
    }
600761
public function listAction()
    {
        $page = $this->getRequest()->getQuery('page', 0);
        $limit = $this->getRequest()->getQuery('limit', $this->defaultPageSize);
        $sort = $this->getRequest()->getQuery('sort', $this->defaultSort);
        $order = $this->getRequest()->getQuery('order', $this->defaultOrder);

        if (empty($sort)) {
            $sort = $this->defaultSort;
        }

        $offset = $limit * $page - $limit;
        if ($offset < 0) {
            $offset = 0;
        }

        /* @var $qb \Doctrine\ODM\MongoDB\Query\Builder */
        $qb = $this->getDocumentManager()->createQueryBuilder($this->getDocumentClass());
        $qb->select()
        ->sort($sort, $order)
        ->limit($limit)
        ->skip($offset);

        $this->handleSearch($qb);

        $paginator = new Paginator(new DoctrinePaginator($qb->getQuery()->execute()));
        $paginator->setDefaultItemCountPerPage($limit);
        $paginator->setCurrentPageNumber($page);
        $paginator->setPageRange($this->paginatorRange);

        return [
            'paginator' => $paginator,
            'sort' => $sort,
            'order' => $order,
            'page' => $page,
            'query' => $this->params()->fromQuery(),
        ];
    }
60092
public function setMaxQueryTime($max)
    {
        assert(is_int($max));
        assert($max >= 0);
        $this->_maxquerytime = $max;

        return $this;
    }
614552
public function getUsersByName($search, $page, $max = 20, $orderedBy = 'id')
    {
        $query = $this->userRepo->findByName($search, false, $orderedBy);

        return $this->pagerFactory->createPager($query, $page, $max);
    }
1016900
public function getTopThievesEntityData($limit = 10)
    {
        $topThieves = $this->gameDataService->getTopJobCharacter(2);

        return $topThieves->setMaxResults($limit)
            ->getQuery()
            ->getResult();
    }
1230614
public function listAction(Request $request)
    {
        $limit = $request->get('limit', 25);
        $start = $request->get('start', 0);
        $sort = $request->get('sort', 'createdAt');
        $dir = $request->get('dir', 'DESC');
        $filter = $request->get('filter', null);

        if ($filter) {
            $filter = json_decode($filter, true);
        }

        if (!is_array($filter)) {
            $filter = [];
        }

        $messageManager = $this->get('phlexible_message.message_manager');

        $priorityList = $messageManager->getPriorityNames();
        $typeList = $messageManager->getTypeNames();

        $priorityFilter = [];
        $typeFilter = [];
        $channelFilter = [];
        $roleFilter = [];

        $criteria = new Criteria();
        foreach ($filter as $key => $value) {
            if ($key === 'subject' && !empty($value)) {
                $criteria->addRaw(Criteria::CRITERIUM_SUBJECT_LIKE, $value);
            } elseif ($key === 'text' && !empty($value)) {
                $criteria->addRaw(Criteria::CRITERIUM_BODY_LIKE, $value);
            } elseif (substr($key, 0, 9) === 'priority_') {
                $priorityFilter[] = substr($key, 9);
            } elseif (substr($key, 0, 5) === 'type_') {
                $typeFilter[] = substr($key, 5);
            } elseif (substr($key, 0, 8) === 'channel_') {
                $channelFilter[] = substr($key, 8);
            } elseif (substr($key, 0, 5) === 'role_') {
                $roleFilter[] = substr($key, 9);
            } elseif ($key === 'date_after' && !empty($value)) {
                $criteria->addRaw(Criteria::CRITERIUM_START_DATE, $value);
            } elseif ($key === 'date_before' && !empty($value)) {
                $criteria->addRaw(Criteria::CRITERIUM_END_DATE, $value);
            }
        }

        if (count($priorityFilter)) {
            $criteria->addRaw(
                Criteria::CRITERIUM_PRIORITY_IN,
                implode(',', $priorityFilter)
            );
        }

        if (count($typeFilter)) {
            $criteria->addRaw(
                Criteria::CRITERIUM_TYPE_IN,
                implode(',', $typeFilter)
            );
        }

        if (count($channelFilter)) {
            $criteria->addRaw(
                Criteria::CRITERIUM_CHANNEL_IN,
                implode(',', $channelFilter)
            );
        }

        if (count($roleFilter)) {
            $criteria->addRaw(
                Criteria::CRITERIUM_ROLE_IN,
                implode(',', $roleFilter)
            );
        }

        $count = $messageManager->countByCriteria($criteria);
        $messages = $messageManager->findByCriteria($criteria, [$sort => $dir], $limit, $start);

        $data = [];
        foreach ($messages as $message) {
            $data[] = [
                'subject' => $message->getSubject(),
                'body' => nl2br($message->getBody()),
                'priority' => $priorityList[$message->getPriority()],
                'type' => $typeList[$message->getType()],
                'channel' => $message->getChannel(),
                'role' => $message->getRole(),
                'user' => $message->getUser(),
                'createdAt' => $message->getCreatedAt()->format('Y-m-d H:i:s'),
            ];
        }

        return new JsonResponse([
            'totalCount' => $count,
            'messages' => $data,
            'facets' => $messageManager->getFacetsByCriteria($criteria),
        ]);
    }
264691
public function show()
    {
        $keyword  = request('q');
        $articles = [];
        $limit    = abs(request('limit', config('site.limit', 10)));

        $max_limit = config('site.max_limit', 100);
        if ($limit > $max_limit) {
            $limit = $max_limit;
        }

        if ($keyword) {
            $articles = $this->engine->search($keyword, $limit);
            $articles->appends('q', $keyword);
            $articles->appends('limit', $limit);
        }

        return view('search.show', compact('articles', 'keyword'));
    }
1327499
public function findAllPaginated($offset = null, $limit = null)
    {
        $qb = $this
            ->createQueryBuilder('w')
            ->orderBy('w.id')
            ->setMaxResults($limit);
        if ($offset) {
            $qb->setFirstResult($offset);
        }

        return $qb->getQuery()->getResult();
    }