Nevermind, I found it on another thread.  I knew that I needed to
group, just wasn't sure how to access the count info.  There appear to
be iterator functions attached to the result set of the following
kind: each_with_group_by_and_count, each_with_group_by, and
each_with_count.  Didn't see these in the docs (that doesn't mean they
weren't there :)) So I thought I would post the solution.

Thanks.
-=Josh

On Mar 29, 2:52 pm, Josh <[email protected]> wrote:
> The latter is what I am looking for thanks.  It was slightly more
> complicated because I was trying to compute set of items that were
> virtual (all books in category X that a user DOESN'T have), but I
> setup my associations such that thinking _sphinx just worked--
> awesome.  Is there an efficient way to get the number of books that
> matched the query in those results, so as to order by the user that
> has the most books that match "foo" and display that he has 10 of
> them?
>
> Thanks again Pat,
> -=Josh
>
> On Mar 28, 12:16 am, Pat Allan <[email protected]> wrote:
>
> > Hi Josh
>
> > I'm not quite sure what you're after... do you want to search by a specific 
> > book on users attached to that book? ie:
> >   book.users.search 'foo'
>
> > This is doable - you'll need the book id as an attribute in the User model, 
> > though. I think this will do the job:
>
> >   has join_class.books(:id), :as => :book_ids
>
> > Or, do you want to search for users using search terms from the books 
> > they're attached to?
>
> >   user.books << Book.create :name => 'foo bar'
> >   user.books << Book.create :name => 'foo baz'
> >   user.save
>
> >   User.search 'foo' # should return user
>
> > This is easy enough, because - like in the attribute example above - you 
> > can pull in data from associations:
>
> >   indexes books.name, :as => :book_names
>
> > Or are you after something different to either of those situations?
>
> > --
> > Pat
>
> > On 27/03/2010, at 1:23 PM, Josh wrote:
>
> > > I am trying to figure out the best way to achieve the following and
> > > would appreciate any input:
>
> > > class foo
> > >  has_many bars, :though => :join_class
> > > end
>
> > > class bar
> > >  has_many :foos, :through => :join_class
>
> > >  define_index do
> > >    indexes :name
> > >    indexes :description
> > >  end
> > > end
>
> > > I want to search through bars and show in the results the foo's that
> > > have them.  For example a user has many books, I would like to search
> > > through books and return the users that have them.
>
> > > What is the best index configuration to achieve this? Because I want
> > > to get foo's it seems I should build an index on that, but I am not
> > > sure what to index.
>
> > > Thanks,
> > > -=Josh
>
> > > --
> > > 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 
> > > athttp://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.

Reply via email to