This was discussed in a chat room, and we figured out a solution that works for ordering by prices of specific price types by putting the following within the index definition:
PriceType.all.each do |price_type|
has "(CASE WHEN prices_#{price_type.id} IS NOT NULL THEN prices_#{price_type.id}.value ELSE NULL END)", as: "price_type_#{price_type.id}".to_sym, type: :float
join "LEFT OUTER JOIN prices AS prices_#{price_type.id} ON prices_#{price_type.id}.product_id = products.id AND prices_#{price_type.id}.price_type_id = #{price_type.id}"
group_by "price_type_#{price_type.id}"
end
This is not particularly ideal from a performance perspective - and the Sphinx setup will need to be rebuilt every time a new PriceType is added to the system. However, if this is not a common occurrence, and there's not too many of them, it's a feasible solution.