Inheritance: implements eZ\Publish\API\Repository\SearchService
 /**
  * Returns the number of results.
  *
  * @return integer The number of results.
  */
 public function getNbResults()
 {
     if (isset($this->nbResults)) {
         return $this->nbResults;
     }
     $countQuery = clone $this->query;
     $countQuery->limit = 0;
     return $this->nbResults = $this->searchService->findLocations($countQuery)->totalCount;
 }
 /**
  * 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);
 }
 /**
  * Prepares content for ContentDataValue class.
  *
  * @param string $contentIdList
  * @param string $responseType
  * @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
  * @throws \EzSystems\RecommendationBundle\Rest\Exception\UnsupportedResponseTypeException
  */
 public function getContent($contentIdList, $responseType, Request $request)
 {
     if ($responseType != 'http') {
         throw new UnsupportedResponseTypeException('Only http response is available for single content');
     }
     $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;
     $content = $this->prepareContent($contentItems, $request);
     return new ContentDataValue($content, ['responseType' => 'http', 'documentRoot' => $request->server->get('DOCUMENT_ROOT'), 'host' => $request->getSchemeAndHttpHost(), 'customerId' => $this->customerId]);
 }
    /**
     * Test for the findContent() method.
     */
    public function testFindLocationsWithDefaultQueryValues()
    {
        $repositoryMock = $this->getRepositoryMock();
        /** @var \eZ\Publish\SPI\Search\Content\Handler $searchHandlerMock */
        $searchHandlerMock = $this->getSPIMockHandler( 'Search\\Content\\Handler' );
        /** @var \eZ\Publish\SPI\Search\Content\Location\Handler $locationSearchHandlerMock */
        /** @var \eZ\Publish\SPI\Search\Content\Location\Handler $locationSearchHandlerMock */
        $locationSearchHandlerMock = $this->getSPIMockHandler( 'Search\\Content\\Location\\Handler' );
        $domainMapperMock = $this->getDomainMapperMock();
        $service = new SearchService(
            $repositoryMock,
            $searchHandlerMock,
            $locationSearchHandlerMock,
            $domainMapperMock,
            $this->getPermissionsCriterionHandlerMock(),
            array()
        );

        $spiLocation = new SPILocation;
        $locationMock = $this->getMockForAbstractClass( "eZ\\Publish\\API\\Repository\\Values\\Content\\Location" );
        $domainMapperMock->expects( $this->once() )
            ->method( "buildLocationDomainObject" )
            ->with( $this->equalTo( $spiLocation ) )
            ->will( $this->returnValue( $locationMock ) );

        /** @var \PHPUnit_Framework_MockObject_MockObject $locationSearchHandlerMock */
        $locationSearchHandlerMock
            ->expects( $this->once() )
            ->method( "findLocations" )
            ->with(
                new LocationQuery(
                    array(
                        "filter" => new Criterion\MatchAll(),
                        "limit" => 1073741824
                    )
                )
            )
            ->will(
                $this->returnValue(
                    new SearchResult(
                        array(
                            "searchHits" => array( new SearchHit( array( "valueObject" => $spiLocation ) ) ),
                            "totalCount" => 1
                        )
                    )
                )
            );

        $result = $service->findLocations( new LocationQuery(), false );

        $this->assertEquals(
            new SearchResult(
                array(
                    "searchHits" => array( new SearchHit( array( "valueObject" => $locationMock ) ) ),
                    "totalCount" => 1
                )
            ),
            $result
        );
    }