Skip to content

Commit 674c156

Browse files
authored
Merge pull request #12179 from nanaya/fix-empty-search
Fix error on forum post search by username with blank query
2 parents 745ebed + affdd7a commit 674c156

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

app/Libraries/Search/TeamSearch.php

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,28 @@ public function __construct(?TeamSearchParams $params = null)
2525

2626
public function getQuery()
2727
{
28-
static $partialMatchFields = [
29-
'description',
30-
'name',
31-
'name.*',
32-
'short_name',
33-
'short_name.*',
34-
];
35-
36-
$value = $this->params->queryString;
37-
$terms = explode(' ', $value);
38-
39-
return new BoolQuery()
40-
->shouldMatch(1)
41-
->should(['term' => ['_id' => ['value' => $value, 'boost' => 100]]])
42-
->should(QueryHelper::queryString($value, $partialMatchFields, 'or', 1 / count($terms)))
43-
->should(QueryHelper::queryString($value, [], 'and'));
28+
$query = new BoolQuery();
29+
30+
if ($this->params->queryString !== null) {
31+
static $partialMatchFields = [
32+
'description',
33+
'name',
34+
'name.*',
35+
'short_name',
36+
'short_name.*',
37+
];
38+
39+
$value = $this->params->queryString;
40+
$terms = explode(' ', $value);
41+
42+
$query
43+
->shouldMatch(1)
44+
->should(['term' => ['_id' => ['value' => $value, 'boost' => 100]]])
45+
->should(QueryHelper::queryString($value, $partialMatchFields, 'or', 1 / count($terms)))
46+
->should(QueryHelper::queryString($value, [], 'and'));
47+
}
48+
49+
return $query;
4450
}
4551

4652
public function records()

0 commit comments

Comments
 (0)