Hi Matt
I'm not sure that approach is going to work - what happens if some
comments are moderated and some aren't? Records will be returned in
both situations.
Do you want to exclude the comment column of comments that aren't
moderated from search queries? If so, I'd recommend making a new
association, filtering out unmoderated comments:
has_many :moderated_comments, :conditions => {:moderated =>
true}, :class_name => "Comment"
And then use that association in your define_index block:
indexes moderated_comments.comment
You will also want delta indexing to be fired when a comment is saved
- and yes, that means forcing the picture's updated_at to be updated.
This was a lot easier pre-2.1 (object.save), but now with the dirty
object stuff (object.changed?, etc) I'm not sure how to force a save
if the object itself hasn't changed.
Hope this helps - but if I'm on the wrong track, let me know.
--
Pat
On 07/03/2009, at 6:04 AM, matt wrote:
>
> HI all,
>
> I have a problem I'm hoping someone can help me with. I've setup TS
> to index a couple of my models and am using a datetime delta to handle
> model updates. This is all working great. The problem I'm having is
> that I need to remove a model from being searchable based on a field
> in a child, so the paren't datetime doesn't get update when the childs
> field changes. Here is what my indexed model looks like
>
> class Picture < ActiveRecord::Base
> has_many :comments
>
> define_index do
> set_property :delta => :datetime, :delta_column
> => :updated_at, :threshold => 30.minutes
>
> indexes :title
> indexes comments.comment
>
> has comments.moderated, :as => :comments_moderated
> end
>
> end
>
> and I search for models using:
>
> Picture.search(params[:q], :without => {:comments_moderated => false}}
>
> This way, search only finds pictures that have all their comments
> moderated.
>
> The problem is, adding or moderating a comment doesn't change the
> updated_at field in picture, so my delta index doesn't pick up the
> fact that a picture should (or not) be found by my above search.
>
> Any ideas on how I can go about resolving this? I'd rather not have
> to update the pictures updated_at field when saving a comment. Is
> there anyway to maybe get delta datetime to take into account the
> child's datetimes as well?
>
> Thanks,
>
> Matt
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---