# Search filter - only topics / only posts

**URL:** https://meta.discourse.org/t/search-filter-only-topics-only-posts/257994
**Category:** Feature
**Tags:** search
**Created:** [March 13, 2023, 5:27pm UTC](https://meta.discourse.org/t/search-filter-only-topics-only-posts/257994 "2023-03-13T17:27:56Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Crius](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/crius/32/317214_2.png) [@Crius](https://meta.discourse.org/u/Crius)
#### Post date: [March 13, 2023, 5:27pm UTC](https://meta.discourse.org/t/search-filter-only-topics-only-posts/257994/1 "2023-03-13T17:27:56Z")

</div>

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

---

<div class="post-metadata">

### Author: ![isaac](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/isaac/32/235758_2.png) [@isaac](https://meta.discourse.org/u/isaac)
#### Post date: [March 13, 2023, 5:53pm UTC](https://meta.discourse.org/t/search-filter-only-topics-only-posts/257994/2 "2023-03-13T17:53:22Z")

</div>

You have the ability currently to search all _topics and posts_

 ![Screenshot 2023-03-13 at 12.51.33 PM](https://global.discourse-cdn.com/meta/original/4X/1/2/0/12060ca1c2dbc74e2b7cff723c2a71128b4f8eff.png)

Are you meaning that you want this functionality while excluding the search results of _topic titles_?

---

<div class="post-metadata">

### Author: ![Heliosurge](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/heliosurge/32/571810_2.png) [@Heliosurge](https://meta.discourse.org/u/Heliosurge)
#### Post date: [March 13, 2023, 6:28pm UTC](https://meta.discourse.org/t/search-filter-only-topics-only-posts/257994/3 "2023-03-13T18:28:09Z")

</div>

Have you looked over Advanced Search features for filtering?

 ![Screenshot_20230313-152836](https://global.discourse-cdn.com/meta/original/4X/b/5/9/b5949161be4a3e30a318bedaf5ceda4b9e56c142.png)

---

<div class="post-metadata">

### Author: ![Crius](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/crius/32/317214_2.png) [@Crius](https://meta.discourse.org/u/Crius)
#### Post date: [March 13, 2023, 7:44pm UTC](https://meta.discourse.org/t/search-filter-only-topics-only-posts/257994/4 "2023-03-13T19:44:15Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [March 13, 2023, 8:54pm UTC](https://meta.discourse.org/t/search-filter-only-topics-only-posts/257994/5 "2023-03-13T20:54:51Z")

</div>

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](https://global.discourse-cdn.com/meta/original/4X/0/6/8/068a6f228599ce683f00713439055a8ddf835ac2.png) create a topic consisting on 1 post at first, and more posts when there are replies.

That said,

> [@Crius](#):
>
> only the topics

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

 ![image](https://global.discourse-cdn.com/meta/original/4X/a/2/8/a2849a93c8123e340c9f657f0be76786fdeab265.png)

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.

---

<div class="post-metadata">

### Author: ![Crius](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/crius/32/317214_2.png) [@Crius](https://meta.discourse.org/u/Crius)
#### Post date: [March 13, 2023, 10:51pm UTC](https://meta.discourse.org/t/search-filter-only-topics-only-posts/257994/6 "2023-03-13T22:51:23Z")

</div>

Thank you for the insight @Canapin.

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? 🙂

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [March 13, 2023, 11:40pm UTC](https://meta.discourse.org/t/search-filter-only-topics-only-posts/257994/7 "2023-03-13T23:40:44Z")

</div>

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

> <https://github.com/discourse/discourse/blob/2c8dfc3dbc401074e91d930dafe98f38c88a396f/app/controllers/search_controller.rb>

The search filters seem to be here:

> <https://github.com/discourse/discourse/blob/60ad836313b15eb8072bfadcbf657d5275754fde/lib/search.rb#L358>

And you may be interested to see how [Discours Assign](https://meta.discourse.org/t/discourse-assign/58044) adds a filter to the search:

> <https://github.com/discourse/discourse-assign/blob/99e5bb48c907e47ce798fcbe097f9c4a98b0c1ad/plugin.rb#L932>

---

<div class="post-metadata">

### Author: ![Crius](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/crius/32/317214_2.png) [@Crius](https://meta.discourse.org/u/Crius)
#### Post date: [March 14, 2023, 1:47pm UTC](https://meta.discourse.org/t/search-filter-only-topics-only-posts/257994/8 "2023-03-14T13:47:52Z")

</div>

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 🙂
