Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.

Commit 46ee99b

Browse files
authored
Merge pull request #50 from apisearch-io/fix/fixed-sort-by-basic-fields
Fixed when sorting by id or type
2 parents 519d439 + 10fd23b commit 46ee99b

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Query/SortBy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public function byFieldValue(
251251
): SortBy {
252252
$this->sortsBy[] = [
253253
'type' => self::TYPE_FIELD,
254-
"indexed_metadata.$field" => [
254+
Filter::getFilterPathByField($field) => [
255255
'order' => $order,
256256
],
257257
];

Tests/Query/SortByTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,33 @@ public function testSortByFieldValue()
116116
);
117117
}
118118

119+
/**
120+
* Test sort by field value.
121+
*/
122+
public function testSortByFieldValueBasicFields()
123+
{
124+
$sortBy = SortBy::create();
125+
$sortBy->byFieldValue('id', SortBy::ASC);
126+
$sortBy->byFieldValue('type', SortBy::ASC);
127+
$this->assertEquals(
128+
[
129+
[
130+
'type' => SortBy::TYPE_FIELD,
131+
'uuid.id' => [
132+
'order' => SortBy::ASC,
133+
],
134+
],
135+
[
136+
'type' => SortBy::TYPE_FIELD,
137+
'uuid.type' => [
138+
'order' => SortBy::ASC,
139+
],
140+
],
141+
],
142+
$sortBy->all()
143+
);
144+
}
145+
119146
/**
120147
* Test sortby nested field and filter.
121148
*/

0 commit comments

Comments
 (0)