Firstly, you'll want service type ids as a multi-value attribute in your Service index definition:
ThinkingSphinx::Index.define(:service, :with => :active_record) do
# ... existing index definition
has service_types.id, :as => :service_type_ids
end
And then you can search and use that attribute:
Service.search(:with => {:service_type_ids => 54})
If you want to wrap that into something like an ActiveRecord scope, Thinking Sphinx has its own scope functionality (the two cannot be combined, as ActiveRecord works with databases querying with SQL, but Sphinx scopes work with Sphinx querying with SphinxQL - similar, but not quite the same).
# include this in your model:
include ThinkingSphinx::Scopes
sphinx_scope(:search_by_service_type) { |ids|
{:with => {:service_type_ids => ids}}
}
And then searching:
Service.search_by_service_type(54)
# You can chain further search arguments onto the scope:
Service.search_by_service_type(54).search('foo', :order => 'created_at DESC')