You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 25, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: Query/Query.php
+16-23Lines changed: 16 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -78,11 +78,11 @@ class Query implements HttpTransportable
78
78
private$itemsPromoted = [];
79
79
80
80
/**
81
-
* @var array
81
+
* @var SortBy
82
82
*
83
-
* Sort
83
+
* Sort by
84
84
*/
85
-
private$sort;
85
+
private$sortBy;
86
86
87
87
/**
88
88
* @var Aggregation[]
@@ -168,7 +168,7 @@ class Query implements HttpTransportable
168
168
*/
169
169
privatefunction__construct(string$queryText)
170
170
{
171
-
$this->sortBy(SortBy::SCORE);
171
+
$this->sortBy = SortBy::create();
172
172
$this->filters['_query'] = Filter::create(
173
173
'',
174
174
[$queryText],
@@ -649,28 +649,21 @@ public function getFilterFields(): array
649
649
/**
650
650
* Sort by.
651
651
*
652
-
* @param array $sort
652
+
* @param SortBy $sortBy
653
653
*
654
654
* @return Query
655
655
*/
656
-
publicfunctionsortBy(array$sort): self
656
+
publicfunctionsortBy(SortBy$sortBy): self
657
657
{
658
-
if (isset($sort['_geo_distance'])) {
658
+
if ($sortBy->isSortedByGeoDistance()) {
659
659
if (!$this->coordinateinstanceof Coordinate) {
660
660
thrownewQueryBuildException('In order to be able to sort by coordinates, you need to create a Query by using Query::createLocated() instead of Query::create()');
661
661
}
662
-
$sort['_geo_distance']['coordinate'] = $this
663
-
->coordinate
664
-
->toArray();
665
-
}
666
662
667
-
foreach ($sortas$field => $direction) {
668
-
if (!is_array($direction)) {
669
-
$sort[$field] = ['order' => $direction];
670
-
}
663
+
$sortBy->setCoordinate($this->coordinate);
671
664
}
672
665
673
-
$this->sort = $sort;
666
+
$this->sortBy = $sortBy;
674
667
675
668
return$this;
676
669
}
@@ -885,11 +878,11 @@ public function getFilterByField(string $fieldName): ? Filter
885
878
/**
886
879
* Get sort by.
887
880
*
888
-
* @return array
881
+
* @return SortBy
889
882
*/
890
-
publicfunctiongetSortBy(): array
883
+
publicfunctiongetSortBy(): SortBy
891
884
{
892
-
return$this->sort;
885
+
return$this->sortBy;
893
886
}
894
887
895
888
/**
@@ -1218,9 +1211,9 @@ public function toArray(): array
0 commit comments