Browse Source

Cleanup and remove appostrophies in search string by default

master
Tom Lingham 11 years ago
parent
commit
8931bc2e56
  1. 3
      .travis.yml
  2. 5
      composer.json
  3. 3
      src/TomLingham/Searchy/Facades/Searchy.php
  4. 5
      src/TomLingham/Searchy/Matchers/ConsecutiveCharactersMatcher.php
  5. 9
      src/TomLingham/Searchy/Matchers/LevenshteinMatcher.php
  6. 5
      src/TomLingham/Searchy/Matchers/StudlyCaseMatcher.php
  7. 3
      src/TomLingham/Searchy/SearchBuilder.php
  8. 5
      src/TomLingham/Searchy/SearchDrivers/BaseSearchDriver.php
  9. 30
      src/TomLingham/Searchy/SearchDrivers/LevenshteinSearchDriver.php
  10. 2
      src/config/config.php

3
.travis.yml

@ -1,7 +1,6 @@
language: php
php:
- 5.3
- 5.4
- 5.5
- 5.6
@ -11,4 +10,4 @@ before_script:
- composer self-update
- composer install --prefer-source --no-interaction --dev
script: phpunit
script: vendor/bin/phpspec run

5
composer.json

@ -1,6 +1,6 @@
{
"name": "tom-lingham/searchy",
"description": "",
"description": "Laravel 4 Searchy makes user driven searching easy with fuzzy search, basic string matching and more to come!",
"authors": [
{
"name": "Tom Lingham",
@ -11,6 +11,9 @@
"php": ">=5.4.0",
"illuminate/support": "4.2.*"
},
"require-dev" :{
"phpspec/phpspec": "~2.0"
},
"autoload": {
"psr-0": {
"TomLingham\\Searchy": "src/"

3
src/TomLingham/Searchy/Facades/Searchy.php

@ -15,9 +15,8 @@ class Searchy extends Facade
*/
protected static function getFacadeAccessor()
{
if (!static::$app) {
if (!static::$app)
static::$app = SearchyServiceProvider::make();
}
return 'searchy';
}

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

@ -34,9 +34,6 @@ class ConsecutiveCharactersMatcher extends BaseMatcher
{
$searchString = $this->formatSearchString( $rawString );
$query = "IF($column {$this->operator} '$searchString', ROUND({$this->multiplier} * (CHAR_LENGTH( '$rawString' ) / CHAR_LENGTH( REPLACE($column, ' ', '') ))), 0)";
return $query;
return "IF($column {$this->operator} '$searchString', ROUND({$this->multiplier} * (CHAR_LENGTH( '$rawString' ) / CHAR_LENGTH( REPLACE($column, ' ', '') ))), 0)";
}
}

9
src/TomLingham/Searchy/Matchers/LevenshteinMatcher.php

@ -12,13 +12,6 @@
class LevenshteinMatcher extends BaseMatcher
{
private $sensitivity;
public function setSensitivity( $sensitivity )
{
$this->sensitivity = $sensitivity;
}
/**
* @param $column
* @param $searchString
@ -26,7 +19,7 @@ class LevenshteinMatcher extends BaseMatcher
*/
public function buildQueryString( $column, $searchString )
{
return "levenshtein($column, '$searchString', {$this->sensitivity})";
return "levenshtein($column, '$searchString')";
}
}

5
src/TomLingham/Searchy/Matchers/StudlyCaseMatcher.php

@ -11,6 +11,7 @@
class StudlyCaseMatcher extends BaseMatcher
{
/**
* @var string
*/
@ -28,8 +29,6 @@ class StudlyCaseMatcher extends BaseMatcher
public function buildQueryString( $column, $searchString )
{
$query = "IF( CHAR_LENGTH( TRIM($column)) = CHAR_LENGTH( REPLACE( TRIM($column), ' ', '')) AND $column {$this->operator} '{$this->formatSearchString($searchString)}', {$this->multiplier}, 0)";
return $query;
return "IF( CHAR_LENGTH( TRIM($column)) = CHAR_LENGTH( REPLACE( TRIM($column), ' ', '')) AND $column {$this->operator} '{$this->formatSearchString($searchString)}', {$this->multiplier}, 0)";
}
}

3
src/TomLingham/Searchy/SearchBuilder.php

@ -78,6 +78,7 @@ class SearchBuilder {
*/
private function makeDriver()
{
// Check if default driver is being overridden, otherwise
// load the default
if ( $this->driverName ){
@ -86,9 +87,11 @@ class SearchBuilder {
$driverName = \Config::get('searchy::default');
}
// Gets the details for the selected driver from the configuration file
$driverMap = \Config::get("searchy::drivers.$driverName");
// Create a new instance of the selected drivers 'class' and pass
// through table and fields to search
return new $driverMap['class']( $this->table, $this->searchFields );

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

@ -66,9 +66,8 @@ abstract class BaseSearchDriver implements SearchDriverInterface {
$query[] = $this->buildSelectCriteria( $searchField );
}
$query = \DB::raw(implode(' + ', $query) . ' AS ' . \Config::get('searchy::fieldName'));
return \DB::raw(implode(' + ', $query) . ' AS ' . \Config::get('searchy::fieldName'));
return $query;
}
/**
@ -109,7 +108,7 @@ abstract class BaseSearchDriver implements SearchDriverInterface {
*/
private function sanitize( $searchString )
{
return preg_replace(\Config::get('searchy::sanitizeRegEx'), '', $searchString);
return preg_replace(\Config::get('searchy::sanitizeRegEx'), '', $searchString );
}
}

30
src/TomLingham/Searchy/SearchDrivers/LevenshteinSearchDriver.php

@ -2,35 +2,11 @@
class LevenshteinSearchDriver extends BaseSearchDriver {
private $sensitivity = 10;
/**
* @var array
*/
protected $matchers = [
'TomLingham\Searchy\Matchers\LevenshteinMatcher' => 100
];
public function setSensitivity( $sensitivity ){
$this->sensitivity = $sensitivity;
return $this;
}
/**
* @param $column
* @param $matcherClass
* @param $multiplier
* @return mixed
*/
protected function makeMatcher( $column, $matcherClass, $multiplier )
{
$matcher = new $matcherClass( $multiplier );
$matcher->setSensitivity( $this->sensitivity );
return $matcher->buildQueryString( $column, $this->searchString );
}
}

2
src/config/config.php

@ -6,7 +6,7 @@ return [
'sanitize' => true,
'sanitizeRegEx' => '/[%]+/i',
'sanitizeRegEx' => '/[%\']+/i',
'fieldName' => 'relevance',

Loading…
Cancel
Save