3

検索に思考スフィンクスを使用するアプリケーションがあり、ファセットをビューに正しく表示できますが、リンクが指定されたオプションの結果のリストを返していません。モデルコントローラーとビュー用に持っているコードは次のとおりです。

コントローラー:

@facets = Load.facets(
  (params[:trucks]),
  :page => (params[:page] || 1),
  :per_page => 25,
  :geo => degrees_to_radians(@location),
  :with => { "@geodist" => 0.0..miles_to_meters(params[:radius].to_i) },
  :sort_mode => :expr,
  :order => sort_by_select(params[:sort])
  )
  @results = @facets.for

モデル:

define_index do 
  indexes commodity
  indexes truck_type
  has latitude, longitude
  has distance, :facet => true
  has weight, :facet => true
  has current_asking_price, :facet => true
  has created_at, :facet => true
  where sanitize_sql(["active", true])
  set_property :delta => :delayed
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>
<% end %>

「:with =>」ハッシュの値の部分にファセットオプションを含めると、正しい結果を得ることができます。ただし、リンクを構成して別の検索を実行し、その値をコントローラーコードに挿入する方法がわかりません。どんな助けでもいただければ幸いです。

4

1 に答える 1

0

一見、ラインのように見えます

<li><%= link_to "#{option} (#{count})", :params => {facet => option, :page => 1}</li>

代わりに読むべき

<li><%= link_to "#{option} (#{count})", :params => {:facet => option, :page => 1} %></li>

これらの変更により:

  • <%=終了タグがない
  • :params:ハッシュの前にシンボル識別子がありませんfacet

ただし、それがあなたの質問に答えているかどうかはわかりません。

次のことを行う必要があるようです。

  1. link_toThinking Sphinx パラメータをタグに埋め込みます。
  2. コントローラーでは、ロジックを使用してパラメーターを処理し、:withハッシュに追加します。

ロジックには、エラー チェック、書式設定、検証などが含まれる場合があります

于 2012-06-19T23:07:28.050 に答える