Navigation
eZ Documentation Center
 

This is outdated documentation made for eZ Publish Platform 5.2. It is being moved into the eZ Publish 5.x documentation, so please go there for most up-to-date documentation.

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Info

The full list of criteria available can be seen at: https://github.com/found on your installation in the following directory vendor/ezsystems/ezpublish-kernel/tree/master/eZ/Publish/API/Repository/Values/Content/Query/Criterion. Additionally you may look at integration tests like vendor/ezsystems/ezpublish-kernel/eZ/Publish/API/Repository/Tests/SearchServiceTest.php for more details on how these are used.

NB: Be aware that the links point to code in the upcoming version (master) and might not represent the criteria in your eZ Publish version.

Note
titleCriterion independence

Note the criterion independance : Criterion are not related to each other by design and this can lead to a limitation in Content Search. See an example in the Criterion Independance example page.

 

Running the search query and using the results

...

Code Block
languagephp
$result = $searchService->findContent( $query );
$output->writeln( 'Found ' . $result->totalCount . ' items' );
foreach ( $result->searchHits as $searchHit )
{
    $output->writeln( $searchHit->valueObject->contentInfo->name );
}

The The searchHits properties  properties of the the SearchResult object  object is an array of ContentInfo objects SearchHit objects. In valueObject property of SearchHit, you will find the Content object that match the given given Query.

Tip: If you you are searching using a unique identifier, for instance using the content id or content remote id criterion, then you can use SearchService::findSingle(), this takes a Criterion and returns a single Content, or throws NotFound exception if none is found.

...

Code Block
languagephp
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content;
 
// [...]
 
$query = new Query();
$criterion1 = new Criterion\Subtree( $locationService->loadLocation( 2 )->pathString );
$criterion2 = new Criterion\ContentTypeIdContentTypeIdentifier( 1'folder' );
$query->criterion = new Criterion\LogicalAnd(
    array( $criterion1, $criterion2 )
);
 
$result = $searchService->findContent( $query );

...

Code Block
languagephp
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content;
 
// [...]
 
$query = new Query();
$query->criterion = new Criterion\LogicalAnd(
    array(
        new Criterion\ParentLocationId( 2 ),
        new Criterion\LogicalOr(
            array(
                new Criterion\ContentTypeIdContentTypeIdentifier( 1'folder' ),
                new Criterion\ContentTypeId( 2 )
            )
        )
    )
);
 
$result = $searchService->findContent( $query );

...