Skip to content

Commit 58e3ea5

Browse files
committed
order by _score bug
+ edge-case where option string is a callable
1 parent 63d9f00 commit 58e3ea5

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Query/Builder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ public function orderBy($column, $direction = 1, array $options = []): self
458458
if (is_string($direction)) {
459459
$direction = strtolower($direction) == 'asc' ? 1 : -1;
460460
}
461-
if (in_array($column, ['_score', '_count'])) {
461+
if (in_array($column, ['_count'])) {
462462
$this->sorts[$column] = $direction;
463463

464464
return $this;

src/Query/ManagesOptions.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function extractSearch($columns = null, $options = []): array
7979
if ($options) {
8080
return [$columns, $options];
8181
}
82-
if (is_callable($columns)) {
82+
if (is_callable($columns) && ! is_string($columns)) {
8383
$options = $columns;
8484
$columns = null;
8585

@@ -100,7 +100,7 @@ public function extractSearch($columns = null, $options = []): array
100100

101101
protected function extractOptionsFull($type, $column, $operator, $value, $boolean, $not, $options = []): array
102102
{
103-
if (is_callable($column)) {
103+
if (is_callable($column) && ! is_string($column)) {
104104
// The query is a closure, return it as is
105105
return [$column, $operator, $value, $boolean, $not, $options];
106106
}
@@ -129,7 +129,7 @@ protected function extractOptionsFull($type, $column, $operator, $value, $boolea
129129
}
130130
$allowedOptions = $this->returnAllowedOptions();
131131

132-
if ($value) {
132+
if ($value && ! is_string($value)) {
133133
// If either is callable or an array containing valid operators, then we have options
134134
if (is_callable($value) || (is_array($value) && count(array_intersect(array_keys($value), $allowedOptions)))) {
135135
$options = $this->parseOptions($value);
@@ -141,7 +141,7 @@ protected function extractOptionsFull($type, $column, $operator, $value, $boolea
141141
}
142142

143143
// Last, let's assess the operator
144-
if ($operator) {
144+
if ($operator && ! is_string($operator)) {
145145
// If either is callable or an array containing valid operators, then we have options
146146
if (is_callable($operator) || (is_array($operator) && count(array_intersect(array_keys($operator), $allowedOptions)))) {
147147
$options = $this->parseOptions($operator);

0 commit comments

Comments
 (0)