検索結果が並び順によって異なる

ユーザーからの苦情を受けて、検索結果に検索語を含むすべての投稿が含まれていないことに気づきました。2018年のこのスレッドで、「最も評価が高い順」で並べ替えると確かにすべての投稿が返されることが言及されており、現在もその状態が続いていることを確認できました。

この動作は予期せず、意図されていないと思われます。この動作を変更するオプションは存在せず、ドキュメントにも記載がなく、UIにも検索結果が省略されていることを示す要素はありません。

/lib/search.rbからの抜粋:

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

これは、「最も評価が高い順」が他の検索順序と明確に異なって扱われている唯一の箇所であり、これが根本原因である可能性が高いです。

aggregate_searchは、投稿ではなくトピックを返す検索に対して適用されるものと思われますが、評価順で並べ替えない限り、すべての検索に適用されているようです。

「いいね!」 1

I believe Discourse has always grouped results by topics, since its first release, and it’s intentional because Discourse is a topic-based system. If the first topic has 20 matching posts, the next relevant topic could show up as result 21 instead of result 2. That would be frustrating if the first topic is not what you’re looking for.

There is another way around this beyond using “most liked,” you can add in:all-posts to your search.