diff --git a/README.md b/README.md index d07feb9..1dc5914 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,11 @@ For example, if you want to search the name, email address and username of a use $users = Searchy::users('name', 'email', 'username')->query('John Smith'); ``` +#### Searching Joined/Concatenated Columns +Sometimes you may want to leverage searches on concatenated column. For example, on a `first_name` and `last_name` field but you only want to run the one query. To do this can separate columns with a double colon: +```php +$users = Searchy::users('first_name::last_name')->query('John Smith'); +``` Configuration ---------------------------------------- diff --git a/src/TomLingham/Searchy/Matchers/ConsecutiveCharactersMatcher.php b/src/TomLingham/Searchy/Matchers/ConsecutiveCharactersMatcher.php index 58d419b..872b836 100644 --- a/src/TomLingham/Searchy/Matchers/ConsecutiveCharactersMatcher.php +++ b/src/TomLingham/Searchy/Matchers/ConsecutiveCharactersMatcher.php @@ -34,6 +34,6 @@ class ConsecutiveCharactersMatcher extends BaseMatcher { $searchString = $this->formatSearchString( $rawString ); - return "IF($column {$this->operator} '$searchString', ROUND({$this->multiplier} * (CHAR_LENGTH( '$rawString' ) / CHAR_LENGTH( REPLACE($column, ' ', '') ))), 0)"; + return "IF(REPLACE($column, '\.', '') {$this->operator} '$searchString', ROUND({$this->multiplier} * (CHAR_LENGTH( '$rawString' ) / CHAR_LENGTH( REPLACE($column, ' ', '') ))), 0)"; } } \ No newline at end of file diff --git a/src/TomLingham/Searchy/SearchDrivers/BaseSearchDriver.php b/src/TomLingham/Searchy/SearchDrivers/BaseSearchDriver.php index 6377398..414c823 100644 --- a/src/TomLingham/Searchy/SearchDrivers/BaseSearchDriver.php +++ b/src/TomLingham/Searchy/SearchDrivers/BaseSearchDriver.php @@ -63,7 +63,12 @@ abstract class BaseSearchDriver implements SearchDriverInterface { $query = []; foreach ($searchFields as $searchField) { - $query[] = $this->buildSelectCriteria( $searchField ); + if (strpos($searchField, '::')){ + $concatString = explode('::', $searchField); + $query[] = $this->buildSelectCriteria( "CONCAT({$concatString[0]}, ' ', {$concatString[1]})"); + } else { + $query[] = $this->buildSelectCriteria( $searchField ); + } } return \DB::raw(implode(' + ', $query) . ' AS ' . \Config::get('searchy::fieldName'));