Search filter - only topics / only posts

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.

Thanks

2 Likes

You have the ability currently to search all topics and posts

Are you meaning that you want this functionality while excluding the search results of topic titles?

1 Like

Have you looked over Advanced Search features for filtering?

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.

I hope it’s clear now.

2 Likes

In Discourse, a “topic” means all the messages. The first post is the original post (OP) or first post.

I understand however that it can be confusing since the button New Topic create a topic consisting on 1 post at first, and more posts when there are replies.

That said,

Would mean “only the first post of a topic” and it is indeed available, it’s the filter in:first:

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.

2 Likes

Thank you for the insight @Canapin.

Thank you for the specification about basically returning only topics. Completely missed that :blush:

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? :slight_smile:

2 Likes

It’s an unknown, strange and terrifying world for me, but looking at the code, the controller would be here:

The search filters seem to be here:

And you may be interested to see how Discours Assign adds a filter to the search:

2 Likes

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 :slight_smile:

2 Likes