Finds documents by a set of criteria.

@param int|null $limit
@param int|null $skip
164370
public function findBy(array $criteria, ?array $sort = null, $limit = null, $skip = null) : array
    {
        return $this->getDocumentPersister()->loadAll($criteria, $sort, $limit, $skip)->toArray();
    }
1029925
public function find($limit = 20, $offset = 0)
	{
		return $this->buildFind()
			->setLimit($limit)
			->setOffset($offset)
			->find();
	}
47142
public function read ($limit = 0, $query = NULL, $view = NULL, $sort = NULL, $options = NULL) {
		return $this->api->read($this->list_name, $limit, $query, $view, $sort, $options);
	}
630641
private function runQuery(Collection $collection, int $offset, int $limit): Iterator
    {
        $collectionQuery = $collection->getQuery();
        if (!$collectionQuery instanceof Query) {
            return new ArrayIterator();
        }

        $queryOffset = $offset - $this->getManualItemsCount($collection, 0, $offset);
        $queryLimit = $limit - $this->getManualItemsCount($collection, $offset, $offset + $limit);

        return $this->queryRunner->runQuery($collectionQuery, $queryOffset, $queryLimit);
    }
539688
public function allDocs($limit = null, $startKey = null, $endKey = null, $skip = null, $descending = false)
    {
        $allDocsPath = '/'.$this->databaseName.'/_all_docs?include_docs=true';
        if ($limit) {
            $allDocsPath .= '&limit='.(int) $limit;
        }
        if ($startKey) {
            $allDocsPath .= '&startkey="'.(string) $startKey.'"';
        }
        if (!is_null($endKey)) {
            $allDocsPath .= '&endkey="'.(string) $endKey.'"';
        }
        if (!is_null($skip) && (int) $skip > 0) {
            $allDocsPath .= '&skip='.(int) $skip;
        }
        if (!is_null($descending) && (bool) $descending === true) {
            $allDocsPath .= '&descending=true';
        }

        return $this->httpClient->request('GET', $allDocsPath);
    }
1185792
public function count(
        $query = [],
        $limit = null,
        $skip = null,
        $timeout = 2000
    ) {
        $this->getContext()->getLog()->profileStart($this->profileName . __FUNCTION__);
        $options = [
            'socketTimeoutMS' => $timeout
        ];
        if (!is_null($limit)) {
            $options['limit'] = $limit;
        }
        if (!is_null($skip)) {
            $options['skip'] = $skip;
        }
        $out = $this->mongoCollection->count($query, $options);
        if ($out === null) {
            return 0;
        }
        $this->getContext()->getLog()->profileEnd($this->profileName . __FUNCTION__);

        return $out;
    }
216990
public function findLimited($limit = 0)
    {
        $queryBuilder = $this->createQueryBuilder('c')
            ->where('c.enabled = :enabled')
            ->orderBy('c.position')
            ->setParameters(array(
                'enabled' => true,
            ));

        if ($limit != 0) {
            $queryBuilder->setMaxResults($limit);
        }

        return $queryBuilder->getQuery()->getResult();
    }
1269445
public function find($criteria = null) {
		if ($criteria !== null) {
			trigger_error('Attempts to set criteria are vain for the File datagate');
		}
		
		$fileIterator = new FileIterator(
			$this->getFile(),
			$this->delimiter,
			$this->partsNames
		);
		
		return $this->createResultset($fileIterator);
	}
759732
public function find(array $criteria = [], array $orderBy = null, $limit = null, $offset = null)
    {
        // @todo implement these
        if ($orderBy !== null || $limit !== null || $offset !== null) {
            throw new \Exception('orderBy, limit and offset not yet implemented');
        }

        if (empty($criteria)) {
            return $this->getConfigs();
        }

        return $this->search($criteria);
    }
165180
public function find($query, $sort = array(), $skip = 0, $limit = 0, $fields = array())
    {
        $cursor = $this->collection->find($query, $fields);
        $count = $cursor->count();
        if (empty($count)) {
            return array();
        }
        if ($sort) $cursor->sort($sort);
        if ($skip) $cursor->skip($skip);
        if ($limit) $cursor->limit($limit);
        return iterator_to_array($cursor);
    }
298767
public function findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null): array
    {
        $table = $this->getTable();

        $this->logger->info(
            'model: find rows within table {table} with criteria {criteria}',
            ['table' => $table, 'criteria' => $criteria, 'orderBy' => $orderBy, 'limit' => $limit, 'offset' => $offset]
        );

        $qb = $this->connection->createQueryBuilder()
            ->select('*')
            ->from($table)
            ->setFirstResult($offset)
            ->setMaxResults($limit)
        ;

        $this->addCriteriaToQueryBuilder($qb, $criteria);
        $this->addOrderByToQueryBuilder($qb, $orderBy);

        $rows = $qb->execute()->fetchAll(\PDO::FETCH_ASSOC);

        if ([] === $rows) {
            return [];
        }

        $models = [];
        foreach ($rows as $row) {
            $this->storageCache->set($row['id'], $row);

            $models[] = $this->fromPersistence($row);
        }

        return $models;
    }
