Hi Alex
Firstly: if you want to sort by cost, it's going to work correctly when cost is
an attribute, not a field - when it's a field, it just gets treated as a
string, not a number.
Secondly, if you want to match by specific fields, use the :conditions hash:
Tour.search :conditions => {:country => 'Australia'}
And for a cost range (if it's an attribute - not possible if it's a field):
Tour.search :with => {:cost => 10.0..50.0}
Hope this helps
--
Pat
On 22/08/2013, at 3:57 PM, alex wrote:
> I want to be able to do an advanced search (basically just include Name,
> Cost, Direction and Country to the search as filters)
>
> My search form looks like this:
>
> <%= form_tag tours_path, method: :get do %>
> <%= text_field_tag :query, params[:query] %>
> <%= select_tag "engine", options_for_select(["elastic", "sphinx"]) %>
> <%= submit_tag "Search", name: nil, class: "btn btn-mini btn-success" %>
> <br>
> Name: <%= text_field_tag :name %><br>
> Cost: from <%= text_field_tag :cost_from %> to <%= text_field_tag :cost_to
> %><br>
> Direction: <%= text_field_tag :direction %><br>
> Country: <%= text_field_tag :country, %><br>
> <% end %>
>
>
> tours_controller:
>
> def index
> if params[:engine] == "elastic"
> @tours = Tour.tire.search(params[:query], load: true)
> elsif params[:engine] == "sphinx"
> @tours = Tour.search (params[:query])
> else
> @tours = Tour.all
> end
> end
>
> I tried something like this: Tour.search "#{params[:query]}#{params[:name]}",
> :match_mode => :all , but it didn't work
>
> /indices/tour_index.rb
>
> ThinkingSphinx::Index.define :tour, :with => :active_record do
> #fields
>
> indexes summary
> indexes country, direction, cost, sortable: true
> indexes :name, sortable: true
>
> # attributes
> #has cost
>
> end
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Thinking Sphinx" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/thinking-sphinx.
> For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups
"Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/groups/opt_out.