Skip to content

Commit

Permalink
Merge pull request #7361 from rossriley/fix/unicode-word-support
Browse files Browse the repository at this point in the history
Add unicode word support for searches
  • Loading branch information
bobdenotter committed Mar 5, 2018
2 parents 71c2359 + d55afeb commit 869974a
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/Storage/Query/QueryParameterParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,19 @@ public function __construct(ExpressionBuilder $expr = null)

public function setupDefaults()
{
$word = "[\p{L}\p{N}_]+";

// @codingStandardsIgnoreStart
$this->addValueMatcher('<(\w+)', ['value' => '$1', 'operator' => 'lt']);
$this->addValueMatcher('<=(\w+)', ['value' => '$1', 'operator' => 'lte']);
$this->addValueMatcher('>=(\w+)', ['value' => '$1', 'operator' => 'gte']);
$this->addValueMatcher('>(\w+)', ['value' => '$1', 'operator' => 'gt']);
$this->addValueMatcher('!$', ['value' => '', 'operator' => 'isNotNull']);
$this->addValueMatcher('!(\w+)', ['value' => '$1', 'operator' => 'neq']);
$this->addValueMatcher('!\[([\w ,]+)\]', ['value' => function ($val) { return explode(',', $val); }, 'operator' => 'notIn']);
$this->addValueMatcher('\[([\w ,]+)\]', ['value' => function ($val) { return explode(',', $val); }, 'operator' => 'in']);
$this->addValueMatcher('(%\w+|\w+%|%\w+%)', ['value' => '$1', 'operator' => 'like']);
$this->addValueMatcher('(\w+)', ['value' => '$1', 'operator' => 'eq']);
$this->addValueMatcher("<($word)", ['value' => '$1', 'operator' => 'lt']);
$this->addValueMatcher("<=($word)", ['value' => '$1', 'operator' => 'lte']);
$this->addValueMatcher(">=($word)", ['value' => '$1', 'operator' => 'gte']);
$this->addValueMatcher(">($word)", ['value' => '$1', 'operator' => 'gt']);
$this->addValueMatcher('!$', ['value' => '', 'operator' => 'isNotNull']);
$this->addValueMatcher("!($word)", ['value' => '$1', 'operator' => 'neq']);
$this->addValueMatcher('!\[([\p{L}\p{N} ,]+)\]', ['value' => function ($val) { return explode(',', $val); }, 'operator' => 'notIn']);
$this->addValueMatcher('\[([\p{L}\p{N} ,]+)\]', ['value' => function ($val) { return explode(',', $val); }, 'operator' => 'in']);
$this->addValueMatcher("(%$word|$word%|%$word%)", ['value' => '$1', 'operator' => 'like']);
$this->addValueMatcher("($word)", ['value' => '$1', 'operator' => 'eq']);
// @codingStandardsIgnoreEnd

$this->addFilterHandler([$this, 'defaultFilterHandler']);
Expand Down Expand Up @@ -286,7 +288,7 @@ public function defaultFilterHandler($key, $value, $expr)
public function parseValue($value)
{
foreach ($this->valueMatchers as $matcher) {
$regex = sprintf('/%s/', $matcher['token']);
$regex = sprintf('/%s/u', $matcher['token']);
$values = $matcher['params'];
if (preg_match($regex, $value)) {
if (is_callable($values['value'])) {
Expand Down

0 comments on commit 869974a

Please sign in to comment.