From 10fd23bc20d63f3f17eb15f2f5625d3333febf28 Mon Sep 17 00:00:00 2001 From: Marc Morera Date: Mon, 27 Aug 2018 18:01:20 +0200 Subject: [PATCH] Fixed when sorting by id or type --- Query/SortBy.php | 2 +- Tests/Query/SortByTest.php | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Query/SortBy.php b/Query/SortBy.php index 3a883c5..398a2f4 100644 --- a/Query/SortBy.php +++ b/Query/SortBy.php @@ -251,7 +251,7 @@ public function byFieldValue( ): SortBy { $this->sortsBy[] = [ 'type' => self::TYPE_FIELD, - "indexed_metadata.$field" => [ + Filter::getFilterPathByField($field) => [ 'order' => $order, ], ]; diff --git a/Tests/Query/SortByTest.php b/Tests/Query/SortByTest.php index d9888f1..c8d9a9c 100644 --- a/Tests/Query/SortByTest.php +++ b/Tests/Query/SortByTest.php @@ -116,6 +116,33 @@ public function testSortByFieldValue() ); } + /** + * Test sort by field value. + */ + public function testSortByFieldValueBasicFields() + { + $sortBy = SortBy::create(); + $sortBy->byFieldValue('id', SortBy::ASC); + $sortBy->byFieldValue('type', SortBy::ASC); + $this->assertEquals( + [ + [ + 'type' => SortBy::TYPE_FIELD, + 'uuid.id' => [ + 'order' => SortBy::ASC, + ], + ], + [ + 'type' => SortBy::TYPE_FIELD, + 'uuid.type' => [ + 'order' => SortBy::ASC, + ], + ], + ], + $sortBy->all() + ); + } + /** * Test sortby nested field and filter. */