Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Component/Predicate/NullPredicate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ class NullPredicate extends AbstractPredicate
*/
public function acceptPredicateVisitor(PredicateVisitor $visitor)
{

}
}
32 changes: 31 additions & 1 deletion src/Component/Query/RecordQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*
Expand All @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/Component/Query/RecordQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}