Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Commit

Permalink
Merge 65f8171 into 4e05a88
Browse files Browse the repository at this point in the history
  • Loading branch information
bertramakers committed May 2, 2019
2 parents 4e05a88 + 65f8171 commit aface23
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"require": {
"cultuurnet/udb3": "~0.1",
"cultuurnet/udb3-search": "~0.1",
"cultuurnet/udb3-search": "dev-feature/III-2901 as 0.1",
"cultuurnet/valueobjects": "~3.0",
"ongr/elasticsearch-dsl": "~5.0.1",
"elasticsearch/elasticsearch": "~5.2",
Expand Down
16 changes: 16 additions & 0 deletions src/Offer/ElasticSearchOfferQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,22 @@ public function withSortByAvailableTo(SortOrder $sortOrder)
return $this->withFieldSort('availableTo', $sortOrder->toNative());
}

/**
* @inheritdoc
*/
public function withSortByCreated(SortOrder $sortOrder)
{
return $this->withFieldSort('created', $sortOrder->toNative());
}

/**
* @inheritdoc
*/
public function withSortByModified(SortOrder $sortOrder)
{
return $this->withFieldSort('modified', $sortOrder->toNative());
}

/**
* @inheritdoc
*
Expand Down
62 changes: 62 additions & 0 deletions tests/Offer/ElasticSearchOfferQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2725,6 +2725,68 @@ public function it_should_build_a_query_with_multiple_sorts()
$this->assertEquals($expectedQueryArray, $actualQueryArray);
}

/**
* @test
*/
public function it_should_build_a_query_with_sort_by_created()
{
/* @var ElasticSearchOfferQueryBuilder $builder */
$builder = (new ElasticSearchOfferQueryBuilder())
->withStart(new Natural(30))
->withLimit(new Natural(10))
->withSortByCreated(SortOrder::ASC());

$expectedQueryArray = [
'from' => 30,
'size' => 10,
'query' => [
'match_all' => (object) [],
],
'sort' => [
[
'created' => [
'order' => 'asc',
],
],
],
];

$actualQueryArray = $builder->build()->toArray();

$this->assertEquals($expectedQueryArray, $actualQueryArray);
}

/**
* @test
*/
public function it_should_build_a_query_with_sort_by_modified()
{
/* @var ElasticSearchOfferQueryBuilder $builder */
$builder = (new ElasticSearchOfferQueryBuilder())
->withStart(new Natural(30))
->withLimit(new Natural(10))
->withSortByModified(SortOrder::ASC());

$expectedQueryArray = [
'from' => 30,
'size' => 10,
'query' => [
'match_all' => (object) [],
],
'sort' => [
[
'modified' => [
'order' => 'asc',
],
],
],
];

$actualQueryArray = $builder->build()->toArray();

$this->assertEquals($expectedQueryArray, $actualQueryArray);
}

/**
* @return FacetName
*/
Expand Down

0 comments on commit aface23

Please sign in to comment.