Skip to content

Commit

Permalink
Merge pull request #175 from Maras0830/master
Browse files Browse the repository at this point in the history
Allow search input '' or null.
  • Loading branch information
nicolaslopezj authored Jul 9, 2018
2 parents 813a860 + ff6c5ef commit ca3630e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/SearchableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public function scopeSearchRestricted(Builder $q, $search, $restriction, $thresh

foreach ($queries as $select)
{
$selects[] = $select;
if (!empty($select)) {
$selects[] = $select;
}
}
}

Expand All @@ -86,7 +88,9 @@ public function scopeSearchRestricted(Builder $q, $search, $restriction, $thresh
$threshold = $relevance_count / 4;
}

$this->filterQueryWithRelevance($query, $selects, $threshold);
if (!empty($selects)) {
$this->filterQueryWithRelevance($query, $selects, $threshold);
}

$this->makeGroupBy($query);

Expand Down Expand Up @@ -220,7 +224,9 @@ protected function makeGroupBy(Builder $query)
*/
protected function addSelectsToQuery(Builder $query, array $selects)
{
$query->selectRaw('max(' . implode(' + ', $selects) . ') as relevance', $this->search_bindings);
if (!empty($selects)) {
$query->selectRaw('max(' . implode(' + ', $selects) . ') as relevance', $this->search_bindings);
}
}

/**
Expand Down Expand Up @@ -333,3 +339,4 @@ protected function mergeQueries(Builder $clone, Builder $original) {
$original->withoutGlobalScopes()->setBindings($mergedBindings);
}
}

0 comments on commit ca3630e

Please sign in to comment.