2012-01-16 7 views
1

Sunspotの検索結果をより小さい値からより大きな値に並べることを試みています。Sunspot order_byソート(nilの値が最後のもの)

order_by :price, :asc 

しかし、いくつかの商品には値段の指定がありません。彼らは結果の前に置かれます。それらを放置するのではなく、最後に表示する良い方法はありますか?

答えて

0

うんで価格フィールドの定義に属性「sortMissingLast = true」を追加し、あなたはこのように、のschema.xml内のフィールドにsortMissingLast = trueを何かを追加する必要がありますする必要があります

<schema name="sunspot" version="1.0"> 
    <types> 
    ... 
    <!-- My custom types --> 
    <fieldType name="sml_int" class="solr.SortableIntField" sortMissingLast="true" omitNorms="true"/> 
    </types> 
    <fields> 
    ... 
    <!-- My custom fields --> 
    <dynamicField name="*_sml_int" type="sml_int" multiValued="false" indexed="true"/> 
    </fields> 
    ... 
</schema> 

次に、あなたのコードの中で、あなたがこれを行うことができます:

class MyModel < ActiveRecord::Base 
    searchable do 
    integer :price, as: :price_sml_int 
    end 
end 
関連する問題