تختلف نتائج البحث حسب ترتيب الفرز

بعد شكاوى المستخدمين، لاحظت أن نتائج البحث لا تتضمن جميع المنشورات التي تحتوي على كلمات البحث. وجدت هذا المنشور من عام 2018 يشير إلى أن الفرز حسب ‘الأكثر إعجاباً’ يقوم فعلاً بإرجاع جميع المنشورات، ويمكنني التأكيد بأن هذا لا يزال هو الحال.

هذا السلوك غير متوقع، ويبدو أنه غير مقصود. لا يوجد خيار لتغيير هذا السلوك، ولا يوجد أي ذكر له في الوثائق، ولا يشير أي عنصر في واجهة المستخدم إلى أنه قد تم استبعاد بعض نتائج البحث.

من الملف /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.