FEATURE: add advanced order to search (PR #10385)

Similar to advanced_filter I introduced advanced_order.

I needed a new option because default orders are evaluated after advanced_filter so I couldn’t use it.

Also, that part is a little bit more generic

elsif word =~ /order:\w+/
  @order = word.gsub('order:', '').to_sym
nil

After those changes, I can use them in plugins in this way:

Search.advanced_order(:votes) do |posts|
  posts.reorder("COALESCE((SELECT dvvc.counter FROM discourse_voting_vote_counters dvvc WHERE dvvc.topic_id = subquery.topic_id), 0) DESC")
end

GitHub

      if word == 'l'

This change looks OK but I think we should expose this to plugins as part of the plugin API instead. Let us add a test for this change too.

minor but perhaps we can group the following tests under context 'plugin extensions' so that we can use fab! to create the posts?

    if @order
      advanced_order = Search.advanced_orders&.fetch(@order, nil)
      posts = advanced_order.call(posts) if advanced_order
    end