Search if a defined number of Groups exists.

@param string $search
@param string $by
@param int    $num
@param int    $page
@param int    $limit

@return mixed
490847
public function searchGroups($search, $by, $limit = 1, $num = 1000, $page = 1)
    {
        $groups = $this->indexGroups($num, $page)['data'];

        $filtered = array_filter(
            $groups,
            function ($group) use ($search, $by) {

                if (array_key_exists($by, $group)) {
                    if (strpos($group[$by], $search) !== false) {
                        return $group;
                    }
                    if ($group[$by] === $search) {
                        return $group;
                    }
                }

                return false;
            }
        );

        if ($limit == 1) {
            return array_shift($filtered);
        }

        return array_slice($filtered, 0, $limit);
    }
1252769
public function getGroups($page, $max = 50, $orderedBy = 'id', $order = null)
    {
        $query = $this->groupRepo->findAll(false, $orderedBy, $order);

        return $this->pagerFactory->createPager($query, $page, $max);
    }
280775
public function findFirstGroupsByName($search)
    {
        return $this->_em->createQueryBuilder()
            ->select('g.id, g.name')
            ->from('ClarolineCoreBundle:Group', 'g')
            ->where('g.name LIKE :search')
            ->setMaxResults(5)
            ->setParameter(':search', "%{$search}%")
            ->getQuery()
            ->getArrayResult();
    }
1057677
public function search($search_text, $page = 0) {
        global $SESSION;
        $sort = optional_param('youtube_sort', '', PARAM_TEXT);
        $sess_keyword = 'youtube_'.$this->id.'_keyword';
        $sess_sort = 'youtube_'.$this->id.'_sort';

        // This is the request of another page for the last search, retrieve the cached keyword and sort
        if ($page && !$search_text && isset($SESSION->{$sess_keyword})) {
            $search_text = $SESSION->{$sess_keyword};
        }
        if ($page && !$sort && isset($SESSION->{$sess_sort})) {
            $sort = $SESSION->{$sess_sort};
        }
        if (!$sort) {
            $sort = 'relevance'; // default
        }

        // Save this search in session
        $SESSION->{$sess_keyword} = $search_text;
        $SESSION->{$sess_sort} = $sort;

        $this->keyword = $search_text;
        $ret  = array();
        $ret['nologin'] = true;
        $ret['page'] = (int)$page;
        if ($ret['page'] < 1) {
            $ret['page'] = 1;
        }
        $start = ($ret['page'] - 1) * self::YOUTUBE_THUMBS_PER_PAGE + 1;
        $max = self::YOUTUBE_THUMBS_PER_PAGE;
        $ret['list'] = $this->_get_collection($search_text, $start, $max, $sort);
        $ret['norefresh'] = true;
        $ret['nosearch'] = true;
        // If the number of results is smaller than $max, it means we reached the last page.
        $ret['pages'] = (count($ret['list']) < $max) ? $ret['page'] : -1;
        return $ret;
    }
902404
public function getPagedResults($limit = 50, $page = 0): Paginator
    {
        $dql = sprintf(self::DQL_GET_PAGED, TargetTemplate::class);
        return $this->getPaginator($dql, $limit, $page);
    }
529735
private static function getNumPages(int $limit, int $count): int
    {
        return (int) ceil($count / $limit);
    }
449622
public function get(int $page, int $limit = 10): \Illuminate\Pagination\LengthAwarePaginator
    {
        if (!$this->_columns && !$this->_query) {
            return null;
        }
        $countTotal = $this->_query->count();
        $this->_query->skip(($limit * $page) - $limit);
        $this->_query->limit($limit);
        $data = collect();
        foreach ($this->_query->get() as $key => $instance) {
            if ($instance instanceof \Illuminate\Database\Eloquent\Model) {
                $_listRow = [];
                foreach ($this->_columns->getColumns() as $column) {
                    $_listRow[$column->getKey()] = $column->getValues($instance);
                }
                $buttons = $this->_columns->filterActions($instance);
                if (count($buttons)) {
                    $_listRow = array_merge($_listRow, [Column::ACTION_NAME => implode('', $buttons)]);
                }
                $data->offsetSet($key, $_listRow);
            }
        }
        $this->_data = new \Illuminate\Pagination\LengthAwarePaginator($data, $countTotal, $limit, $page, [
            'path'     => \Illuminate\Pagination\Paginator::resolveCurrentPath(),
            'pageName' => 'page',
        ]);

        return $this->_data;
    }
