How to sort the field (in the template) depending on their weight?
I use thinking_sphinx for search, and i'm trying to get the output table in which fields are grouped according to weight(from set_property :field_weights)
This 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
How to sort the field (in the template) depending on their weight?
I'm not sure if I understand the Q, but it seems that you are trying to read the configuration of the field_weights from the view... I don't know if thinking_sphinx has a method to do that, but what I would do is save that configuration elsewere and use it where you need it...
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
Then in your view you can use YourModel::FieldWeights to display the fields in order of their weights, for example:
YourModel::FieldWeight.invert.sort
精彩评论