Indexing associations

32 views
Skip to first unread message

Jim Ruther Nill

unread,
Nov 17, 2011, 10:47:23 PM11/17/11
to thinkin...@googlegroups.com
Hi!

in my define_index block inside the Task model i have a where clause

where 'project.status != "closed"'

but everytime I change the project status, I have to reindex else the
search results will be wrong.  Is there any better way to do this?  I have
delayed delta indexing enabled for tasks.  I wonder if I also need to do
this for projects.

Thanks!

Pat Allan

unread,
Nov 18, 2011, 9:09:46 AM11/18/11
to thinkin...@googlegroups.com
Hi Jim

I guess what you'll want to do is have a after_commit hook on your project model that updates the delta flags on all tasks for that project (which will in turn fire the delta callback for them). This will ensure Sphinx's data is close to up-to-date.

How many tasks are generally tied to a project?

--
Pat

> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To post to this group, send email to thinkin...@googlegroups.com.
> To unsubscribe from this group, send email to thinking-sphi...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.

Jim Ruther Nill

unread,
Nov 18, 2011, 11:02:19 AM11/18/11
to thinkin...@googlegroups.com
Hi Pat,

Thanks for getting back to me.  There's no limit to the number of tasks per project.
A good estimate would be around 50 tasks per project.  Does this mean that
everytime the project changes status, i have to update those 50 tasks? Sorry but
does that also mean that the delayed delta will queue 50 jobs to delayed_job?

Thanks!

Jim
--
-------------------------------------------------------------
visit my blog at http://jimlabs.heroku.com

Pat Allan

unread,
Nov 20, 2011, 12:47:27 AM11/20/11
to thinkin...@googlegroups.com
At a basic level, you'd need to update all of those tasks, but jobs will not be duplicated (however, if a job is completed before all 50 tasks are updated, then another would be added).

There is a better way, of course - it's just a little more fiddly.

Firstly, update the delta flags in one SQL statement (assuming this is done within the context of a project object):

Task.update_all({:delta => true}, {:project_id => id})

And then, let's just manually create the delta job:

ThinkingSphinx::Deltas::Job.enqueue(
ThinkingSphinx::Deltas::DeltaJob.new(Task.delta_index_names),
ThinkingSphinx::Configuration.instance.delayed_job_priority
)

That should be the best approach from a performance perspective. Let us know how it goes :)

--
Pat

Jim Ruther Nill

unread,
Nov 20, 2011, 5:33:10 AM11/20/11
to thinkin...@googlegroups.com
On Sun, Nov 20, 2011 at 1:47 PM, Pat Allan <p...@freelancing-gods.com> wrote:
At a basic level, you'd need to update all of those tasks, but jobs will not be duplicated (however, if a job is completed before all 50 tasks are updated, then another would be added).

There is a better way, of course - it's just a little more fiddly.

Firstly, update the delta flags in one SQL statement (assuming this is done within the context of a project object):

 Task.update_all({:delta => true}, {:project_id => id})

And then, let's just manually create the delta job:

 ThinkingSphinx::Deltas::Job.enqueue(
   ThinkingSphinx::Deltas::DeltaJob.new(Task.delta_index_names),
   ThinkingSphinx::Configuration.instance.delayed_job_priority
 )

That should be the best approach from a performance perspective. Let us know how it goes :)


cool. Thanks Pat! I'll let you know how it goes when I try it tomorrow. Thanks!

Jim Ruther Nill

unread,
Nov 20, 2011, 11:14:13 PM11/20/11
to thinkin...@googlegroups.com
On Sun, Nov 20, 2011 at 6:33 PM, Jim Ruther Nill <jvn...@gmail.com> wrote:


On Sun, Nov 20, 2011 at 1:47 PM, Pat Allan <p...@freelancing-gods.com> wrote:
At a basic level, you'd need to update all of those tasks, but jobs will not be duplicated (however, if a job is completed before all 50 tasks are updated, then another would be added).

There is a better way, of course - it's just a little more fiddly.

Firstly, update the delta flags in one SQL statement (assuming this is done within the context of a project object):

 Task.update_all({:delta => true}, {:project_id => id})

And then, let's just manually create the delta job:

 ThinkingSphinx::Deltas::Job.enqueue(
   ThinkingSphinx::Deltas::DeltaJob.new(Task.delta_index_names),
   ThinkingSphinx::Configuration.instance.delayed_job_priority
 )

That should be the best approach from a performance perspective. Let us know how it goes :)


cool. Thanks Pat! I'll let you know how it goes when I try it tomorrow. Thanks!

This is working perfectly Pat. Thanks again!
Reply all
Reply to author
Forward
0 new messages