How soon after adding a new record to the database will it show up in search (using delta indexes)?

developer's Avatar

developer

16 Sep, 2011 04:27 PM

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?

Thanks,
Jason

  1. 1 Posted by developer on 16 Sep, 2011 05:33 PM

    developer's Avatar

    I think I misunderstood how it works.

    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?

    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:

    class Parent
      after_save :update_child_deltas
      private
      def update_child_deltas
        Child.update_all(["delta = ?", true], ["parent_id = ?", self.id])
      end
    end
    

    Is this the correct approach for this case? Will the children be updated by the delta index using this approach?

    Thanks,
    Jason

  2. Support Staff 2 Posted by Pat Allan on 17 Sep, 2011 05:44 AM

    Pat Allan's Avatar

    Hi Jason

    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.

    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:

        Child.index_delta

    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.

    Cheers

    Pat

  3. 3 Posted by Jason on 19 Sep, 2011 01:39 PM

    Jason's Avatar

    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.

    Regarding the Child.index_delta approach, what is the reason why there would be duplicate data using that method? Just curious.

    Thanks,
    Jason

  4. Support Staff 4 Posted by Pat Allan on 20 Sep, 2011 04:39 AM

    Pat Allan's Avatar

    Hi Jason

    Fair enough about the callbacks… there's some space for improvements there, I'll see what I can do.

    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.

    Cheers

    Pat

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac