Browse Source

Merge pull request #4 from TomLingham/develop

Develop
master
Tom 11 years ago
parent
commit
1c648b81c7
  1. 5
      README.md
  2. 2
      src/TomLingham/Searchy/Matchers/ConsecutiveCharactersMatcher.php
  3. 5
      src/TomLingham/Searchy/SearchDrivers/BaseSearchDriver.php

5
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'); $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 Configuration
---------------------------------------- ----------------------------------------

2
src/TomLingham/Searchy/Matchers/ConsecutiveCharactersMatcher.php

@ -34,6 +34,6 @@ class ConsecutiveCharactersMatcher extends BaseMatcher
{ {
$searchString = $this->formatSearchString( $rawString ); $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)";
} }
} }

5
src/TomLingham/Searchy/SearchDrivers/BaseSearchDriver.php

@ -63,8 +63,13 @@ abstract class BaseSearchDriver implements SearchDriverInterface {
$query = []; $query = [];
foreach ($searchFields as $searchField) { foreach ($searchFields as $searchField) {
if (strpos($searchField, '::')){
$concatString = explode('::', $searchField);
$query[] = $this->buildSelectCriteria( "CONCAT({$concatString[0]}, ' ', {$concatString[1]})");
} else {
$query[] = $this->buildSelectCriteria( $searchField ); $query[] = $this->buildSelectCriteria( $searchField );
} }
}
return \DB::raw(implode(' + ', $query) . ' AS ' . \Config::get('searchy::fieldName')); return \DB::raw(implode(' + ', $query) . ' AS ' . \Config::get('searchy::fieldName'));

Loading…
Cancel
Save