From 6b4c2c789acd6e2625a6f0fa59f6f50f2ce22743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vilius=20=C5=A0umskas?= Date: Mon, 26 Oct 2020 11:39:27 +0200 Subject: [PATCH 1/2] Enhance boolean search expression. 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: https://github.com/teamtnt/tntsearch/issues/161, https://github.com/teamtnt/tntsearch/issues/215, https://github.com/trilbymedia/grav-plugin-tntsearch/issues/92) 2) In some sense it partialy reverts https://github.com/teamtnt/tntsearch/commit/33cc5244f02592e53ceffacf3c366e0b5111d7e8 as email address parts are broken into tokens in the default Tokenizer anyway. --- src/Support/Expression.php | 4 ++-- tests/support/ExpressionTest.php | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Support/Expression.php b/src/Support/Expression.php index 7ce5395..69e4d6a 100644 --- a/src/Support/Expression.php +++ b/src/Support/Expression.php @@ -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); diff --git a/tests/support/ExpressionTest.php b/tests/support/ExpressionTest.php index a42c804..dddccd3 100644 --- a/tests/support/ExpressionTest.php +++ b/tests/support/ExpressionTest.php @@ -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@test.com")); $this->assertEquals(['first', 'last', '&', 'something', 'else', '&', '|'], $exp->toPostfix("(first last) or (something else)")); } } From 6b983c7359d6e9a83cd52d82d0a71926a101af49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vilius=20=C5=A0umskas?= Date: Mon, 26 Oct 2020 11:51:28 +0200 Subject: [PATCH 2/2] Make Scrutinizer tests happy. --- src/Support/Expression.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Support/Expression.php b/src/Support/Expression.php index 69e4d6a..7ce8fff 100644 --- a/src/Support/Expression.php +++ b/src/Support/Expression.php @@ -87,7 +87,7 @@ public function priority($operator) public function lex($string) { $bad = [' or ', ' -', ' ']; - $good = [ '|' , '~', '&']; + $good = ['|', '~', '&']; $string = str_replace($bad, $good, $string); $string = mb_strtolower($string);