Figured this out.
Also, sorry for the illustrations above.
The one in "a) this works" should have read:
Started POST "/search" for ... at 2012-06-03 19:54:44 -0700
> Processing by SearchController#perform_search as HTML
> Parameters: {"utf8"=>"รข", "fit"=>{"make_id"=>"", "vehicle_id"=>""},
> "search"=>{"category_id"=>"1", "sub_category_id"=>""}, "commit"=>"Search"}
> Sphinx Query (3.0ms)
> Sphinx Found 3 results
> Part Load (0.4ms) SELECT `parts`.* FROM `parts` WHERE `parts`.`id` IN
> (2, 3, 4)
> Rendered search/results.html.erb within layouts/application (0.7ms)
> Completed 200 OK in 93ms (Views: 7.2ms | ActiveRecord: 3.2ms | Sphinx:
> 3.0ms)
Anyway, from my observations,
1. when the query is successful, I observed the Sphinx Query does not
have any parameters.
- successful query: Sphinx Query (3.0ms)
- unsuccessful query: Sphinx Query (3.0ms) {"category_id"=>"1",
"sub_category_id"=>""
2. I then dug deeper and read field conditions in the
documentation<http://freelancing-god.github.com/ts/en/searching.html> of
thinking sphinx. I changed the syntax to use :condition and it works as
required.
# Thinking sphinx's search() method freaks out when elements are not
> # populated (ie. is ""). We sanitize the search parameters handed
> to
> # ts' search() method before anything is done.
> params[:search].each do |key, value|
> if value.nil? or value == "" then
> params[:search].delete(key)
> end
> end
> # Perform search in descending order of the update timestamp
> @search = Part.search :conditions => params[:search],
> :page => params[:page],
> :sort_by => 'updated_at',
> :sort_mode => 'desc'
> end
Thank you, all :)
--
You received this message because you are subscribed to the Google Groups
"Thinking Sphinx" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/thinking-sphinx/-/AluNVyzSiD4J.
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.