Hi Pat,

I'm using the following:

Rails 2.3.8, Sphinx 1.10-beta, TS 1.3.20

If you looked at the code below, I would like to search Spots
(different model) name, city, state, country listed in Trips. Somehow
my search filter only works on the name of the Trip, but not the spots
in it.

trip.rb
=====
class Trip < ActiveRecord::Base
  has_many :spots, :through => :spot_trips

 # ThinkingSphinx Index
  define_index do
    indexes :name, :sortable => true
    indexes duration
    indexes spots.name, :as => :spot_name
    indexes spots.city, :as => :spot_city
    indexes spots.state, :as => :spot_state
    indexes spots.country, :as => :spot_country
    has budget, created_at, rating_average
  end
end



trips_controller.rb
=======
class TripsController < ApplicationController
  before_filter :require_user, :except => [:show, :index]

  def index
    if params[:filter] == 'on'
      country = params[:country] == 'All' ? {} : {:spot_country =>
params[:country]}
      duration = params[:days].blank? ? "" : params[:days]

      if !duration.blank? && country
        conditions = {:duration => duration}.merge(country)
      elsif !duration.blank? && country.blank?
        conditions = {:duration => duration}
      else country && duration.blank?
        conditions = country
      end

      keyword = params[:keyword].blank? ? "" : params[:keyword]

      case params[:order]
      when 'date_descend'
        order = {:order => 'created_at DESC'}
      when 'date_ascend'
        order = {:order => 'created_at ASC'}
      when 'rating_descend'
        order = {:order => 'rating_average DESC'}
      when 'rating_ascend'
        order = {:order => 'rating_average ASC'}
      when 'budget_dscend'
        order = {:order => 'budget DESC'}
      when 'budget_ascend'
        order = {:order => 'budget ASC'}
      else
        order = {}
      end

      results = Trip.search params[:keyword], {:conditions =>
conditions, :star => true}.merge(order)
      @trips = results.paginate(:page => params[:page])
    else
      @trips = Trip.paginate(:all, :page => params[:page], :order =>
'created_at DESC')
    end
  end


index.html.erb for trip
=====
I have these for filters:

<%= text_field_tag 'keyword' %>
<select name="country">
  <option>All</option>
  <option value="Afghanistan">Afghanistan</option>
  .
  .
</select>
<input class="duration" name="days" />
<select name="order">
  <option value="date_descend" <%= params[:order] == 'date_dscend' ?
'selected' : ''%>>
    Date: Latest to earliest
  </option>
  <option value="date_ascend" <%= params[:order] == 'date_ascend' ?
'selected' : ''%>>
    Date: Earliest to latest
  </option>
  <option value="rating_descend" <%= params[:order] ==
'rating_descend' ? 'selected' : ''%>>
    Rating: Highest to lowest
  </option>
  <option value="rating_ascend" <%= params[:order] ==
'rating_ascend' ? 'selected' : ''%>>
    Rating: Lowest to highest
  </option>
</select>

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.

Reply via email to