Finds all nodes an relations by search criteria.

@param array $criteria The search criteria.
@throws Exception If no criterion supplied.
@return ArrayCollection Collection of nodes or relations.
@api
174956
public function findBy(array $criteria)
    {
        //Make sure there is a criteria
        if(count($criteria) == 0)
        {
            throw new Exception("Please supply at least one criteria to findBy().");
        }

        $collection = new ArrayCollection();

        //If this repository is for a node
        if($this->meta instanceof Node)
        {
            $query = $this->createIndexQuery($criteria);

            foreach($this->getIndex()->query($query) as $node)
            {
                $collection->add($this->entityManager->loadNode($node));
            }
        }

        //Is a relation
        elseif($this->meta instanceof Relation)
        {
            //Array of different results
            $result_sets = array();

            //Criteria to use for query
            $query_criteria = array();

            //Generate the query criteria
            foreach($criteria as $k => $v)
            {
                $key = Meta\Reflection::normalizeProperty($k);

                //If it's the start or end
                if($key == $this->meta->getStart()->getName() || $key == $this->meta->getEnd()->getName())
                {
                    //Load relation by node (null if the property isn't a start/end)
                    $result_sets[] = $this->getRelationsByNode($key, $v);
                }

                //Regular property, add to query criteria to run later
                else
                {
                    $query_criteria[$k] = $v;
                }
            }

            //Do the query
            if(count($query_criteria) > 0)
            {
                $query = $this->createIndexQuery($query_criteria);
                $result_sets[] = $this->getIndex()->query($query);
            }

            //Intersect the 3 potential result sets (if they are there)
            $results = count($result_sets) > 1 ? call_user_func_array('array_intersect', $result_sets) : $result_sets[0];

            foreach($results as $rel)
            {
                $collection->add($this->entityManager->loadRelation($rel));
            }
        }

        return $collection;
    }
230733
public function sortBy($criteria)
    {
        $criteria = $this->factoryCallableCriteria($criteria);
        $sorted   = $this->create();
        $groups   = $this->groupBy($criteria);

        $criterias = $this->map(function ($element, $key) use ($criteria) {
            return $criteria($element, $key);
        })->toArray();

        sort($criterias);
        $criterias = array_unique($criterias);

        foreach ($criterias as $key) {
            foreach ($groups[$key] as $element) {
                $sorted[] = $element;
            }
        }

        return $sorted;
    }
1026570
public function searchOne(array $criterias = array())
    {
        $results = $this->search($criterias, 1);

        if (count($results) !== 1) {
            return null;
        }

        return $results[0];
    }
343446
public function search(array $criteria = array())
    {
        /** @var Statement $statement */
        /** @var Feature $feature */
        $maxResults      = isset($criteria['maxResults']) ? intval($criteria['maxResults']) : self::MAX_RESULTS;
        $intersect       = isset($criteria['intersectGeometry']) ? $criteria['intersectGeometry'] : null;
        $returnType      = isset($criteria['returnType']) ? $criteria['returnType'] : null;
        $srid            = isset($criteria['srid']) ? $criteria['srid'] : $this->getSrid();
        $where           = isset($criteria['where']) ? $criteria['where'] : null;
        $queryBuilder    = $this->getSelectQueryBuilder($srid);
        $connection      = $queryBuilder->getConnection();
        $whereConditions = array();

        // add GEOM where condition
        if ($intersect) {
            $geometry          = BaseDriver::roundGeometry($intersect, 2);
            $whereConditions[] = $this->getDriver()->getIntersectCondition($geometry, $this->geomField, $srid, $this->getSrid());
        }

        // add filter (https://trac.wheregroup.com/cp/issues/3733)
        if (!empty($this->sqlFilter)) {
            $securityContext   = $this->container->get("security.context");
            $user              = $securityContext->getUser();
            $sqlFilter         = strtr($this->sqlFilter, array(
                ':userName' => $user->getUsername()
            ));
            $whereConditions[] = $sqlFilter;

        }

        // add second filter (https://trac.wheregroup.com/cp/issues/4643)
        if ($where) {
            $whereConditions[] = $where;
        }

        if (isset($criteria["source"]) && isset($criteria["distance"])) {
            $whereConditions[] = "ST_DWithin(t." . $this->getGeomField() . ","
                . $connection->quote($criteria["source"])
                . "," . $criteria['distance'] . ')';
        }


        if (count($whereConditions)) {
            $queryBuilder->where(join(" AND ", $whereConditions));
        }

        $queryBuilder->setMaxResults($maxResults);

        // $queryBuilder->setParameters($params);
        // $sql = $queryBuilder->getSQL();

        $statement  = $queryBuilder->execute();
        $rows       = $statement->fetchAll();
        $hasResults = count($rows) > 0;

        // Convert to Feature object
        if ($hasResults) {
            $this->prepareResults($rows, $srid);
        }

        if ($returnType == "FeatureCollection") {
            $rows = $this->toFeatureCollection($rows);
        }

        return $rows;
    }
1174829
public static function query( ezpContentCriteria $criteria )
    {
        $fetchParams = self::translateFetchParams( $criteria );
        $nodes = eZContentObjectTreeNode::subTreeByNodeID( $fetchParams->params, $fetchParams->rootNodeId );
        $return = array();
        foreach( $nodes as $node )
        {
            $return[] = ezpContent::fromNode( $node );
        }
        return $return;
    }
