I also use James's solution and it's working great ;)

On Aug 1, 6:53 am, James Healy <[email protected]> wrote:
> The quickest way is to add an attribute to the index from the comments
> table. Since it's an attribute, if you never use it it won't effect your
> search results.
>
>     define_index do
>       indexes body
>       has comments(:id), :as => 'comment_ids'
>       has "GREATEST(posts.created_at, MAX(comments.created_at))", :as => 
> 'last_active_at', :type => :datetime
>       group_by 'posts.id'
>     end
>
> Alternatively, if you're running rails 2.3.3, you could use the new
> :touch feature to update Post.updated_at when a comment is
> created or updated. This might avoid the need for adding comments to
> your Post index completely.
>
> The latest Railscast covers :touch pretty 
> well:http://railscasts.com/episodes/172-touch-and-cache
>
> -- James Healy <jimmy-at-deefa-dot-com>  Sat, 01 Aug 2009 14:48:02 +1000
>
> Dmitry Ratnikov wrote:
>
> >   Hi,
> >  I am trying to make use of the :time_segments option to search for
> > most recent blog posts and would like to do something like:
>
> >  class Post < ActiveRecord::Base
> >    has_many :comments
>
> >    define_index do
> >      # no indexes comments.body since I'd like to search for comments
> > separately
>
> >      indexes body
> >      has "GREATEST(posts.created_at, MAX(comments.created_at))", :as
> > => 'last_active_at', :type => :datetime
> >      group_by 'posts.id'
> >    end
> >  end
>
> >  However that fails, since I don't see a good way to specify that the
> > resulting query should join on the 'comments' table. Is it possible to
> > specify that join?
>
> >  Thanks,
>
> >  -- Dmitry
--~--~---------~--~----~------------~-------~--~----~
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