# Search Results Differ by Sort Order

**URL:** <https://meta.discourse.org/t/search-results-differ-by-sort-order/417674>\
**Category:** Bug\
**Tags:** search\
**Created:** [17 november 2026 om 18:41 UTC](https://meta.discourse.org/t/search-results-differ-by-sort-order/417674 "2026-11-17T18:41:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carleas](https://avatars.discourse-cdn.com/v4/letter/c/57b2e6/32.png) [@Carleas](https://meta.discourse.org/u/Carleas)\
**Post date:** [17 november 2026 om 18:41 UTC](https://meta.discourse.org/t/search-results-differ-by-sort-order/417674/1 "2026-11-17T18:41:18Z")

</div>

After user complaints, I noticed that search results do not include all posts containing the search terms. I found [this from 2018](https://meta.discourse.org/t/seeing-multiple-posts-per-topic-in-search-results/83782) mentioning that sorting by ‘Most Liked’ _does_ return all posts, which I can confirm is still the case.

This behavior is unexpected, and seems unintended. There is no option to change this behavior, nothing in the docs about it, and nothing in the UI suggests that search results have been omitted.

From `/lib/search.rb`:

```ruby
def aggregate_post_sql(opts)
    ...
    query =
      if @order == :likes
        # likes are a pain to aggregate so skip
        posts_query(limit, type_filter: opts[:type_filter]).select("topics.id", "posts.post_number")
      else
        posts_query(limit, aggregate_search: true, type_filter: opts[:type_filter]).select(
          "topics.id",
          "#{min_or_max}(posts.post_number) post_number",
        ).group("topics.id")
      end
      ...
end

```

This is the only place where ‘Most Liked’ is clearly treated differently from other search orderings, so it’s probably the root cause.

It looks like `aggregate_search` is intended to be applied when a search should return topics instead of posts, but it’s being applied to all searches unless sorted by likes.
