diff options
| author | 2020-04-17 10:57:35 +0200 | |
|---|---|---|
| committer | 2020-04-17 10:57:35 +0200 | |
| commit | ae70374b0323dc26f560b28414d2d270c06ddd50 (patch) | |
| tree | 2716a1d96c0d45d5db7df7cbba7540a2b520aa5f /app/Models/Search.php | |
| parent | a49db010e4a5e48017d8583c374210242a680ddd (diff) | |
Filter by multiple feed IDs (#2892)
Add the possibility to filter by feed ID like `f:123 more-search`
or multiple feed IDs, like `f:123,234,345 more-search` or an exclusion
like `!f:456,789 more-search`
Diffstat (limited to 'app/Models/Search.php')
| -rw-r--r-- | app/Models/Search.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/app/Models/Search.php b/app/Models/Search.php index 74264b712..1e1b9c1ff 100644 --- a/app/Models/Search.php +++ b/app/Models/Search.php @@ -12,7 +12,9 @@ class FreshRSS_Search { // This contains the user input string private $raw_input = ''; + // The following properties are extracted from the raw input + private $feed_ids; private $intitle; private $min_date; private $max_date; @@ -23,6 +25,7 @@ class FreshRSS_Search { private $tags; private $search; + private $not_feed_ids; private $not_intitle; private $not_min_date; private $not_max_date; @@ -41,6 +44,8 @@ class FreshRSS_Search { $input = preg_replace('/:"(.*?)"/', ':"\1"', $input); + $input = $this->parseNotFeedIds($input); + $input = $this->parseNotPubdateSearch($input); $input = $this->parseNotDateSearch($input); @@ -49,6 +54,8 @@ class FreshRSS_Search { $input = $this->parseNotInurlSearch($input); $input = $this->parseNotTagsSearch($input); + $input = $this->parseFeedIds($input); + $input = $this->parsePubdateSearch($input); $input = $this->parseDateSearch($input); @@ -69,6 +76,13 @@ class FreshRSS_Search { return $this->raw_input; } + public function getFeedIds() { + return $this->feed_ids; + } + public function getNotFeedIds() { + return $this->not_feed_ids; + } + public function getIntitle() { return $this->intitle; } @@ -154,6 +168,38 @@ class FreshRSS_Search { } /** + * Parse the search string to find feed IDs. + * + * @param string $input + * @return string + */ + private function parseFeedIds($input) { + if (preg_match_all('/\bf:(?P<search>[0-9,]*)/', $input, $matches)) { + $ids_lists = $matches['search']; + $input = str_replace($matches[0], '', $input); + $ids_lists = self::removeEmptyValues($ids_lists); + if (!empty($ids_lists[0])) { + $this->feed_ids = explode(',', $ids_lists[0]); + array_filter($this->feed_ids, function($v) { $v != ''; }); + } + } + return $input; + } + + private function parseNotFeedIds($input) { + if (preg_match_all('/[!-]f:(?P<search>[0-9,]*)/', $input, $matches)) { + $ids_lists = $matches['search']; + $input = str_replace($matches[0], '', $input); + $ids_lists = self::removeEmptyValues($ids_lists); + if (!empty($ids_lists[0])) { + $this->not_feed_ids = explode(',', $ids_lists[0]); + array_filter($this->not_feed_ids, function($v) { $v != ''; }); + } + } + return $input; + } + + /** * Parse the search string to find intitle keyword and the search related * to it. * The search is the first word following the keyword. |
