2

Sunspot と Mongoid を使用しています。関連性 (スコア) 値で並べ替え、次にイベントの日付で並べ替える必要があります。これを行うには、次のことを行う必要があります

Article.search do
  keywords params[:query]
  order_by :score, :desc
  order_by :article_date, :asc
end

しかし、それはそれに応じて機能しません。代わりに、article_date で並べ替えます。article_date を削除すると、スコアに従って適切にソートされます。article_date と別のフィールド (スコアではなくタイトルなど) を使用して並べ替えると、正常に機能します。

ここに私の宝石のバージョンがあります

sunspot (1.3.0) を使用する sunspot_rails (1.3.0) を使用する sunspot_mongoid (0.4.1) を使用する sunspot_solr (1.3.0) を使用する

ここでの例に基づいて作業を行いました: Solr/Lucene is it possible to order to order by relevance, then by a second attribute? また、太陽黒点のドキュメントhttp://sunspot.github.com/sunspot/docs

何か案が?

[アップデート]

これは、ヒットではなく結果をループすることに関連している可能性があると考えて、両方のシナリオを試しました。

Post.search.results.each do |result|
AND
Post.search.each_hit_with_result do |hit, result|

ああ、同じこと。

4

0 に答える 0