Hi Zach
Can't spot anything obviously wrong with what you're doing thus far... though
I'm guessing in your console output you actually typed 'total_amount' instead
of 'total_flow' in the attribute check? Or the attribute is actually called
total_flow?
--
Pat
On 28/11/2010, at 9:59 AM, Zach Brock wrote:
> I'm trying to index an aggregate function result on a model. There's
> a User class with many Payments. Each payment has an amount_cents
> column.
>
> class User < ActiveRecord::Base
> has_many :payments
>
> define_index do
> indexes :name
> has :created_at
> has "SUM(payments.amount_cents)", :as => :total_amount, :type
> => :integer
> join payments
> end
> end
>
> The values that I'm seeing indexed are just totally wrong.
>
> ree-1.8.7-2010.02 > client =
> ThinkingSphinx::Configuration.instance.client
> ree-1.8.7-2010.02 > first_match = client.query("Pamela", "user")
> [:matches].first
> ree-1.8.7-2010.02 > first_match[:attributes]["total_flow"]
> => 10995990
> ree-1.8.7-2010.02 > first_match[:attributes]["sphinx_internal_id"]
> => 64
> ree-1.8.7-2010.02 > User.find(64).name
> => "Pamela Woods"
> ree-1.8.7-2010.02 > User.find(64).payments.sum(:amount_cents)
> => 150630
>
> I tried the SQL that is generated in my development.sphinx.conf and it
> looks like it should be working correctly. Is there a trick to
> working with aggregate functions when indexing? I suppose I could
> denormalize the total amount onto user to make it easier to index. Is
> there a better way?
>
> --
> 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.