Thinking Sphinx, Filter conditions with a has_many relationship

Hello all,

I just started using Sphinx for full text search. It works very well, but I can't figure out how to set a condition for a has_many relationship.

For example, I have a Game model, and it has a habtm relationship with Category. I want to search all games, but filter all results by a particular category. Without sphinx, you would do this by

    Game.all :conditions => { "categories_games.category_id" => 1 }, :include => :categories

This works fine, but when I try to do this, it doesn't work

    Game.search params[:q], :conditions => { "categories_games.category_id" => 1 }, :include => :categories

This is understandable, because for conditions to work with sphinx, they have to be indexed. If I add the following to the index

    has players

I can do this

   Game.search params[:q], :conditions => { :players => 2 }

Apparently, the way to index a habtm relationship is

   has categories(:id), :as => :category_ids

But I have no idea how to add it to the search. The conditions thing I mentioned above doesn't work, neither does setting :category_ids => 1 in my conditions.

How can I do this? Thanks! ~sean

Example: http://pastie.textmate.org/247713

Anyone know anything about sphinx? Am I asking questions wrong? This is like the 3rd question in a row that has gone unanswered.

Hi Sean, please join the thinking-sphinx mailing list:

http://groups.google.com/group/thinking-sphinx

Thanks xavier!

I found my answer very quickly in the sphinx group, but for reference, all I needed to do was to change

Game.search params[:q], :conditions =>

{ “categories_games.category_id” => 1 }, :include => :categories

to

Game.search params[:q], :with => { :category_ids => 1 }

And keep the index the same. Thanks again Xavier!