aboutsummaryrefslogtreecommitdiff
path: root/app/Models/BooleanSearch.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2025-10-15 00:08:40 +0200
committerGravatar GitHub <noreply@github.com> 2025-10-15 00:08:40 +0200
commite070c3ed2bec4ea4a6c2a216a5c836d1e02ab381 (patch)
treec65a238580dc5b78c6cf6a1947523ff6291eaa0a /app/Models/BooleanSearch.php
parent1b8bc1ae8b9810eb66ff798093b89d2ce690373f (diff)
Implement search form (#8103)
* Add UI for advanced search To help users with the seach operators. Obviously not as powerful as a manually-written search query. Lack in particular negation and logical *and* for now, but I might try to do something about it. <img width="939" height="1438" alt="image" src="https://github.com/user-attachments/assets/0bcad39b-eff3-4f44-876b-a2552af2af00" /> * Consistency: allow multiple user queries like S:1,2 * Fix user query and add tests
Diffstat (limited to 'app/Models/BooleanSearch.php')
-rw-r--r--app/Models/BooleanSearch.php28
1 files changed, 19 insertions, 9 deletions
diff --git a/app/Models/BooleanSearch.php b/app/Models/BooleanSearch.php
index 1832bd419..7b3cc0e12 100644
--- a/app/Models/BooleanSearch.php
+++ b/app/Models/BooleanSearch.php
@@ -102,7 +102,7 @@ class FreshRSS_BooleanSearch implements \Stringable {
private function parseUserQueryIds(string $input, bool $allowUserQueries = true): string {
$all_matches = [];
- if (preg_match_all('/\bS:(?P<search>\d+)/', $input, $matchesFound)) {
+ if (preg_match_all('/\bS:(?P<search>[0-9,]+)/', $input, $matchesFound)) {
$all_matches[] = $matchesFound;
}
@@ -119,16 +119,26 @@ class FreshRSS_BooleanSearch implements \Stringable {
continue;
}
for ($i = count($matches['search']) - 1; $i >= 0; $i--) {
- // Index starting from 1
- $id = (int)(trim($matches['search'][$i])) - 1;
- if (!empty($queries[$id])) {
- $fromS[] = $matches[0][$i];
- if ($allowUserQueries) {
- $toS[] = '(' . self::escapeLiteralParentheses($queries[$id]) . ')';
- } else {
- $toS[] = '';
+ $ids = explode(',', $matches['search'][$i]);
+ $ids = array_map('intval', $ids);
+
+ $matchedQueries = [];
+ foreach ($ids as $id) {
+ if (!empty($queries[$id])) {
+ $matchedQueries[] = $queries[$id];
}
}
+ if (empty($matchedQueries)) {
+ continue;
+ }
+
+ $fromS[] = $matches[0][$i];
+ if ($allowUserQueries) {
+ $escapedQueries = array_map(fn(string $query): string => self::escapeLiteralParentheses($query), $matchedQueries);
+ $toS[] = '(' . implode(') OR (', $escapedQueries) . ')';
+ } else {
+ $toS[] = '';
+ }
}
}