The discussion revolves around adding a search filter in Discourse to allow users to search for either only topics or only posts, rather than mixing both in results. Crius initiates the request, explaining that filtering results would reduce noise when users know they’re looking for either topics (first posts) or replies. Canapin clarifies that searching for topics corresponds to the in:first filter, which returns only the first post of each topic, but there’s no built-in way to exclude first posts or filter by replies. Canapin shares relevant code locations in Discourse’s search controller and filter logic, suggesting a plugin could implement such a feature. Crius appreciates the guidance and plans to explore it further once free from work commitments.
While I understand that the regular search for topics/posts might be good enough for most use cases, I’ve had some requests from users to have a way to filter the results in case they are searching for that, to only shows replies or topics (which would translate to first reply to a topic I guess).
This could probably be achievable also with a theme component but I thought to ask first in case I’m just missing something obvious.
I know it’s possible to search in topic and post. What is being reported is that results mix up topics and posts and it would be nice to have a way to tell Discourse to show “only the topics” OR “only the posts” as well as both (as it is now).
As the results are presented in an infinite scrolling interface, being able to filter out what the user knows already won’t be there, would limit the noise.
If I know that I’ve looking for a post, there is no reason to have to keep scrolling through also the topics to find what I want.
Searching in all posts except the first ones isn’t possible, and at this time there is no operator to exclude a term, a filter, a category or anything else.
Thank you for the specification about basically returning only topics. Completely missed that
As a workaround, when the search result return the actual results, it builds the URL, do you reckon we could have a component/plugin that simply add a style="display:none" to the ones that follow the URL format that specify a post and vice-versa for topics.
In the case of a plugin, somewhere in the search results there must be a function that determine “this is a first reply” or “this is not a first reply”. Maybe it would be possible to intercept that and skip it from being added to the array of results given a specifically added new filter?
If you know which file has that controller/model, can you link it here so I can give it a look as well?
Thank you @Canapin. I’ll check back on this in a couple weeks as I’m currently swamped at work and just gathering info on what I can work on after I get a little more free again