2011-04-25 64 views
0

我用thinking_sphinx搜索,我試圖讓該字段是根據體重分組輸出表(從set_property:field_weights)如何根據它們的重量對字段(在模板中)進行排序?

這define_block

define_index do 
    indexes status, title, content, manager, note, start_date, end_date 
    has created_at, updated_at, parent_id, organization_id 

    has user_id, :as => :user_id, :type => :integer 

    has '7', :as => :model_order, :type => :integer 

    set_property :field_weights => { 
     :title => 1, 
     :start_date => 2, 
     :user_id => 7 
    } 

    set_property :delta => true 
    end 

如何到現場進行排序(在模板中)取決於他們的體重?

回答

0

我不確定我是否理解Q,但似乎您正試圖從視圖中讀取field_weights的配置... 我不知道如果thinking_sphinx有一個方法可以做到這一點,但我會做的是elsewere保存配置,並在你需要它使用它...

class YourModel 
    FieldWeights = { 
     :title => 1, 
     :start_date => 2, 
     :user_id => 7 
    } 
    # more code here.... 

    define_index do 
    indexes status, title, content, manager, note, start_date, end_date 
    has created_at, updated_at, parent_id, organization_id 

    has user_id, :as => :user_id, :type => :integer 

    has '7', :as => :model_order, :type => :integer 

    set_property :field_weights => YourModel::FieldWeights 

    set_property :delta => true 
    end 
end 

然後在您的視圖中,可以使用YourModel :: FieldWeights在其權重的順序顯示的字段,例如:

YourModel::FieldWeight.invert.sort 
相關問題