Finds Locations for the given query.
public findLocations ( eZ\Publish\API\Repository\Values\Content\LocationQuery $query, array $languageFilter = [], boolean $filterOnUserPermissions = true ) : eZ\Publish\API\Repository\Values\Content\Search\SearchResult | ||
$query | eZ\Publish\API\Repository\Values\Content\LocationQuery | |
$languageFilter | array | Configuration for specifying prioritized languages query will be performed on.
Currently supports: array("languages" => array(
useAlwaysAvailable defaults to true to avoid exceptions on missing translations |
$filterOnUserPermissions | boolean | if true only the objects which is the user allowed to read are returned. |
return | eZ\Publish\API\Repository\Values\Content\Search\SearchResult |
/** * 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; }
/** * 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 ); }