/**
     * Finds Locations for the given query.
     *
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid
     *
     * @param \eZ\Publish\API\Repository\Values\Content\LocationQuery $query
     * @param boolean $filterOnUserPermissions if true only the objects which is the user allowed to read are returned.
     *
     * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult
     */
    public function findLocations( LocationQuery $query, $filterOnUserPermissions = true )
    {
        $query = clone $query;
        $query->filter = $query->filter ?: new Criterion\MatchAll();

        $this->validateSortClauses( $query );

        if ( $filterOnUserPermissions && !$this->permissionsCriterionHandler->addPermissionsCriterion( $query->filter ) )
        {
            return new SearchResult( array( 'time' => 0, 'totalCount' => 0 ) );
        }

        if ( $query->limit === null )
        {
            $query->limit = self::MAX_LIMIT;
        }

        $result = $this->locationSearchHandler->findLocations( $query );

        foreach ( $result->searchHits as $hit )
        {
            $hit->valueObject = $this->domainMapper->buildLocationDomainObject(
                $hit->valueObject
            );
        }

        return $result;
    }
 /**
  * Finds Locations for the given query.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid
  *
  * @param \eZ\Publish\API\Repository\Values\Content\LocationQuery $query
  * @param array $fieldFilters - a map of filters for the returned fields.
  *        Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code>
  *                            useAlwaysAvailable defaults to true to avoid exceptions on missing translations
  * @param bool $filterOnUserPermissions if true only the objects which is the user allowed to read are returned.
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult
  */
 public function findLocations(LocationQuery $query, array $fieldFilters = array(), $filterOnUserPermissions = true)
 {
     if (!is_int($query->offset)) {
         throw new InvalidArgumentType("\$query->offset", 'integer', $query->offset);
     }
     if (!is_int($query->limit)) {
         throw new InvalidArgumentType("\$query->limit", 'integer', $query->limit);
     }
     $query = clone $query;
     $query->filter = $query->filter ?: new Criterion\MatchAll();
     $this->validateSortClauses($query);
     if ($filterOnUserPermissions && !$this->permissionsCriterionHandler->addPermissionsCriterion($query->filter)) {
         return new SearchResult(array('time' => 0, 'totalCount' => 0));
     }
     $result = $this->locationSearchHandler->findLocations($query, $fieldFilters);
     foreach ($result->searchHits as $hit) {
         $hit->valueObject = $this->domainMapper->buildLocationDomainObject($hit->valueObject);
     }
     return $result;
 }