diff --git a/src/Component/Predicate/NullPredicate.php b/src/Component/Predicate/NullPredicate.php index 723546c..2bd91b5 100644 --- a/src/Component/Predicate/NullPredicate.php +++ b/src/Component/Predicate/NullPredicate.php @@ -14,6 +14,5 @@ class NullPredicate extends AbstractPredicate */ public function acceptPredicateVisitor(PredicateVisitor $visitor) { - } } diff --git a/src/Component/Query/RecordQueryBuilder.php b/src/Component/Query/RecordQueryBuilder.php index f14984e..7ed7877 100644 --- a/src/Component/Query/RecordQueryBuilder.php +++ b/src/Component/Query/RecordQueryBuilder.php @@ -100,6 +100,11 @@ class RecordQueryBuilder */ private $sortType = null; + /** + * @var bool Whether to activate truncation search mode + */ + private $enableTruncation = false; + /** * Sets the record search query string. Format follows the same specification as the Phraseanet search * engine. @@ -413,6 +418,30 @@ public function setFields(array $fields) return $this; } + /** + * Enables truncation search mode. + */ + public function enableTruncation() + { + $this->enableTruncation = true; + } + + /** + * Disables truncation search mode + */ + public function disableTruncation() + { + $this->enableTruncation = false; + } + + /** + * @return bool + */ + public function isTruncationEnabled() + { + return $this->enableTruncation; + } + /** * Returns the built query. * @@ -425,7 +454,8 @@ public function getQuery() 'bases' => array_unique($this->collections), 'offset_start' => $this->offsetStart, 'per_page' => $this->recordsPerPage, - 'search_type' => $this->searchType + 'search_type' => $this->searchType, + 'truncation' => $this->enableTruncation ? 1 : 0 ); $query = $this->appendRecordType($query); diff --git a/tests/unit/Component/Query/RecordQueryBuilderTest.php b/tests/unit/Component/Query/RecordQueryBuilderTest.php index c1a6035..905e12a 100644 --- a/tests/unit/Component/Query/RecordQueryBuilderTest.php +++ b/tests/unit/Component/Query/RecordQueryBuilderTest.php @@ -378,4 +378,30 @@ public function testSetFieldsWithInvalidNameThrowsException($name) $builder->setFields(array('bacon', 'eggs', $name)); } + + public function testTruncationIsDisabledByDefault() + { + $builder = new RecordQueryBuilder(); + + $this->assertFalse($builder->isTruncationEnabled(), 'Truncation should be disabled by default'); + } + + public function testTruncationCanBeEnabled() + { + $builder = new RecordQueryBuilder(); + + $builder->enableTruncation(); + + $this->assertTrue($builder->isTruncationEnabled(), 'Truncation should be enabled after calling enable'); + } + + public function testTruncationCanBeDisabled() + { + $builder = new RecordQueryBuilder(); + + $builder->enableTruncation(); + $builder->disableTruncation(); + + $this->assertFalse($builder->isTruncationEnabled(), 'Truncation should be disabled after calling disable'); + } }