aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAlexandre Alapetite <alexandre@alapetite.fr>2024-10-02 08:20:15 +0200
committerGitHub <noreply@github.com>2024-10-02 08:20:15 +0200
commit2d0897ea747208356d8c70cc25e327d7f08c523c (patch)
tree3965faf6c106772c5c2fa2faff56c43b769b67be
parent2489b6259ad334407c023eb60722c9746d973542 (diff)
downloadfreshrss-2d0897ea747208356d8c70cc25e327d7f08c523c.tar.gz
freshrss-2d0897ea747208356d8c70cc25e327d7f08c523c.zip
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
-rw-r--r--app/Models/BooleanSearch.php18
-rw-r--r--app/Models/UserQuery.php2
-rw-r--r--p/api/query.php2
3 files changed, 11 insertions, 11 deletions
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<string,FreshRSS_UserQuery> */
$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<string,FreshRSS_UserQuery> */
$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[] = '';
}
diff --git a/app/Models/UserQuery.php b/app/Models/UserQuery.php
index d701b6b44..1ec8ee148 100644
--- a/app/Models/UserQuery.php
+++ b/app/Models/UserQuery.php
@@ -95,7 +95,7 @@ class FreshRSS_UserQuery {
}
// linked too deeply with the search object, need to use dependency injection
- $this->search = new FreshRSS_BooleanSearch($query['search'], 0, 'AND', false);
+ $this->search = new FreshRSS_BooleanSearch($query['search'], 0, 'AND', allowUserQueries: true);
if (!empty($query['state'])) {
$this->state = intval($query['state']);
}
diff --git a/p/api/query.php b/p/api/query.php
index 57ec10ff3..345a56788 100644
--- a/p/api/query.php
+++ b/p/api/query.php
@@ -93,7 +93,7 @@ foreach (FreshRSS_Context::userConf()->queries as $raw_query) {
$search = $query->getSearch()->getRawInput();
// Note: we disallow references to user queries in public user search to avoid sniffing internal user queries
- $userSearch = new FreshRSS_BooleanSearch(Minz_Request::paramString('search'), 0, 'AND', false);
+ $userSearch = new FreshRSS_BooleanSearch(Minz_Request::paramString('search'), 0, 'AND', allowUserQueries: false);
if ($userSearch->getRawInput() !== '') {
if ($search === '') {
$search = $userSearch->getRawInput();