3

I have an application, that uses thinking sphinx for search and I can get facets to show up in the view correctly, but the links are not returning a list of the results with the given options. Here is the code that I have for the model controller and view:

The Controller:

@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

The Model:

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

The View:

<% @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 %>

I can get the correct results if I include the facet options in the value portion of the ":with =>" hash. However I am unsure how to configure the links so it performs another search, and inserts that value into the controller code. Any help would be appreciated.

tomciopp
  • 2,602
  • 2
  • 31
  • 60

1 Answers1

0

At a glance, it looks like the line

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

Should instead read

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

With these changes:

  • <%= has no closing tag
  • :params hash is missing the symbol identifier : before facet

However I'm not sure if that answers your question.

It sounds like you need to do the following:

  1. Embed the Thinking Sphinx parameters into the link_to tag.
  2. In the controller, use logic to handle the parameters, add then them to the :with hash.

The logic might include error checking, formatting, validation, et cetera.

fdsaas
  • 714
  • 4
  • 10