|
@ -23,32 +23,37 @@ abstract class BaseSearchDriver implements SearchDriverInterface { |
|
|
*/ |
|
|
*/ |
|
|
protected $table; |
|
|
protected $table; |
|
|
|
|
|
|
|
|
|
|
|
protected $columns; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @param null $table |
|
|
* @param null $table |
|
|
* @param array $searchFields |
|
|
* @param array $searchFields |
|
|
|
|
|
* @param array $columns |
|
|
*/ |
|
|
*/ |
|
|
public function __construct( $table = null, $searchFields = [] ) |
|
|
|
|
|
|
|
|
public function __construct( $table = null, $searchFields = [], $columns = ['*'] ) |
|
|
{ |
|
|
{ |
|
|
$this->searchFields = $searchFields; |
|
|
$this->searchFields = $searchFields; |
|
|
$this->table = $table; |
|
|
$this->table = $table; |
|
|
|
|
|
$this->columns = $columns; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @param $searchString |
|
|
* @param $searchString |
|
|
* @return \Illuminate\Database\Query\Builder|mixed|static |
|
|
* @return \Illuminate\Database\Query\Builder|mixed|static |
|
|
* @throws \Whoops\Example\Exception |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public function query( $searchString ) |
|
|
public function query( $searchString ) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
if(\Config::get('searchy::sanitize')) |
|
|
|
|
|
|
|
|
if(\Config::get('searchy.sanitize')) |
|
|
$this->searchString = $this->sanitize($searchString); |
|
|
$this->searchString = $this->sanitize($searchString); |
|
|
|
|
|
|
|
|
$results = \DB::table($this->table) |
|
|
$results = \DB::table($this->table) |
|
|
->select('*') |
|
|
|
|
|
|
|
|
->select( implode($this->columns, ', ') ) |
|
|
->addSelect($this->buildSelectQuery( $this->searchFields )) |
|
|
->addSelect($this->buildSelectQuery( $this->searchFields )) |
|
|
->orderBy(\Config::get('searchy::fieldName'), 'desc') |
|
|
|
|
|
->having(\Config::get('searchy::fieldName'),'>', 0); |
|
|
|
|
|
|
|
|
->orderBy(\Config::get('searchy.fieldName'), 'desc') |
|
|
|
|
|
->having(\Config::get('searchy.fieldName'),'>', 0); |
|
|
|
|
|
|
|
|
|
|
|
die($results->toSQL()); |
|
|
|
|
|
|
|
|
return $results; |
|
|
return $results; |
|
|
} |
|
|
} |
|
@ -71,7 +76,7 @@ abstract class BaseSearchDriver implements SearchDriverInterface { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return \DB::raw(implode(' + ', $query) . ' AS ' . \Config::get('searchy::fieldName')); |
|
|
|
|
|
|
|
|
return \DB::raw(implode(' + ', $query) . ' AS ' . \Config::get('searchy.fieldName')); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -113,7 +118,7 @@ abstract class BaseSearchDriver implements SearchDriverInterface { |
|
|
*/ |
|
|
*/ |
|
|
private function sanitize( $searchString ) |
|
|
private function sanitize( $searchString ) |
|
|
{ |
|
|
{ |
|
|
return preg_replace(\Config::get('searchy::sanitizeRegEx'), '', $searchString ); |
|
|
|
|
|
|
|
|
return preg_replace(\Config::get('searchy.sanitizeRegEx'), '', $searchString ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |