A couple of points:
* :select is meant to be passed through to ActiveRecord, and will mean
only the user_id column in the resulting instances will be populated -
which isn't exactly what you want.
* You don't need 'self.' in your define_index block
* What you could do is the following (I think I'm getting the hash
structure right):
Article.search_for_ids('').results[:matches].collect { |match|
match[:attributes]['user_id'] }
This will mean your database will not need to be queried at all.
--
Pat
On 31/08/2009, at 1:23 PM, mix wrote:
>
> Hi, i've this:
> has self.user_id, :as => :user_id, :type => :integer
>
> (i've also tried with indexes instead of has, but the result is the
> same)
>
> And i want to do this:
> Article.search('', :select => "user_id")
>
> i see from the dev.log that the sql query is done correctly:
>
> Querying Sphinx:
> Article Load (0.4ms) SELECT user_id FROM `articles` WHERE
> (`articles`.`id` IN
> (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20))
>
> But the result is
>
> [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
> nil, nil, nil, nil, nil, nil]
>
> When querying directly with find the result is different (and
> correct):
>
>>> Article
>>> .find_all_by_id
>>> ([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
>>> ]).map(&:user_id)
> => [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---