Skip to content

Commit

Permalink
Enhance boolean search expression.
Browse files Browse the repository at this point in the history
This patch changes two things:
1) When using custom Tokenizer, enables searching for UUIDs, product names and other items with dashes in their names by counting only space and dash character as an expression instead of just dash (see:
teamtnt#161, teamtnt#215, trilbymedia/grav-plugin-tntsearch#92)
2) In some sense it partialy reverts teamtnt@33cc524 as email address parts are broken into tokens in the default Tokenizer anyway.
  • Loading branch information
ViliusS committed Oct 26, 2020
1 parent 5ee9533 commit 6b4c2c7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Support/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public function priority($operator)

public function lex($string)
{
$bad = [' or ', '-', ' ', '@', '.'];
$good = [ '|' , '~', '&', '&', '&'];
$bad = [' or ', ' -', ' '];
$good = [ '|' , '~', '&'];

$string = str_replace($bad, $good, $string);
$string = mb_strtolower($string);
Expand Down
1 change: 0 additions & 1 deletion tests/support/ExpressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public function testToPostfix()
$this->assertEquals(['great', 'awsome', '|'], $exp->toPostfix("great or awsome"));
$this->assertEquals(['great', 'awsome', '&'], $exp->toPostfix("great awsome"));
$this->assertEquals(['email', 'test', '&', 'com', '&'], $exp->toPostfix("email test com"));
$this->assertEquals(['email', 'test', '&', 'com', '&'], $exp->toPostfix("[email protected]"));
$this->assertEquals(['first', 'last', '&', 'something', 'else', '&', '|'], $exp->toPostfix("(first last) or (something else)"));
}
}

0 comments on commit 6b4c2c7

Please sign in to comment.