From d6c2daee51fa90f000c106492141baf3824931d2 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 25 Jan 2025 09:16:13 +0100 Subject: Add search operator intext: (#7228) * Add search operator intext: fix https://github.com/FreshRSS/FreshRSS/issues/6188 https://github.com/FreshRSS/FreshRSS/discussions/7220 * Add example to doc --- tests/app/Models/SearchTest.php | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'tests') diff --git a/tests/app/Models/SearchTest.php b/tests/app/Models/SearchTest.php index 81b4ac1fb..a62e255de 100644 --- a/tests/app/Models/SearchTest.php +++ b/tests/app/Models/SearchTest.php @@ -70,6 +70,27 @@ class SearchTest extends PHPUnit\Framework\TestCase { ]; } + /** + * @param array|null $intext_value + * @param array|null $search_value + */ + #[DataProvider('provideIntextSearch')] + public static function test__construct_whenInputContainsIntext(string $input, ?array $intext_value, ?array $search_value): void { + $search = new FreshRSS_Search($input); + self::assertSame($intext_value, $search->getIntext()); + self::assertSame($search_value, $search->getSearch()); + } + + /** + * @return list> + */ + public static function provideIntextSearch(): array { + return [ + ['intext:word1', ['word1'], null], + ['intext:"word1 word2"', ['word1 word2'], null], + ]; + } + /** * @param array|null $author_value * @param array|null $search_value @@ -379,6 +400,11 @@ class SearchTest extends PHPUnit\Framework\TestCase { '(e.title LIKE ? )', ['%"hello world"%'], ], + [ + 'intext:\'"hello world"\'', + '(e.content LIKE ? )', + ['%"hello world"%'], + ], [ '(ab) OR (cd) OR (ef)', '(((e.title LIKE ? OR e.content LIKE ?) )) OR (((e.title LIKE ? OR e.content LIKE ?) )) OR (((e.title LIKE ? OR e.content LIKE ?) ))', @@ -469,6 +495,11 @@ class SearchTest extends PHPUnit\Framework\TestCase { '(e.title ~ ? )', ['^(ab|cd)'] ], + [ + 'intext:/^(ab|cd)/', + '(e.content ~ ? )', + ['^(ab|cd)'] + ], ]; } @@ -505,6 +536,11 @@ class SearchTest extends PHPUnit\Framework\TestCase { '(e.title ~ ? )', ['^ab\\M'] ], + [ + 'intext:/^ab\\M/', + '(e.content ~ ? )', + ['^ab\\M'] + ], [ 'author:/^ab$/', "(REPLACE(e.author, ';', '\n') ~ ? )", @@ -573,6 +609,11 @@ class SearchTest extends PHPUnit\Framework\TestCase { "(e.title REGEXP ? )", ['(?-i)(?m)^ab$'] ], + [ + 'intext:/^ab$/m', + '(UNCOMPRESS(e.content_bin) REGEXP ?) )', + ['(?-i)(?m)^ab$'] + ], ]; } @@ -606,6 +647,11 @@ class SearchTest extends PHPUnit\Framework\TestCase { "(REGEXP_LIKE(e.title,?,'mc') )", ['^ab$'] ], + [ + 'intext:/^ab$/m', + "(REGEXP_LIKE(UNCOMPRESS(e.content_bin),?,'mc')) )", + ['^ab$'] + ], ]; } @@ -642,6 +688,11 @@ class SearchTest extends PHPUnit\Framework\TestCase { '(e.title REGEXP ? )', ['/^ab\\b/'] ], + [ + 'intext:/^ab\\b/', + '(e.content REGEXP ? )', + ['/^ab\\b/'] + ], ]; } } -- cgit v1.2.3