Two things to keep in mind:
* You need to tell TS to join on your series association
* You will need to reference that joined table in your SQL snippet.
So, if the table is called series_medias:
join series
has 'IF(medias.series_id IS NULL, medias.num_votes, series_medias.num_votes)',
:as => :sort_media_rank, :type => :integer
Give that a shot, let us know how you go.
Cheers
--
Pat
On 17/02/2011, at 9:14 AM, p. wrote:
> class Media < ActiveRecord::Base
> belongs_to :series, :class_name => 'Media', :foreign_key => 'series_id'
>
> define_index do
> indexes title
> has 'IF(series_id, series_id, id)', :type => :integer, :as =>
> :parent_media
> end
>
> end
>
> Okay, basically i have a media class that is self-referencing, which is to
> say that a record may or may not point to another record through the
> series_id FK - this series_id can be null. Each record has a num_votes
> column.
>
> What I'd like to do when indexing is use the num_votes of the series IF there
> is a related series record and if not use the num_votes of the current
> record. So far, I have tried these:
>
> has 'IF(series_id, series_medias.num_votes, num_votes)', :type => :integer,
> :as => :sort_media_rank
> has series ? series(:num_votes) : :num_votes
>
> is it even possible to do a conditional for a has clause?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Thinking Sphinx" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/thinking-sphinx?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/thinking-sphinx?hl=en.