【问题标题】:Thinking Sphinx name of facets思考狮身人面像的刻面名称
【发布时间】:2013-04-24 09:18:52
【问题描述】:

我已经为产品模型定义了这样的方面:

product_index.erb

ThinkingSphinx::Index.define :product, :with => :active_record do  
  indexes publish
  indexes name, :sortable => true
  indexes price, :sortable => true
  indexes manufacturer.permalink, :as => :manufacturer, :facet => true
  has manufacturer_id
end

以及考虑的方面:

<% @facets.each do |facet, facet_options| %>
<h5><%= facet %></h5>
<ul>
    <% facet_options.each do |option, count| %>
    <li><%= link_to "#{option} (#{count})",
    :params => {facet => option, :page => 1} %></li>
    <% end %>
</ul>

这是为这样的制造商生成方面:

制造商

如何为标题添加自己的名称(例如,将 ma​​nufacturer 替换为 Brand)并为链接添加自己的名称(例如,将 Manufacturer-permalink (53) 替换为 Manufacturer.name ( 53)(其中制造商是模型类))

【问题讨论】:

    标签: ruby-on-rails sphinx thinking-sphinx faceted-search


    【解决方案1】:

    我为此目的写了一些东西 - 将外键方面翻译成它们对应的对象。你可以在这里找到代码:https://gist.github.com/pat/5477820

    您需要清楚要遍历哪些方面 - 否则您最终会在 HTML 中同时列出制造商 ID 和制造商。

    在构面搜索查询之后,您的控制器可能会执行以下操作:

    FacetExpander.expand @facets, :manufacturer
    

    那么在你看来:

    <h5>Manufacturers</h5>
    <ul>
      <% @facets[:manufacturers].each do |manufacturer, count| %>
      <li><%= link_to "#{manufacturer.name} (#{count})",
        :params => {:manufacturer_id => manufacturer.id, :page => 1} %></li>
      <% end %>
    </ul>
    

    【讨论】:

      猜你喜欢
      • 2014-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多