1006194
public function findAllWithPagination($filters, $limit, $offset, $resultInArray = FALSE)
    {
        $where = $this->getQueryFilter($filters);
        $query = $this->getEntityManager()->createQuery('SELECT m FROM FulgurioLightCMSBundle:Media m ' . $where . ' ORDER BY m.created_at DESC')->setMaxResults($limit)->setFirstResult($offset);
        if (!empty($filters))
        {
            foreach ($filters as $filterKey => $filterValue)
            {
                $query->setParameter($filterKey, $filterValue);
            }
        }
        if ($resultInArray)
        {
            return $query->getArrayResult();
        }
        return $query->getResult();
    }
630554
public function getQueryResults($limit = null)
    {
        if (isset($limit)) {
            $this->queryBuilder->setMaxResults($limit);
        }
        
        if (!$this->queryBuilder->getDQLPart('orderBy')) {
            $this->queryBuilder->orderBy('a.createdAt', 'ASC');
        }

        return $this->queryBuilder->getQuery()->getResult();
    }
1255871
public function findNews($family, $limit = null)
    {
        $qb = $this->getQueryBuilder()
            ->orderBy('p.highlighted', 'desc')
            ->addOrderBy('p.createdAt', 'desc');

        // filter by family
        if (!is_null($family)) {
            $qb->innerJoin('p.category', 'c')
                ->innerJoin('c.parentCategory', 'pc')
                ->andWhere('pc.family = :family')
                ->setParameter('family', $family);
        }

        if (!is_null($limit)) {
            $qb->setMaxResults($limit);
        }

        return $qb->getQuery()
            ->getResult();
    }
486977
public final function findAll($query = null, array $queryParams = null, $limit = null): EntityCollection
    {
        $queryBuilder = new QueryBuilder($this->db->getLink());
        $queryBuilder->setTable($this->table);

        $queryBuilder->select("{$this->table}.*");

        if (method_exists($this, 'onFind')) {
            $queryBuilder = $this->onFind($queryBuilder);
            if (!$queryBuilder || !($queryBuilder instanceof QueryBuilder)) {
                throw new InvalidValueException('You should return query builder back from onFind()!');
            }
        }

        $isEmptyQuery = empty($query);
        $isEmptyQueryParams = empty($queryParams);

        // fetch all rows, oh ohh..
        // e.g: findAll()
        if ($isEmptyQuery) {
            // nothing to do..
        }
        // fetch all rows by primary key with given params
        // e.g: findAll([1,2,3])
        elseif (!$isEmptyQuery && $isEmptyQueryParams) {
            $queryBuilder->where("{$this->table}.{$this->tablePrimary} IN(?)", [$query]);
        }
        // fetch all rows with given params and params
        // e.g: findAll('id IN (?)', [[1,2,3]])
        // e.g: findAll('id IN (?,?,?)', [1,2,3])
        elseif (!$isEmptyQuery && !$isEmptyQueryParams) {
            // now, it is user's responsibility to append table(s) before field(s)
            $queryBuilder->where($query, $queryParams);
        }

        @ [$limitStart, $limitStop] = (array) $limit;
        if ($limitStart !== null) {
            $queryBuilder->limit((int) $limitStart, $limitStop);
        }

        $hasOnEntity = method_exists($this, 'onEntity');

        $entityCollection = new EntityCollection();
        foreach ($queryBuilder->run() as $result) {
            $entity = new Entity($this, (array) $result);
            if ($hasOnEntity) {
                $this->onEntity($entity);
            }
            $entityCollection->addEntity($entity);
        }

        return $entityCollection;
    }
631416
final public function limit($limit,$offset=null) {
      if (is_numeric($limit) || is_array($limit)) {
         if(is_array($limit)) {
            $temp   = $limit;
            $limit  =  $temp[0];
            $offset = @$temp[1];
         }

         $this->limit = " LIMIT {$limit} ";

         if(is_numeric($offset)) {
            $this->offset( $offset );
         }
         $this->find_first_data = $this->find_save_data = $this->find_delete_data = FALSE;

         $this->get_instance();
         return $this;
      }

      return null;
   }
964700
public function search(SearchCriteria $criteria, $limit = null, $offset = 0)
    {
        $actor = $criteria->actor;

        $query = $this->pages->query();

        if ($actor !== null && !$actor->isAdmin()) {
            $query->whereIsHidden(0);
        }

        $search = new PageSearch($query->getQuery(), $actor);

        $this->gambits->apply($search, $criteria->query);
        $this->applySort($search, $criteria->sort);
        $this->applyOffset($search, $offset);
        $this->applyLimit($search, $limit + 1);

        $pages = $query->get();

        if ($areMoreResults = ($limit > 0 && $pages->count() > $limit)) {
            $pages->pop();
        }

        return new SearchResults($pages, $areMoreResults);
    }