Sort or Order post with combination of both (Replies + Activity)

While I was having a go at creating a query for this it occurred to me that there are a couple of options in the advanced Search filter that may also be of use. In there you can set a maximum number of posts, a before or after date, as well as adding in whether they’re open or not, limit it to a specific category, etc,etc. That may be a more accessible way for more people to get something similar to what you’re looking for.

However, I think a data-explorer query could also do the job too, and may be more customizable too depending on what you need. Maybe something like this:


-- [params]
-- int :number_of_posts

SELECT t.category_id,
       t.id AS topic_id,
       t.created_at::date
FROM topics t
WHERE t.posts_count < :number_of_posts
AND t.archetype = 'regular'
AND t.closed = false
AND t.deleted_at IS NULL
AND t.created_at >= CURRENT_DATE - INTERVAL '1 WEEK'
ORDER BY t.created_at DESC

Which would pull out all topics with fewer than x amount of replies that were created in the last week (not closed, not deleted, not PM).

Is that close to what you had in mind?