ruby on rails - Thinking Sphinx: how to return any attribute when attribute query is blank -



ruby on rails - Thinking Sphinx: how to return any attribute when attribute query is blank -

i have search form user can search article content , narrow downwards using select box categories. when category param blank, searches blank id, i'd homecoming category in case. possible configure thinking sphinx accomplish or have include status on controller?

article model:

class article < activerecord::base belongs_to :category define_index indexes :name indexes content has category(:id), :as => :category_id end ... end

searchcontroller:

@articles = article.search params[:q], :with => {:category_id => params[:category]}

for sphinx, nils/nulls treated 0's, if no params[:category] value passed through controller, it's best if don't pass through filter on attribute. this, perhaps:

filters = {} filters[:category_id] = params[:category] if params[:category].present? @articles = article.search params[:q], :with => filters

ruby-on-rails thinking-sphinx

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -