public function buildContentDomainObjectsOnSearchResult(SearchResult $result, array $languageFilter)
    {
        if (empty($result->searchHits)) {
            return [];
        }

        $contentIds = [];
        $contentTypeIds = [];
        $translations = $languageFilter['languages'] ?? [];
        $useAlwaysAvailable = $languageFilter['useAlwaysAvailable'] ?? true;
        foreach ($result->searchHits as $hit) {
            /** @var \eZ\Publish\SPI\Persistence\Content\ContentInfo $info */
            $info = $hit->valueObject;
            $contentIds[] = $info->id;
            $contentTypeIds[] = $info->contentTypeId;
            // Unless we are told to load all languages, we add main language to translations so they are loaded too
            // Might in some case load more languages then intended, but prioritised handling will pick right one
            if (!empty($languageFilter['languages']) && $useAlwaysAvailable && $info->alwaysAvailable) {
                $translations[] = $info->mainLanguageCode;
            }
        }

        $missingContentList = [];
        $contentList = $this->contentHandler->loadContentList($contentIds, array_unique($translations));
        $contentTypeList = $this->contentTypeHandler->loadContentTypeList(array_unique($contentTypeIds));
        foreach ($result->searchHits as $key => $hit) {
            if (isset($contentList[$hit->valueObject->id])) {
                $hit->valueObject = $this->buildContentDomainObject(
                    $contentList[$hit->valueObject->id],
                    $this->contentTypeDomainMapper->buildContentTypeDomainObject(
                        $contentTypeList[$hit->valueObject->contentTypeId],
                        $languageFilter['languages'] ?? []
                    ),
                    $languageFilter['languages'] ?? [],
                    $useAlwaysAvailable ? $hit->valueObject->mainLanguageCode : null
                );
            } else {
                $missingContentList[] = $hit->valueObject;
                unset($result->searchHits[$key]);
                --$result->totalCount;
            }
        }

        return $missingContentList;
    }
public function buildContentDomainObjectsOnSearchResult(SearchResult $result, array $languageFilter)
    {
        if (empty($result->searchHits)) {
            return [];
        }

        $contentIds = [];
        $contentTypeIds = [];
        $translations = $languageFilter['languages'] ?? [];
        $useAlwaysAvailable = $languageFilter['useAlwaysAvailable'] ?? true;
        foreach ($result->searchHits as $hit) {
            /** @var \eZ\Publish\SPI\Persistence\Content\ContentInfo $info */
            $info = $hit->valueObject;
            $contentIds[] = $info->id;
            $contentTypeIds[] = $info->contentTypeId;
            // Unless we are told to load all languages, we add main language to translations so they are loaded too
            // Might in some case load more languages then intended, but prioritised handling will pick right one
            if (!empty($languageFilter['languages']) && $useAlwaysAvailable && $info->alwaysAvailable) {
                $translations[] = $info->mainLanguageCode;
            }
        }

        $missingContentList = [];
        $contentList = $this->contentHandler->loadContentList($contentIds, array_unique($translations));
        $contentTypeList = $this->contentTypeHandler->loadContentTypeList(array_unique($contentTypeIds));
        foreach ($result->searchHits as $key => $hit) {
            if (isset($contentList[$hit->valueObject->id])) {
                $hit->valueObject = $this->buildContentDomainObject(
                    $contentList[$hit->valueObject->id],
                    $this->contentTypeDomainMapper->buildContentTypeDomainObject(
                        $contentTypeList[$hit->valueObject->contentTypeId],
                        $languageFilter['languages'] ?? []
                    ),
                    $languageFilter['languages'] ?? [],
                    $useAlwaysAvailable ? $hit->valueObject->mainLanguageCode : null
                );
            } else {
                $missingContentList[] = $hit->valueObject;
                unset($result->searchHits[$key]);
                --$result->totalCount;
            }
        }

        return $missingContentList;
    }
public function buildContentDomainObjectsOnSearchResult ( SearchResult $ result , array $ languageFilter ) { if ( empty ( $ result -> searchHits ) ) { return [ ] ; } $ contentIds = [ ] ; $ contentTypeIds = [ ] ; $ translations = $ languageFilter [ 'languages' ] ?? [ ] ; $ useAlwaysAvailable = $ languageFilter [ 'useAlwaysAvailable' ] ?? true ; foreach ( $ result -> searchHits as $ hit ) { /** @var \eZ\Publish\SPI\Persistence\Content\ContentInfo $info */ $ info = $ hit -> valueObject ; $ contentIds [ ] = $ info -> id ; $ contentTypeIds [ ] = $ info -> contentTypeId ; // Unless we are told to load all languages, we add main language to translations so they are loaded too // Might in some case load more languages then intended, but prioritised handling will pick right one if ( ! empty ( $ languageFilter [ 'languages' ] ) && $ useAlwaysAvailable && $ info -> alwaysAvailable ) { $ translations [ ] = $ info -> mainLanguageCode ; } } $ missingContentList = [ ] ; $ contentList = $ this -> contentHandler -> loadContentList ( $ contentIds , array_unique ( $ translations ) ) ; $ contentTypeList = $ this -> contentTypeHandler -> loadContentTypeList ( array_unique ( $ contentTypeIds ) ) ; foreach ( $ result -> searchHits as $ key => $ hit ) { if ( isset ( $ contentList [ $ hit -> valueObject -> id ] ) ) { $ hit -> valueObject = $ this -> buildContentDomainObject ( $ contentList [ $ hit -> valueObject -> id ] , $ this -> contentTypeDomainMapper -> buildContentTypeDomainObject ( $ contentTypeList [ $ hit -> valueObject -> contentTypeId ] , $ languageFilter [ 'languages' ] ?? [ ] ) , $ languageFilter [ 'languages' ] ?? [ ] , $ useAlwaysAvailable ? $ hit -> valueObject -> mainLanguageCode : null ) ; } else { $ missingContentList [ ] = $ hit -> valueObject ; unset ( $ result -> searchHits [ $ key ] ) ; -- $ result -> totalCount ; } } return $ missingContentList ; }
Build API Content domain objects in bulk and apply to ContentSearchResult.

Loading of Content objects are done in bulk.

@param \eZ\Publish\API\Repository\Values\Content\Search\SearchResult $result SPI search result with SPI ContentInfo items as hits
@param array $languageFilter

@return \eZ\Publish\SPI\Persistence\Content\ContentInfo[] ContentInfo we did not find content for is returned.
Build API Content domain objects in bulk and apply to ContentSearchResult .