如何根据字段的权重对字段(在模板中)进行排序?

发布于 2024-11-03 12:45:08 字数 593 浏览 4 评论 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

如何根据字段的权重对字段(在模板中)进行排序?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

霞映澄塘 2024-11-10 12:45:10

我不确定我是否理解问题,但似乎您正在尝试从视图中读取 field_weights 的配置...
我不知道 Thinking_sphinx 是否有方法可以做到这一点,但我要做的就是保存该配置并在需要的地方使用它...

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文