Skip to content

Commit

Permalink
feature #80 add support for (NOT_)EQUALS in PatternMatch (sstok)
Browse files Browse the repository at this point in the history
This PR was merged into the master branch.

Discussion
----------

|Q            |A  |
|---          |---|
|Bug Fix?     |no |
|New Feature? |yes|
|BC Breaks?   |no |
|Deprecations?|no |
|Fixed Tickets|#79|
|License      |MIT|

Commits
-------

bfed29d add support for (NOT_)EQUALS in PatternMatch
  • Loading branch information
sstok committed Aug 9, 2015
2 parents aa43570 + bfed29d commit 68e1fcf
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/Input/FilterQueryInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,18 @@ private function getPatternMatchOperator($subParse = false)

return 'REGEX';

case '=':
$this->match(Lexer::T_EQUALS);

return 'EQUALS';

case !$subParse && '!':
$this->match(Lexer::T_NEGATE);

return 'NOT_'.$this->getPatternMatchOperator(true);

default:
$this->syntaxError(['*', '>', '<', '?', '!*', '!>', '!<', '!?']);
$this->syntaxError(['*', '>', '<', '?', '!*', '!>', '!<', '!?', '=', '!=']);
}
}
}
2 changes: 2 additions & 0 deletions src/Input/schema/dic/input/xml-input-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
<xsd:enumeration value="not_starts_with"/>
<xsd:enumeration value="not_ends_with"/>
<xsd:enumeration value="not_regex"/>
<xsd:enumeration value="equals"/>
<xsd:enumeration value="not_equals"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
Expand Down
5 changes: 4 additions & 1 deletion src/Value/PatternMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ final class PatternMatch
const PATTERN_NOT_STARTS_WITH = 6;
const PATTERN_NOT_ENDS_WITH = 7;
const PATTERN_NOT_REGEX = 8;
const PATTERN_EQUALS = 9;
const PATTERN_NOT_EQUALS = 10;

/**
* @var string
Expand Down Expand Up @@ -67,7 +69,7 @@ public function __construct($value, $patternType, $caseInsensitive = false)
}
}

if ($patternType < 1 || $patternType > 8) {
if ($patternType < 1 || $patternType > 10) {
throw new \InvalidArgumentException(sprintf('Unknown pattern-match type "%s".', $patternType));
}

Expand Down Expand Up @@ -114,6 +116,7 @@ public function isExclusive()
self::PATTERN_NOT_CONTAINS,
self::PATTERN_NOT_ENDS_WITH,
self::PATTERN_NOT_REGEX,
self::PATTERN_NOT_EQUALS,
], true
);
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Input/ArrayInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ public function provideMatcherValues()
['value' => '^foo|bar?', 'type' => 'REGEX'],
['value' => 'value4', 'type' => 'NOT_CONTAINS'],
['value' => 'value5', 'type' => 'NOT_CONTAINS', 'case-insensitive' => true],
['value' => 'value9', 'type' => 'EQUALS'],
['value' => 'value10', 'type' => 'NOT_EQUALS'],
['value' => 'value11', 'type' => 'EQUALS', 'case-insensitive' => true],
['value' => 'value12', 'type' => 'NOT_EQUALS', 'case-insensitive' => true],
],
],
],
Expand Down
4 changes: 2 additions & 2 deletions tests/Input/FilterQueryInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function testPatternMatchLexerNoEndLessLoop()

$this->setExpectedException(
'Rollerworks\Component\Search\Input\FilterQuery\QueryException',
"[Syntax Error] line 0, col 8: Error: Expected '*' | '>' | '<' | '?' | '!*' | '!>' | '!<' | '!?', got '!'"
"[Syntax Error] line 0, col 8: Error: Expected '*' | '>' | '<' | '?' | '!*' | '!>' | '!<' | '!?' | '=' | '!=', got '!'"
);

$processor->process($config, 'name: ~!!*"value";');
Expand Down Expand Up @@ -192,7 +192,7 @@ public function provideComparisonValues()
public function provideMatcherValues()
{
return [
['name: ~*value, ~i>value2, ~<value3, ~?"^foo|bar?", ~!*value4, ~i!*value5;'],
['name: ~*value, ~i>value2, ~<value3, ~?"^foo|bar?", ~!*value4, ~i!*value5, ~=value9, ~!=value10, ~i=value11, ~i!=value12;'],
];
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Input/InputProcessorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ public function it_processes_matchers($input)
$values->addPatternMatch(new PatternMatch('^foo|bar?', PatternMatch::PATTERN_REGEX));
$values->addPatternMatch(new PatternMatch('value4', PatternMatch::PATTERN_NOT_CONTAINS));
$values->addPatternMatch(new PatternMatch('value5', PatternMatch::PATTERN_NOT_CONTAINS, true));
$values->addPatternMatch(new PatternMatch('value9', PatternMatch::PATTERN_EQUALS));
$values->addPatternMatch(new PatternMatch('value10', PatternMatch::PATTERN_NOT_EQUALS));
$values->addPatternMatch(new PatternMatch('value11', PatternMatch::PATTERN_EQUALS, true));
$values->addPatternMatch(new PatternMatch('value12', PatternMatch::PATTERN_NOT_EQUALS, true));
$expectedGroup->addField('name', $values);

$condition = new SearchCondition($config->getFieldSet(), $expectedGroup);
Expand Down
4 changes: 4 additions & 0 deletions tests/Input/JsonInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ public function provideMatcherValues()
['value' => '^foo|bar?', 'type' => 'REGEX'],
['value' => 'value4', 'type' => 'NOT_CONTAINS'],
['value' => 'value5', 'type' => 'NOT_CONTAINS', 'case-insensitive' => true],
['value' => 'value9', 'type' => 'EQUALS'],
['value' => 'value10', 'type' => 'NOT_EQUALS'],
['value' => 'value11', 'type' => 'EQUALS', 'case-insensitive' => true],
['value' => 'value12', 'type' => 'NOT_EQUALS', 'case-insensitive' => true],
],
],
],
Expand Down
4 changes: 4 additions & 0 deletions tests/Input/XmlInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ public function provideMatcherValues()
<pattern-matcher type="regex" case-insensitive="false">^foo|bar?</pattern-matcher>
<pattern-matcher type="not_contains" case-insensitive="false">value4</pattern-matcher>
<pattern-matcher type="not_contains" case-insensitive="true">value5</pattern-matcher>
<pattern-matcher type="equals">value9</pattern-matcher>
<pattern-matcher type="not_equals">value10</pattern-matcher>
<pattern-matcher type="equals" case-insensitive="true">value11</pattern-matcher>
<pattern-matcher type="not_equals" case-insensitive="true">value12</pattern-matcher>
</pattern-matchers>
</field>
</fields>
Expand Down

0 comments on commit 68e1fcf

Please sign in to comment.