Browse Source

Just some tlc

master
Tom Lingham 9 years ago
parent
commit
19d7db244d
  1. 3
      src/Matchers/BaseMatcher.php
  2. 20
      src/SearchBuilder.php

3
src/Matchers/BaseMatcher.php

@ -27,9 +27,8 @@ abstract class BaseMatcher implements MatcherInterface
*/ */
public function buildQueryString($column, $searchString) public function buildQueryString($column, $searchString)
{ {
if (method_exists($this, 'formatSearchString')) {
if (method_exists($this, 'formatSearchString'))
$searchString = $this->formatSearchString($searchString); $searchString = $this->formatSearchString($searchString);
}
return "IF($column {$this->operator} '$searchString', {$this->multiplier}, 0)"; return "IF($column {$this->operator} '$searchString', {$this->multiplier}, 0)";
} }

20
src/SearchBuilder.php

@ -42,11 +42,10 @@ class SearchBuilder
*/ */
public function search($searchable) public function search($searchable)
{ {
if (is_object($searchable) && method_exists($searchable, 'getTable')) {
$this->table = $searchable->getTable();
} else {
$this->table = $searchable;
}
// Check if table name or Eloquent
$isEloquent = is_object($searchable) && method_exists($searchable, 'getTable');
$this->table = $isEloquent ? $searchable->getTable() : $searchable;
return $this; return $this;
} }
@ -95,18 +94,17 @@ class SearchBuilder
// Check if default driver is being overridden, otherwise // Check if default driver is being overridden, otherwise
// load the default // load the default
if ($this->driverName) {
$driverName = $this->driverName;
} else {
$driverName = $this->config->get('searchy.default');
}
$driverName = $this->driverName ? $this->driverName : $this->config->get('searchy.default');
// Gets the details for the selected driver from the configuration file // Gets the details for the selected driver from the configuration file
$driver = $this->config->get("searchy.drivers.$driverName")['class']; $driver = $this->config->get("searchy.drivers.$driverName")['class'];
// Create a new instance of the selected drivers 'class' and pass // Create a new instance of the selected drivers 'class' and pass
// through table and fields to search // through table and fields to search
$driverInstance = new $driver($this->table, $this->searchFields, $relevanceFieldName, ['*']);
$driverInstance = new $driver( $this->table,
$this->searchFields,
$relevanceFieldName,
['*']);
return $driverInstance; return $driverInstance;
} }

Loading…
Cancel
Save