Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbaljet committed Sep 17, 2021
1 parent 6bd4009 commit 318f60f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `laravel-cross-eloquent-search` will be documented in this file

## 2.2.1 - 2021-09-17

- Bugfix for JSON columns

## 2.2.0 - 2021-09-17

- Support for ordering by relevance
Expand Down
5 changes: 4 additions & 1 deletion src/Searcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Database\Query\Grammars\MySqlGrammar;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
Expand Down Expand Up @@ -354,7 +355,9 @@ private function addRelevanceQueryToBuilder($builder, $modelToSearchThrough)
return;
}

$expressionsAndBindings = $modelToSearchThrough->getQualifiedColumns()->flatMap(function ($field) use ($builder) {
$expressionsAndBindings = $modelToSearchThrough->getQualifiedColumns()->flatMap(function ($field) {
$field = (new MySqlGrammar)->wrap($field);

return $this->termsWithoutWildcards->map(function ($term) use ($field) {
return [
'expression' => "COALESCE(CHAR_LENGTH(LOWER({$field})) - CHAR_LENGTH(REPLACE(LOWER({$field}), ?, ?)), 0)",
Expand Down

0 comments on commit 318f60f

Please sign in to comment.