Skip to the content
Documentation

Criterion Independence example: comparison of v.1 vs v.2

No ratings yet

Versions Compared

Old Version 1

changes.mady.by.user Sarah Haïm-Lubczanski

Saved on Apr 04, 2014

compared with

New Version Current

changes.mady.by.user Dominika Kurek

Saved on Jan 19, 2016

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

With Exponential you can have multiple location content. Criterions do not relate to others criterion you can  use the Public API and Criterion to search this content, it can lead to a comportement you are not expecting.Example of Criterions not relating to each other: There is a Content with two Locations: Location A and Location B

  • Location A is visible
  • Location B is hidden

 Searching with LocationId criterion with Location B id and Visibility criterion with Visibility::VISIBLE will return the Content because conditions are satisfied:

  • Content has Location B
  • Content is visible (it has Location A that is visible)

 

Code Block
language php
<?php

use eZ\Publish\API\Repository\Values\Content\Query;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\LogicalAnd;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\LocationId;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Visibility;

/** @var string|int $locationBId */
/** @var \eZ\Publish\API\Repository\Repository $repository */

$searchService = $repository->getSearchService();

$query = new Query(
    array(
        'filter' => new LogicalAnd(
            array(
                new LocationId( $locationBId ),
                new Visibility( Visibility::VISIBLE ),
            )
        )
    )
);

$searchResult = $searchService->findContent( $query );

// Content is found
$content = $searchResult->searchHits[0];

Comments

Add a comment

Comments are read by a moderator before they appear.