Skip to content

Commit 23f7ba3

Browse files
committed
Search tweaks
1 parent 0336c0e commit 23f7ba3

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/Hunter.php

+15-13
Original file line numberDiff line numberDiff line change
@@ -405,24 +405,26 @@ public function getSearchParams($term, array $options = [])
405405
$params = $this->getBasicParams($options);
406406

407407
// Get fields option
408-
$fields = Arr::get($options, 'field');
408+
$fields = Arr::get($options, 'fields');
409409

410410
// Check for user specified fields or use default
411-
if (is_string($fields) === false) {
411+
if (empty($fields) === true) {
412412
$fields = $this->config('fields');
413413
}
414414

415-
// Add fields to search
416-
if (empty($fields) === false) {
417-
$params['body']['query']['bool']['must'][] = [
418-
'multi_match' => [
419-
'query' => $term,
420-
'fields' => $fields,
421-
],
422-
];
423-
}
424-
else {
425-
$params['body']['query']['match']['_all'][] = $term;
415+
// Add text query if one was entered
416+
if ($term) {
417+
if (empty($fields) === false) {
418+
$params['body']['query']['bool']['must'][] = [
419+
'multi_match' => [
420+
'query' => $term,
421+
'fields' => $fields,
422+
],
423+
];
424+
}
425+
else {
426+
$params['body']['query']['match']['_all'][] = $term;
427+
}
426428
}
427429

428430
// Include the locale field

0 commit comments

Comments
 (0)