From ae70374b0323dc26f560b28414d2d270c06ddd50 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 17 Apr 2020 10:57:35 +0200 Subject: 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` --- app/Models/Search.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'app/Models/Search.php') 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; } @@ -153,6 +167,38 @@ class FreshRSS_Search { return $value; } + /** + * Parse the search string to find feed IDs. + * + * @param string $input + * @return string + */ + private function parseFeedIds($input) { + if (preg_match_all('/\bf:(?P[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[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. -- cgit v1.2.3