774504
public function usersGroups($page = null, $limit = null)
    {
        $parameters = [];

        if (null !== $page) {
            $parameters['page'] = (int)$page;
        }
        if (null !== $limit) {
            $parameters['limit'] = (int)$limit;
        }

        /** @noinspection PhpUndefinedMethodInspection */
        return $this->client->makeRequest(
            '/user-groups',
            "GET",
            $parameters
        );
    }
896165
public function getAll(int $page = 1, int $limit = 25)
    {
        return $this->match(new Criteria([], [], ($page - 1) * $limit, $limit));
    }
542005
public function getPagedResults($limit = 25, $page = 0)
    {
        $template = self::DQL_ALL;
        $dql = sprintf($template, UserPermission::class, User::class);

        return $this->getPaginator($dql, $limit, $page, []);
    }
1104313
public static function search(
        Client $client,
        array $tags,
        int $page,
        int $limit = 20
    ): array {
        if (!self::isValidPageNumber($page)) {
            throw new InvalidArgumentException('Page number should be greater than zero');
        }

        if (!self::isValidLimitation($page)) {
            throw new InvalidArgumentException('Limit should be greater than zero');
        }

        $query = [
            'page' => $page,
            'limit' => $limit,
            'tags' => implode(',', $tags),
        ];

        $postsAsArrays = $client->sendRequest(
            self::ENDPOINT,
            $query
        );

        return array_map(function (array $post) use ($client): self {
            return self::fromArray($client, $post);
        }, $postsAsArrays);
    }
1054075
public function limitLinkSearch($search, $wp_query)
    {
        global $wpdb;

        if (empty($search)) {
            return $search;
        }

        $query_vars = $wp_query->query_vars;
        $search = '';
        $and = '';

        foreach((array)$query_vars['search_terms'] as $term) {
            $search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$wpdb->esc_like($term)}%'))";
            $and = ' AND ';
        }

        $search = (!empty($search)) ? " AND ({$search}) " : $search;

        return $search;
    }
405015
public function getWorkspaceByName(
        $search,
        $page,
        $max = 20,
        $orderedBy = 'id',
        $order = 'ASC'
    )
    {
        $query = $this->workspaceRepo->findByName($search, false, $orderedBy, $order);

        return $this->pagerFactory->createPager($query, $page, $max);
    }
1008153
public function search(
        Search $data,
        $limit = 0,
        $offset = 0,
        $sort_column = self::DEFAULT_SORT_COLUMN,
        $sort_direction = self::DEFAULT_SORT_DIRECTION
    ) {
        return $this->driver->search(
            $data,
            ($limit > 0 ? (int) $limit : 0),
            ($offset > 0 ? (int) $offset : 0),
            $this->getValidSortColumn($sort_column),
            $this->getValidSortDirection($sort_direction)
        );
    }
976499
public function getByPage($page = 1, $limit = 10, $with = array())
    {
        $result = new StdClass;
        $result->page = $page;
        $result->limit = $limit;
        $result->totalItems = 0;
        $result->items = array();

        $query = $this->make($with);
        $users = $query->skip($limit * ($page - 1))
            ->take($limit)
            ->get();
        $result->totalItems = $this->model->count();
        $result->items = $users->all();

        return $result;
    }
167734
public function paginate($limit = 25, $page = 0)
    {
        if ($limit > 0) {
            $this->queryBuilder->setMaxResults($limit);
        }

        if ($page > 0) {
            $this->queryBuilder->setFirstResult($page * $limit);
        }

        return $this;
    }
506261
public function searchComponents($search, $by, $limit = 1, $num = 1000, $page = 1)
    {
        $components = $this->indexComponents($num, $page)['data'];

        $filtered = array_filter(
            $components,
            function ($component) use ($search, $by) {

                if (array_key_exists($by, $component)) {
                    if (strpos($component[$by], $search) !== false) {
                        return $component;
                    }
                    if ($component[$by] === $search) {
                        return $component;
                    }
                }

                return false;
            }
        );

        if ($limit == 1) {
            return array_shift($filtered);
        }

        return array_slice($filtered, 0, $limit);
    }