Why is add_sphinx_index being called when I create an ActiveRecord object?

Brett Levine's Avatar

Brett Levine

22 Jan, 2012 09:40 PM

Will someone from your support staff please answer this question?

  1. 1 Posted by Brett Levine on 22 Jan, 2012 09:40 PM

    Brett Levine's Avatar

    Will someone from your support staff please answer this question?

  2. Support Staff 2 Posted by Pat Allan on 22 Jan, 2012 10:25 PM

    Pat Allan's Avatar

    Hi Brett

    This happens because Thinking Sphinx does not process the define_index blocks as the models are loaded, but only when there's an operation that may require TS to do something. In this case, TS needs to determine whether there is a delta index for the model, so it needs to process the block to see if set_property :delta => true (or similar) is being called.

    While this will happen in the development environment on every relevant request, in production it should only get called once - as the index definitions will be remembered like the model definitions are.

    Let me know if you need any further clarification.

    Cheers

    Pat

  3. 3 Posted by Brett Levine on 23 Jan, 2012 07:59 PM

    Brett Levine's Avatar

    Hey Pat,

    Thanks very much for the reply. I think I understand what you're saying, but to confirm more broadly that I'm doing the best thing...

    Your documentation states:
    "The only indexing approach that's currently viable in combination with Heroku is a variation upon the Delayed Deltas."

    And also:
    "Regular indexing is best managed by Cron — and Heroku makes this pretty easy."

    I'm not sure if this means, I really *should* use delta indexing with Heroku, or it's just optional.

    If I can live with reindexing every 30 minutes or so, am I better off using delta indexes or not? I am most concerned about model read/write performance being as good as possible.

    If I use delta indexes, I should still run rake fs:index every 30 minutes right?

    Thanks,
    Brett

  4. Support Staff 4 Posted by Pat Allan on 24 Jan, 2012 11:03 AM

    Pat Allan's Avatar

    Hi Brett

    You don't have to use delta indexing - you should read your first quote as 'the only *delta* indexing approach…'. I'll update that accordingly. If you're fine with reindexing every 30 minutes, then that keeps things simpler, less moving parts.

    That said, if you want something a little more up-to-date, then certainly give delta indexes a shot. And yes, if you do opt for deltas, you'll still need a regular full index (though wouldn't need to be every 30 minutes).

    Cheers

    Pat

  5. 5 Posted by Brett Levine on 24 Jan, 2012 07:33 PM

    Brett Levine's Avatar

    Hi Pat,

    Thanks for the reply. I sort of guessed that was your intention with the docs but wanted to make sure. Since we don't need immediate updating I'll fall back to just the rake task and remove delta indexing.

    Thanks,
    Brett

  6. Pat Allan closed this discussion on 31 Jan, 2012 11:11 AM.

Comments are currently closed for this discussion. You can start a new one.

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