eZ\Publish\Core\Repository\SearchService::findContent PHP Method

findContent() public method

Finds content objects for the given query.
public findContent ( eZ\Publish\API\Repository\Values\Content\Query $query, array $languageFilter = [], boolean $filterOnUserPermissions = true ) : eZ\Publish\API\Repository\Values\Content\Search\SearchResult
$query eZ\Publish\API\Repository\Values\Content\Query
$languageFilter array Configuration for specifying prioritized languages query will be performed on. Currently supports: array("languages" => array(,..), "useAlwaysAvailable" => bool) useAlwaysAvailable defaults to true to avoid exceptions on missing translations.
$filterOnUserPermissions boolean if true only the objects which the user is allowed to read are returned.
return eZ\Publish\API\Repository\Values\Content\Search\SearchResult
    public function findContent(Query $query, array $languageFilter = array(), $filterOnUserPermissions = true)
    {
        $contentService = $this->repository->getContentService();
        $result = $this->internalFindContentInfo($query, $languageFilter, $filterOnUserPermissions);
        foreach ($result->searchHits as $hit) {
            // As we get ContentInfo from SPI, we need to load full content (avoids getting stale content data)
            $hit->valueObject = $contentService->internalLoadContent($hit->valueObject->id, !empty($languageFilter['languages']) ? $languageFilter['languages'] : null, null, false, isset($languageFilter['useAlwaysAvailable']) ? $languageFilter['useAlwaysAvailable'] : true);
        }
        return $result;
    }

Usage Example

 /**
  * Prepares content for ContentDataValue class.
  *
  * @param string $contentIdList
  * @param \Symfony\Component\HttpFoundation\Request $request
  *
  * @return \EzSystems\RecommendationBundle\Rest\Values\ContentData
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content, version with the given id and languages or content type does not exist
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the user has no access to read content and in case of un-published content: read versions
  */
 public function getContent($contentIdList, Request $request)
 {
     $contentIds = explode(',', $contentIdList);
     $lang = $request->get('lang');
     $criteria = array(new Criterion\ContentId($contentIds));
     if (!$request->get('hidden')) {
         $criteria[] = new Criterion\Visibility(Criterion\Visibility::VISIBLE);
     }
     if ($lang) {
         $criteria[] = new Criterion\LanguageCode($lang);
     }
     $query = new Query();
     $query->query = new Criterion\LogicalAnd($criteria);
     $contentItems = $this->searchService->findContent($query)->searchHits;
     $data = $this->prepareContent($contentItems, $request);
     return new ContentDataValue($data);
 }
All Usage Examples Of eZ\Publish\Core\Repository\SearchService::findContent