You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
<?php namespace TomLingham\Searchy\Matchers;
|
|
|
|
/**
|
|
* Matches strings that include all the characters in the search relatively position within the string.
|
|
* It also calculates the percentage of characters in the string that are matched and applies the multiplier accordingly.
|
|
*
|
|
* For Example, a search for 'fba' would match; 'Foo Bar' or 'Afraid of bats'
|
|
*
|
|
* Class ConsecutiveCharactersMatcher
|
|
* @package TomLingham\Searchy\Matchers
|
|
*/
|
|
class ConsecutiveCharactersMatcher extends BaseMatcher
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $operator = 'LIKE';
|
|
|
|
/**
|
|
* @param $searchString
|
|
* @return string
|
|
*/
|
|
public function formatSearchString( $searchString )
|
|
{
|
|
return '%'.implode('%', str_split( $searchString )).'%';
|
|
}
|
|
|
|
/**
|
|
* @param $column
|
|
* @param $rawString
|
|
* @return mixed|string
|
|
*/
|
|
public function buildQueryString( $column, $rawString )
|
|
{
|
|
$searchString = $this->formatSearchString( $rawString );
|
|
|
|
return "IF(REPLACE($column, '\.', '') {$this->operator} '$searchString', ROUND({$this->multiplier} * (CHAR_LENGTH( '$rawString' ) / CHAR_LENGTH( REPLACE($column, ' ', '') ))), 0)";
|
|
}
|
|
}
|