Thanks Pat!

Indeed, I ended up doing kind of like what you first suggest here. The real 
epiphany came when I realized I could point one association to another, 
thus going through more than one table. Never tried that before. :-)

Thanks,
Roger


kl. 18:19:53 UTC+2 søndag 29. juni 2014 skrev Pat Allan følgende:
>
> Hi Roger
>
> Sounds like your idea of sorting by the lowest price per dentist (if 
> searching on the Dentist model directly) is the best bet - you’ll want to 
> have a SQL snippet with that aggregate in your index definition:
>
>   has “MIN(procedure_prices.price)”, as: :procedure_price, type: :float
>
> Another option would be to have an index on your ProcedurePrice model 
> (which can pull in organisations, dentist details), and search on that 
> instead. Depends what else the search involves, I guess.
>
> Hope this is helpful!
>
> — 
> Pat
>
> On 20 Jun 2014, at 11:11 am, Roger Kind Kristiansen <[email protected] 
> <javascript:>> wrote:
>
> Hopefully it's just that my cases keep getting a bit more complex, but I 
> never quite seem to get the hang of the indexing. Again it would be great 
> with some advice from someone smarter than me, so I'm trying my luck here 
> again:
>
> I have a bunch of Dentists, who performs many different Procedures. The 
> prices of the procedures belong to the organization/clinic the dentist 
> works at.
>
> Now I have a dentist index, to which I'd like to add support for sorting 
> by the price of a given procedure. Since a dentist might be connected to 
> multiple practices, I'm thinking of restricting sorting to the lowest 
> priced entry. Since this includes quite a few more steps than what I've 
> encountered so far I have been unable to wrap my head around how to do this.
>
> The simplified data model looks somewhat like this:
>
> class Dentist < Person
>   has_many :organizations, through: :person_organizations
> end
>
> class Organization
>   has_many :prices, class_name: 'ProcedurePrice'
> end
>
> class ProcedurePrice
>   attr_accessible :price
>   belongs_to :procedure
> end
>
> class Procedure
>   attr_accessible :name
> end
>     
>
> Any ideas on how to solve this?
>
> Cheers,
> Roger
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] <javascript:>.
> To post to this group, send email to [email protected] 
> <javascript:>.
> Visit this group at http://groups.google.com/group/thinking-sphinx.
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/d/optout.

Reply via email to