802423
public function findBy(array $criteria, array $sorting = null, $limit = null, $offset = null)
    {
        $queryBuilder = $this->getCollectionQueryBuilder();

        $this->applyCriteria($queryBuilder, $criteria);
        $this->applySorting($queryBuilder, (array) $sorting);

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

        if (null !== $offset) {
            $queryBuilder->setFirstResult($offset);
        }

        $query = $queryBuilder->getQuery();

        if (null !== $limit) {
            return $this->collectionResult($query);
        }

        return $query->getResult();
    }
1358726
public function findOne(array $criteria = [])
    {
        $result = $this->search($criteria);

        if (count($result) > 0) {
            return $result[0];
        }

        return null;
    }
1199728
protected static function parseCriteria(array $criteria): array
    {
        $columns = [];
        $values = [];
        $options = ['order' => 'name'];

        // Find by source
        if ($criteria['source']) {
            $columns[] = 'source=?';
            $values[] = $criteria['source'];
        }

        // Find by alias
        if ($criteria['alias']) {
            $columns[] = 'alias=?';
            $values[] = $criteria['alias'];
        }

        // Find only the used tags
        if ($criteria['usedOnly']) {
            $ids = \Haste\Model\Model::getRelatedValues($criteria['sourceTable'], $criteria['sourceField']);

            if (\count($ids) < 1) {
                throw new NoTagsException();
            }

            $columns[] = 'id IN ('.\implode(',', \array_map('intval', \array_unique($ids))).')';
        }

        // Find the tags by values/IDs
        if (\is_array($criteria['values'])) {
            if (\count($criteria['values']) < 1) {
                throw new NoTagsException();
            }

            $columns[] = 'id IN ('.\implode(',', \array_map('intval', $criteria['values'])).')';
        }

        // Find the tags by aliases
        if (\is_array($criteria['aliases'])) {
            if (\count($criteria['aliases']) < 1) {
                throw new NoTagsException();
            }

            $columns[] = "alias IN ('".\implode("','", $criteria['values'])."')'";
        }

        return [$columns, $values, $options];
    }
72367
function criteria(array $criteria) {
		if ((list($left, $right) = each($criteria))) {
			$this->write("(");
			if (is_array($right)) {
				$this->criteria($right);
			} else {
				$this->write("(", $left, $this->param($right), ")");
			}
			while ((list($left, $right) = each($criteria))) {
				$this->write(is_int($left) && is_array($right) ? "OR" : "AND");
				if (is_array($right)) {
					$this->criteria($right);
				} else {
					$this->write("(", $left, $this->param($right), ")");
				}
			}
			$this->write(")");
		}
		return $this;
	}
149864
public static function count($criteria = array())
    {
        self::processCriteriaWithType($criteria);
        $count = self::connection()->count(self::collectionName(), $criteria);
        return $count;
    }
821144
public function addSearchCriteria(array $criteria)
    {
        $suffix = $this->getSuffix();
        foreach ($criteria as $crit => $value) {
            if (false === strpos($crit, '.')) {
                $crit = (true === in_array($crit, self::$joinCriteria) ? $this->getSectionAlias() : $this->getAlias()).'.'.$crit;
            }

            $param = str_replace('.', '_', $crit).$suffix;
            $this->andWhere($crit.' IN (:'.$param.')')
                    ->setParameter($param, $value);
        }

        return $this;
    }
333037
public function search(array $criteria = array())
    {
        $criteria['where'] = isset($criteria['where']) ? $criteria['where'] : '';
        if (isset($this->events[ self::EVENT_ON_BEFORE_SEARCH ])) {
            $this->secureEval($this->events[ self::EVENT_ON_BEFORE_SEARCH ], array(
                'criteria' => &$criteria
            ));
        }

        $results = $this->getDriver()->search($criteria);

        if (isset($this->events[ self::EVENT_ON_AFTER_SEARCH ])) {
            $this->secureEval($this->events[ self::EVENT_ON_AFTER_SEARCH ], array(
                'criteria' => &$criteria,
                'results' => &$results
            ));
        }

        return $results;
    }
418930
public function findBy(array $criteria = [], array $orders = [], $limit = null, $offset = null): array
    {
        $queryCriteria = Criteria::create();

        foreach ($criteria as $prop => $value) {
            $queryCriteria->andWhere(Criteria::expr()->eq($prop, $value));
        }

        $queryCriteria->orderBy($orders);

        if ($limit !== null) {
            $queryCriteria->setMaxResults($limit);
        }

        if ($offset !== null) {
            $queryCriteria->setFirstResult($offset);
        }

        return $this->matching($queryCriteria);
    }
36964
public function getChildren(Criteria $criteria = null, ConnectionInterface $con = null)
    {
        if (null === $this->collNestedSetChildren || null !== $criteria) {
            if ($this->isLeaf() || ($this->isNew() && null === $this->collNestedSetChildren)) {
                // return empty collection
                $this->initNestedSetChildren();
            } else {
                $collNestedSetChildren = ChildCategoryQuery::create(null, $criteria)
                    ->childrenOf($this)
                    ->orderByBranch()
                    ->find($con);
                if (null !== $criteria) {
                    return $collNestedSetChildren;
                }
                $this->collNestedSetChildren = $collNestedSetChildren;
            }
        }

        return $this->collNestedSetChildren;
    }
1116665
public function findOneOrNullBy(array $criteria)
    {

        $query = $this->createQueryBuilder($criteria);

        $object = $this->getOneOrNullResultFromQueryBuilder($query);

        return $object;
    }
1242178
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
    {
        $query = $this->createQueryBuilder($criteria, $orderBy, $limit, $offset);
        return $this->getResultFromQueryBuilder($query);
    }
1056924
protected function findUser(array $criteria)
    {
        if (null === $this->repository) {
            $this->repository = $this->em->getRepository($this->class);
        }

        return $this->repository->findOneBy($criteria);
    }