# Search results should prioritize first post in topic when title matches search term

**URL:** https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154
**Category:** Feature
**Created:** [January 5, 2021, 1:15pm UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154 "2021-01-05T13:15:39Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [January 19, 2021, 6:09am UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/22 "2021-01-19T06:09:31Z")

</div>

So there is absolutely no way to tell in the search index if the post is the first post?

> [@tgxworld](#):
>
> Revert to old behaviour. When multiple posts in a topic matches a given search term, always pick the post with the smallest post number. The downside here is that the smallest post number may not always be the first post and our search result may end up being poor when that is the case. There are also cases where a post’s body is obviously a much better match but ends up being excluded just because another post with a lower post number in the topic also matches the search terms.

What about this kind of tweak:

> When multiple posts in a topic matches a given search term, AND ONE OF THE POSTS IS THE FIRST POST give that specific post, the one that is the first post, a huge bump in search ranking.

Then you avoid a mindless “order by post number” behavior, while properly giving the first post priority?

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [January 19, 2021, 6:45am UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/23 "2021-01-19T06:45:49Z")

</div>

> [@codinghorror](#):
>
> So there is absolutely no way to tell in the search index if the post is the first post?

Currently no but it wouldn’t be hard to add since it is similar to an optimisation I did last year to allow us to filter the `PostSearchIndex` by PM or not PM.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [January 27, 2021, 9:23pm UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/24 "2021-01-27T21:23:30Z")

</div>

My call here would be that the theoretic benefit of accurate in topic ranking of duplicates has way too many downsides.

- People could be using search like a bookmark and get confused when a search that always took them to #77 now takes them to #892

- Pouring oil on fire, we have no mechanism for “going to first unread in a topic” so prioritizing later posts comes with a big downside that the odds are higher you would create reading gaps (EG. you read 1,2,3 but did not read 4-88 … now you hit 89)

I much prefer to just unconditionally prioritize the first hit in a topic, it is simpler to explain and much more stable.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [January 27, 2021, 11:00pm UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/25 "2021-01-27T23:00:57Z")

</div>

> [@sam](#):
>
> I much prefer to just unconditionally prioritize the first hit in a topic, it is simpler to explain and much more stable.

I agree and that solution works for me 👍

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [January 28, 2021, 4:53am UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/26 "2021-01-28T04:53:20Z")

</div>

> [@sam](#):
>
> I much prefer to just unconditionally prioritize the first hit in a topic, it is simpler to explain and much more stable.

Do we use the ranking of the first hit or do we use the ranking of the best post in the topic? We used to be doing the latter which seems incorrect because we were taking the ranking of a post that will not appear in the search result to be ranked against posts of other topics.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [January 28, 2021, 5:01am UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/27 "2021-01-28T05:01:46Z")

</div>

> [@tgxworld](#):
>
> Do we use the ranking of the first hit or do we use the ranking of the best post in the topic?

I would say for we link to `MIN(post_number)` and we rank on `MAX(rank)` when doing the aggregate stuff.

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [February 1, 2021, 5:53am UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/28 "2021-02-01T05:53:06Z")

</div>

The new behaviour has been reverted in

[https://github.com/discourse/discourse/pull/11914](https://github.com/discourse/discourse/pull/11914)

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [February 15, 2021, 12:00am UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/29 "2021-02-15T00:00:01Z")

</div>

This topic was automatically closed after 6 days. New replies are no longer allowed.

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [February 19, 2021, 2:01pm UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/30 "2021-02-19T14:01:14Z")

</div>



---

<div class="post-metadata">

### Author: ![seanblue](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@seanblue](https://meta.discourse.org/u/seanblue)
#### Post date: [February 19, 2021, 7:01pm UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/31 "2021-02-19T19:01:40Z")

</div>

Thanks for reopening the topic. I think there is still an issue related to this. On [https://community.wanikani.com](https://community.wanikani.com), there is a topic titled “General Anime Thread”. If I search for “general anime” I get this topic as the top result, but it goes to [post 511](https://community.wanikani.com/t/general-anime-thread/18709/511). What’s particularly odd is that this post doesn’t even contain the words “general” or “anime”. So somehow this seems even worse that the originally reported issue. [https://community.wanikani.com](https://community.wanikani.com) should be on a version after this fix was merged, as far as I can tell.

To give a second example, if I search for “japanese book club”, I get [post 925](https://community.wanikani.com/t/intermediate-japanese-book-club-currently-reading-%E5%90%9B%E3%81%AE%E5%90%8D%E3%81%AF/18908/925) of that topic, even though the search term is in the title of the topic.

I’ve tried to reproduce on meta, but I haven’t been able to. It could just be the specific terms I’ve tried searching for though.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [February 21, 2021, 1:04am UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/32 "2021-02-21T01:04:46Z")

</div>

Did you check the version by viewing source? If you cannot repro here, it is likely a version mismatch.

---

<div class="post-metadata">

### Author: ![seanblue](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@seanblue](https://meta.discourse.org/u/seanblue)
#### Post date: [February 21, 2021, 1:32am UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/33 "2021-02-21T01:32:36Z")

</div>

This is from the page source:

```plaintext
Discourse 2.7.0.beta4 - https://github.com/discourse/discourse version 47835ade9a3dcebb14bdd744e92d93b9c9199b90

```

That commit is from two days ago, and I can still reproduce this issue with the examples in my last post.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 23, 2021, 4:58am UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/34 "2021-02-23T04:58:06Z")

</div>

Thanks for the very detailed report, @tgxworld will have a quick look!

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [February 23, 2021, 8:38am UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/36 "2021-02-23T08:38:30Z")

</div>

@sam I know what this is. We have a search performance optimisation on large sites where we only search through a partial index. Since the first post is really old, it is left out of the partial index which is why we’re not linking to the first post. I’ll need to think about the fix for this because the solutions I have in mind currently either trade-off performance for accuracy or accuracy for performance.

---

<div class="post-metadata">

### Author: ![seanblue](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@seanblue](https://meta.discourse.org/u/seanblue)
#### Post date: [February 23, 2021, 6:57pm UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/37 "2021-02-23T18:57:01Z")

</div>

Would it be reasonable (in performance trade off) if every topic’s first post was included in the index? Or maybe just the first post of every topic _if_ the topic has a post within the optimized time range? Assuming that last one is even feasible from a database perspective.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 23, 2021, 8:14pm UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/38 "2021-02-23T20:14:42Z")

</div>

This is technically feasible but a monster of a problem

I am afraid that the trade off of spending say 1 week of careful index shuffling may not be worth it when it comes to correcting this

I can also think of plenty outlier situations that complicate this (like a forum with mountains of short topics)

Let’s wait on this for a bit and see how often it pops up

One interim change we can probably afford on your forum is doubling the size of your recent index, this is configurable (@tgxworld maybe make it so)

---

<div class="post-metadata">

### Author: ![seanblue](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@seanblue](https://meta.discourse.org/u/seanblue)
#### Post date: [February 23, 2021, 9:57pm UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/39 "2021-02-23T21:57:40Z")

</div>

> [@sam](#):
>
> One interim change we can probably afford on your forum is doubling the size of your recent index, this is configurable (@tgxworld maybe make it so)

Thanks! If you think it’s safe to do, that would be great!

---

<div class="post-metadata">

### Author: ![seanblue](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@seanblue](https://meta.discourse.org/u/seanblue)
#### Post date: [March 7, 2021, 2:53am UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/40 "2021-03-07T02:53:32Z")

</div>

> [@sam](#):
>
> One interim change we can probably afford on your forum is doubling the size of your recent index, this is configurable

Was this ever done? Searching for the previously mentioned topic now goes to post 523 instead of 511, which seems to indicate more and more posts going out of range of the index.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [March 8, 2021, 1:06am UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/41 "2021-03-08T01:06:15Z")

</div>

Hi Sean, sorry it was not raised.

I just changed it (`SiteSetting.search_recent_posts_size`) to 250k, you only have 163k topics. It will take a couple of days for the change to kick in, a scheduled job needs to run.

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [March 8, 2021, 1:20am UTC](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/42 "2021-03-08T01:20:03Z")

</div>

I belive the changes have already kicked in. I changed it to 1 million previously but forgot to post an update here.

@sam Do we plan to tackle this problem at some point? Including all first post in the partial index doesn’t sound like a bad trade-off. I know from previous discussions that @codinghorror believes that search should heavily prioritise topics first before allowing posts within a topic to show up.

[Previous page](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154.md?page=1)

[Next page](https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154.md?page=3)
