fossar / selfoss

multipurpose rss reader, live stream, mashup, aggregation web application
https://selfoss.aditu.de
GNU General Public License v3.0
2.36k stars 343 forks source link

Filter does not seem to work #1426

Closed mrichtarsky closed 1 year ago

mrichtarsky commented 1 year ago

Hi,

for an RSS feed, I have this filter: !title:/UK/

I expect that this filters out all articles with "UK" in the title. However, article with titles as follows are still shown:

"Ofcom proposes deeper probe into UK cloud market"

Am I doing anything wrong?

Thanks and best regards, Martin

jtojnar commented 1 year ago

It does appear to work for me on 107c1b80ce7b1b418e0ba0121c536853a6a5992a with https://advanced-television.com/feed/ in “RSS Feed” spout. Note that filters do not work retrospectively – once an item is stored in the selfoss database, it will remain there until garbage collected.

mrichtarsky commented 1 year ago

I creates the filter already yesterday so it should certainly be effective. But good to know the syntax is OK. I will try some other things like filtering on other fields.

jtojnar commented 1 year ago

You could try to apply the following changes and set logger_level=DEBUG in your config to get more debug info:

diff --git a/src/helpers/ContentLoader.php b/src/helpers/ContentLoader.php
index 9a5ebe86..e8c2fb03 100644
--- a/src/helpers/ContentLoader.php
+++ b/src/helpers/ContentLoader.php
@@ -31,6 +31,8 @@ class ContentLoader {
     private ThumbnailStore $thumbnailStore;
     private WebClient $webClient;

+    public static $log;
+
     public function __construct(Configuration $configuration, \daos\DatabaseInterface $database, IconStore $iconStore, Image $imageHelper, \daos\Items $itemsDao, Logger $logger, \daos\Sources $sourcesDao, SpoutLoader $spoutLoader, ThumbnailStore $thumbnailStore, WebClient $webClient) {
         $this->configuration = $configuration;
         $this->database = $database;
@@ -38,6 +40,7 @@ class ContentLoader {
         $this->imageHelper = $imageHelper;
         $this->itemsDao = $itemsDao;
         $this->logger = $logger;
+        self::$log = $logger;
         $this->sourcesDao = $sourcesDao;
         $this->spoutLoader = $spoutLoader;
         $this->thumbnailStore = $thumbnailStore;
diff --git a/src/helpers/Filters/MapFilter.php b/src/helpers/Filters/MapFilter.php
index e0a8125f..7c4e65fa 100644
--- a/src/helpers/Filters/MapFilter.php
+++ b/src/helpers/Filters/MapFilter.php
@@ -37,6 +37,7 @@ final class MapFilter implements Filter {
      * @param T $item
      */
     public function admits($item): bool {
+        \helpers\ContentLoader::$log->debug("trying to match with map");
         return $this->filter->admits(($this->transform)($item));
     }
 }
diff --git a/src/helpers/Filters/NegationFilter.php b/src/helpers/Filters/NegationFilter.php
index 4a22246f..56de7f6a 100644
--- a/src/helpers/Filters/NegationFilter.php
+++ b/src/helpers/Filters/NegationFilter.php
@@ -31,6 +31,7 @@ final class NegationFilter implements Filter {
      * @param T $item
      */
     public function admits($item): bool {
+        \helpers\ContentLoader::$log->debug("trying to match negation");
         return !$this->filter->admits($item);
     }
 }
diff --git a/src/helpers/Filters/RegexFilter.php b/src/helpers/Filters/RegexFilter.php
index 82223f08..89321b0c 100644
--- a/src/helpers/Filters/RegexFilter.php
+++ b/src/helpers/Filters/RegexFilter.php
@@ -34,6 +34,7 @@ final class RegexFilter implements Filter {
      */
     public function admits($item): bool {
         $result = @preg_match($this->regex, $item);
+        \helpers\ContentLoader::$log->debug("trying to match '{$this->regex}' against '{$item}' result: " . var_export($result));
         \assert($result !== false); // Verified at construction.

         return $result === 1;
mrichtarsky commented 1 year ago

I'm still on 2.19-4fc98f6, so the patch doesn't apply. The filter logic seems to have been rewritten recently. Perhaps the documentation I followed doesn't match to my old version anymore? I also see this in the logs (without patch), which seems to match that explanation:

[2023-04-17 11:01:28] selfoss.ERROR: filter error: null

Since there is no recent release which has the changed filter code, I would update to a snapshot first. Is it safe to use the latest, or is there a more stable one you can recommend?

Thanks in advance (and also thanks for selfoss which I use heavily)!

jtojnar commented 1 year ago

Oh, the documentation on the website is for the master branch. I still need to decide on some way to make that clear. Ideally we would have a select box that would allow switching between versions but that is less elegant.

The version you are on only supports the filtering both title and content at the same time (described in the first point in the filter docs).

I am not aware of any new regressions in the latest snapshot 2.20-9a3d7cf compared to previous snapshots.

However, since the version you are using is almost a year old, and a new stable version has been released since, please read the changes in the NEWS file if any of the changes affect you. Notably, if you have custom spouts or custom sharers, you will need to modify them.

mrichtarsky commented 1 year ago

Thanks for the helpful pointers, everything works as expected now!