diff --git a/src/JohannesSchobel/DingoQueryMapper/Operators/CollectionOperator.php b/src/JohannesSchobel/DingoQueryMapper/Operators/CollectionOperator.php index 1edc720..0306fe4 100644 --- a/src/JohannesSchobel/DingoQueryMapper/Operators/CollectionOperator.php +++ b/src/JohannesSchobel/DingoQueryMapper/Operators/CollectionOperator.php @@ -127,16 +127,32 @@ private function createEvaluationRule($key, $operator, $value) // now check if the operator was "(not) like"? if (strpos($operator, 'like') !== false) { - $value = str_replace('%', '', $value); - $rule = "substr('%s', 0, strlen('%s')) %s '%s'"; // haystack, $needle, $comparable, $needle - $expectedResult = '==='; + // check for %value% to perform a more fuzzy match + if (preg_match('/%(.*).{1,}?%/', $value)) { + $value = str_replace('%', '', $value); + $rule = "%sis_int(stripos('%s', '%s')) ? true : false"; - if (stripos($operator, 'not') !== false) { - // it is a NOT LIKE operator - $expectedResult = '!=='; - } + $expectedResult = ''; + + if (stripos($operator, 'not') !== false) { + // it is a NOT LIKE operator + $expectedResult = '!'; + } + + $rule = sprintf($rule, $expectedResult, $key, $value); + } else { + $value = str_replace('%', '', $value); + $rule = "substr('%s', 0, strlen('%s')) %s '%s'"; // haystack, $needle, $comparable, $needle + + $expectedResult = '==='; + + if (stripos($operator, 'not') !== false) { + // it is a NOT LIKE operator + $expectedResult = '!=='; + } - $rule = sprintf($rule, $key, $value, $expectedResult, $value); + $rule = sprintf($rule, $key, $value, $expectedResult, $value); + } } return $rule;