tag:support.flying-sphinx.com,2011-01-05:/discussions/questions/8-how-soon-after-adding-a-new-record-to-the-database-will-it-show-up-in-search-using-delta-indexesFlying Sphinx: Discussion 2012-06-25T19:28:31Ztag:support.flying-sphinx.com,2011-01-05:Comment/100093442011-09-16T16:27:35Z2011-09-16T16:27:36ZHow soon after adding a new record to the database will it show up in search (using delta indexes)?<div><p>Is it immediate or is it based on how often the delta index is
run and if it's the latter, how often do the delta indexes run on
Heorku?</p>
<p>Thanks,<br>
Jason</p></div>developertag:support.flying-sphinx.com,2011-01-05:Comment/100093442011-09-16T17:33:01Z2011-09-16T17:33:05ZHow soon after adding a new record to the database will it show up in search (using delta indexes)?<div><p>I think I misunderstood how it works.</p>
<p>It appears that a dj job is submitted when a model is added or
changed via a callback. So, the record would show up as fast as dj
can process the job. Is this right? Does the job process all
records with delta = true or just the record that triggered the
callback?</p>
<p>Specifically, I'm wondering what happens in the case where a
parent object changes in such a way that needs to update it's
children's indicies. For example, I've added a callback to a parent
class that does the following:</p>
<pre>
<code>class Parent
after_save :update_child_deltas
private
def update_child_deltas
Child.update_all(["delta = ?", true], ["parent_id = ?", self.id])
end
end</code>
</pre>
<p>Is this the correct approach for this case? Will the children be
updated by the delta index using this approach?</p>
<p>Thanks,<br>
Jason</p></div>developertag:support.flying-sphinx.com,2011-01-05:Comment/100093442011-09-17T05:44:16Z2011-09-17T05:44:16ZHow soon after adding a new record to the database will it show up in search (using delta indexes)?<div><p>Hi Jason</p>
<p>Yes, when you edit or create a model instance, a job is added
via a callback, and that'll get processed as soon as DJ gets to it.
The job will process all records that have delta set to true.</p>
<p>So, if you're updating multiple objects like in your example,
which would not fire callbacks, then you can work around this with
something like so:</p>
<pre>
<code>Child.index_delta</code>
</pre>
<p>However, the one catch is because you're not changing records
one by one (and thus invoking callbacks), both the old data for
those Sphinx records and the new will return search results. This
may not be a problem, but if it is, best to update each one
normally in turn.</p>
<p>Cheers</p>
<p>Pat</p></div>Pat Allantag:support.flying-sphinx.com,2011-01-05:Comment/100093442011-09-19T13:39:46Z2011-09-19T13:39:48ZHow soon after adding a new record to the database will it show up in search (using delta indexes)?<div><p>We can have tens of thousands of child objects in our case, so,
we cannot update them one by one like that in a call back. I
suppose what we could do is submit a delayed_job in the callback
that will perform the updates in the background.</p>
<p>Regarding the Child.index_delta approach, what is the reason why
there would be duplicate data using that method? Just curious.</p>
<p>Thanks,<br>
Jason</p></div>Jasontag:support.flying-sphinx.com,2011-01-05:Comment/100093442011-09-20T04:39:09Z2011-09-20T04:39:09ZHow soon after adding a new record to the database will it show up in search (using delta indexes)?<div><p>Hi Jason</p>
<p>Fair enough about the callbacks… there's some space for
improvements there, I'll see what I can do.</p>
<p>The reason there's duplicate data is because there's child_core
and child_delta indices - the latter will be updated by the
index_delta core, but child_core won't be - so any data in there
will be used to match against search queries.</p>
<p>Cheers</p>
<p>Pat</p></div>Pat Allan