Skip to content

Commit

Permalink
make any column searchable in postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
m-bymike committed Sep 19, 2018
1 parent aa7cec5 commit caa7d53
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Illuminate/Database/Query/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Database\Query\Grammars;

use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Database\Query\Builder;

class PostgresGrammar extends Grammar
Expand All @@ -20,6 +21,43 @@ class PostgresGrammar extends Grammar
'is distinct from', 'is not distinct from',
];

/**
* {@inheritdoc}
*
* @param Builder $query
* @param array $where
*
* @return string
*/
protected function whereBasic(Builder $query, $where)
{
// Special treatment for like clauses. In order to make
// any column searchable, we need to convert it to text.
if (Str::contains($where['operator'], 'like')) {
return $this->whereBasicLike($query, $where);
}

$value = $this->parameter($where['value']);

return $this->wrap($where['column']).' '.$where['operator'].' '.$value;
}

/**
* Compile a "where like" clause. Suffix column with text conversion
* to make numeric columns searchable.
*
* @param Builder $query
* @param array $where
*
* @return string
*/
protected function whereBasicLike(Builder $query, $where)
{
$value = $this->parameter($where['value']);

return $this->wrap($where['column']).' :: text '.$where['operator'].' '.$value;
}

/**
* Compile a "where date" clause.
*
Expand Down

0 comments on commit caa7d53

Please sign in to comment.