Filter on labels?

TTRSS’s filters and labels are very powerful, and I have been using them extensively to assign labels to articles. However, I can’t seem to match against a label in a filter; I can only use regular expressions on title, content, etc.

As an example, I have lots of different feeds from different sources. I have set up filters to apply labels to articles for terms like “coronavirus”, “trump”, etc. Sometimes, I prefer to read my news feed WITHOUT those articles, when I am just tired of it all.

What I can do is use the following for a search term: “-label:coronavirus -label:trump” and this works well. However, I would really like the ability to make a filter that can inverse match against those labels and apply another label, such as “nopolitics”. Then, I could simply click on that label to see the articles with those labels filtered out. In addition, this would let me create more filters that use the “nopolitics” label.

Is there a way to match against an existing label? Alternatively, is there a way to save a search, or apply a label to a search? I doesn’t seem to me that having TTRSS subscribe to its own search results is the correct answer.

the problem with adding something like this is the way filters are designed: matching actions are gathered from filters - in order - based on article content provided by the feed (until Stop action is encountered) and then applied, once, as article is imported to the database - which makes it impossible to have filters depend on changes made by other filters.

before you ask, no, i’m not going to do a third overhaul of filters to make this possible. that would add complexity which, in my personal opinion, is simply not worth the trouble.

however, there are other ways to solve your actual problem which tt-rss actually provides, to give one example you could reduce the score of these articles in the same filter that applies the label, that would clear them out to the bottom of headlines list, so you could read them at your leisure.

personally, i just use filters to delete articles like that. and boy do i have a huge list of keywords. :face_with_raised_eyebrow:

this is something that could be useful, one could write a plugin to do that. it wouldn’t be too hard, i think, tt-rss supports virtual feeds provided by plugins.

Thank you for the reply, your explanation of how filters work makes sense to me (the fact that a later filter cannot depend on changes made by a previous filter). I am happy to have confirmation that I am not just missing something.

I’ve never written a plugin before, I will have to read up on that. For my own purposes, the ability to save a search, give it a name, and have that name appear on the left side similar to labels would be perfect. Do you by chance have any pointers of where I should start, such as an existing plugin that could be modified?

Thank you for your help!

here’s an extremely rough prototype of a plugin which makes feeds based on searches:

<?php
class VF_Search extends Plugin {

	private $host;
	private $feeds = [];

	// put your search queries here:
	private $searches = [
		"tt-rss",
		"title:debian",
		"linux",
		"title:security",
	];

	function about() {
		return array(1.0,
			"Feeds based on search results",
			"fox",
			false);
	}

	function init($host) {
		$this->host = $host;

		foreach ($this->searches as $search) {
			array_push($this->feeds,
				[$host->add_feed(-1, "Search: $search", 'search', $this), $search]
			);
		}
	}

	function get_unread($feed_id) {
		return 0;
	}

	function get_total($feed_id) {
		return 0;
	}

	function get_headlines($feed_id, $options) {
		$search = array_reduce($this->feeds,
			function ($carry, $feed) use ($feed_id) {
				if ($feed_id == $feed[0])
					return $feed[1];
				else
					return $carry;
			}
		);

		$params = array(
			"feed" => -4,
			"limit" => $options["limit"],
			"view_mode" => $this->get_unread(-1) > 0 ? "adaptive" : "all_articles",
			"override_order" => $options['override_order'],
			"offset" => $options["offset"],
			"filter" => $options["filter"],
			"since_id" => $options["since_id"],
			"include_children" => $options["include_children"],
			"search" => $search,
			"override_vfeed" => "ttrss_feeds.title AS feed_title,"
		);

		$qfh_ret = Feeds::queryFeedHeadlines($params);
		$qfh_ret[1] = "Search: $search";

		return $qfh_ret;
	}

	function api_version() {
		return 2;
	}

}

put it to plugins.local/vf_search/init.php and add your search queries to the array near the top.

if someone wants to add configurable UI for it or whatever, they have my blessing.

Awesome, thank you for this! I’ll see what I can do.

Speaking of filters, for quite a while, my feed hasn’t been sorting on the “score” assigned by filters… I’m not sure if I broke something, but I’ve looked, and just haven’t figured it out… but kept figuring “meh, I’ll try again later, or see if it gets fixed in an update”.

default sorting definitely should take scoring into account. there was a bit of a rewrite in that area though a few months ago when plugin override for sort order was implemented, the discussion should be around here somewhere.

e: time sure flies Possible sort bug - #9 by fox - Support - Tiny Tiny RSS: Community


i was bored - https://git.tt-rss.org/fox/ttrss-vf-search

note that this needs core changes i’ve just merged.

Oh man, this is awesome! I was just looking at the source code last night to figure out how to make a tab in the preferences, and then you drop this on me. Thank you so much! I’ll test it out this weekend once I get my instance updated.

I’ll look at the plugin, because I do read oldest first… It doesn’t make sense to me to read newer stuff before older stuff. :lol:
That’s like reading the replies before what they’re replying to! :laughing:

Thanks.

https://git.tt-rss.org/fox/tt-rss/commit/c82457e534a573d5838ccecd9ab94cf7c5b05cc2

i think this might be useful to enough people ootb so i’ve added it to the repo.

I just wanted to chime in and say that this worked perfectly for me. Thank you again!

followup: i’ve split this one (and a bunch of other plugins) into a separate repo, accessible through tt-rss new built-in plugin installer: https://git.tt-rss.org/fox/ttrss-scored-oldest-first