From 2d0897ea747208356d8c70cc25e327d7f08c523c Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Wed, 2 Oct 2024 08:20:15 +0200 Subject: Allow dynamic search operator in user queries (#6851) * Allow dynamic search operator in user queries fix https://github.com/FreshRSS/FreshRSS/issues/6849 * Other approach --- app/Models/BooleanSearch.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'app/Models/BooleanSearch.php') diff --git a/app/Models/BooleanSearch.php b/app/Models/BooleanSearch.php index b8e3af5e0..10c2321fb 100644 --- a/app/Models/BooleanSearch.php +++ b/app/Models/BooleanSearch.php @@ -31,12 +31,14 @@ class FreshRSS_BooleanSearch { if (!is_string($input)) { return; } + } + $this->raw_input = $input; + if ($level === 0) { $input = $this->parseUserQueryNames($input, $allowUserQueries); $input = $this->parseUserQueryIds($input, $allowUserQueries); $input = trim($input); } - $this->raw_input = $input; $input = self::consistentOrParentheses($input); @@ -58,11 +60,11 @@ class FreshRSS_BooleanSearch { } if (!empty($all_matches)) { - /** @var array */ $queries = []; foreach (FreshRSS_Context::userConf()->queries as $raw_query) { - $query = new FreshRSS_UserQuery($raw_query, FreshRSS_Context::categories(), FreshRSS_Context::labels()); - $queries[$query->getName()] = $query; + if (($raw_query['name'] ?? '') !== '' && ($raw_query['search'] ?? '') !== '') { + $queries[$raw_query['name']] = trim($raw_query['search']); + } } $fromS = []; @@ -76,7 +78,7 @@ class FreshRSS_BooleanSearch { if (!empty($queries[$name])) { $fromS[] = $matches[0][$i]; if ($allowUserQueries) { - $toS[] = '(' . trim($queries[$name]->getSearch()->getRawInput()) . ')'; + $toS[] = '(' . $queries[$name] . ')'; } else { $toS[] = ''; } @@ -100,11 +102,9 @@ class FreshRSS_BooleanSearch { } if (!empty($all_matches)) { - /** @var array */ $queries = []; foreach (FreshRSS_Context::userConf()->queries as $raw_query) { - $query = new FreshRSS_UserQuery($raw_query, FreshRSS_Context::categories(), FreshRSS_Context::labels()); - $queries[] = $query; + $queries[] = trim($raw_query['search'] ?? ''); } $fromS = []; @@ -119,7 +119,7 @@ class FreshRSS_BooleanSearch { if (!empty($queries[$id])) { $fromS[] = $matches[0][$i]; if ($allowUserQueries) { - $toS[] = '(' . trim($queries[$id]->getSearch()->getRawInput()) . ')'; + $toS[] = '(' . $queries[$id] . ')'; } else { $toS[] = ''; } -- cgit v1.2.3