Search by ID, no keyword. Tried using :conditions but no result ouput.

Posted by Victor on Stack Overflow See other posts from Stack Overflow or by Victor
Published on 2011-01-15T07:39:49Z Indexed on 2011/01/15 7:53 UTC
Read the original article Hit count: 204

Using Thinking Sphinx, Rails 2.3.8.

I don't have a keyword to search, but I wanna search by shop_id which is indexed. Here's my code:

  @country = Country.search '', {
    :with           => {:shop_id => params[:shop_id]},
    :group_by       => 'trip_id',
    :group_function => :attr,
    :page           => params[:page]
  }

The one above works. But I thought the '' is rather redundant. So I replaced it with :conditions resulting as:

  @country = Country.search :conditions => {
    :with           => {:shop_id => params[:shop_id]},
    :group_by       => 'trip_id',
    :group_function => :attr,
    :page           => params[:page]
  }

But then it gives 0 result. What is the correct code?

Thanks.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about thinking-sphinx