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

Brett Levine's Avatar

Brett Levine

20 Jan, 2012 08:52 PM

I'm surprised to see a call to my controller's create method fail because of indexing. I thought indexing only happens when I do a rake fs:index. This led me to add delta indexes, but i'm wondering if that's the way to go on heroku.

…inking-sphinx-2.0.10/lib/thinking_sphinx/source/sql.rb: 150:in types_to_crcs' …inking-sphinx-2.0.10/lib/thinking_sphinx/source/sql.rb: 122:incrc_column'
…0.10/lib/thinking_sphinx/source/internal_properties.rb: 8:in add_internal_attributes_and_facets' …s/thinking-sphinx-2.0.10/lib/thinking_sphinx/source.rb: 35:ininitialize'
…ing-sphinx-2.0.10/lib/thinking_sphinx/index/builder.rb: 263:in new' …ing-sphinx-2.0.10/lib/thinking_sphinx/index/builder.rb: 263:insource'
…ing-sphinx-2.0.10/lib/thinking_sphinx/index/builder.rb: 99:in block in indexes' …ing-sphinx-2.0.10/lib/thinking_sphinx/index/builder.rb: 98:ineach'
…ing-sphinx-2.0.10/lib/thinking_sphinx/index/builder.rb: 98:in `indexes'

                          /app/app/models/record.rb:  69:in `block in <class:Record>'

…ing-sphinx-2.0.10/lib/thinking_sphinx/index/builder.rb: 32:in instance_eval' …ing-sphinx-2.0.10/lib/thinking_sphinx/index/builder.rb: 32:ininitialize'
…ing-sphinx-2.0.10/lib/thinking_sphinx/index/builder.rb: 22:in new' …ing-sphinx-2.0.10/lib/thinking_sphinx/index/builder.rb: 22:ingenerate'
…ing-sphinx-2.0.10/lib/thinking_sphinx/active_record.rb: 203:in add_sphinx_index' …ing-sphinx-2.0.10/lib/thinking_sphinx/active_record.rb: 170:inblock in define_index'
…ing-sphinx-2.0.10/lib/thinking_sphinx/active_record.rb: 185:in call' …ing-sphinx-2.0.10/lib/thinking_sphinx/active_record.rb: 185:inblock in define_indexes'
…ing-sphinx-2.0.10/lib/thinking_sphinx/active_record.rb: 184:in each' …ing-sphinx-2.0.10/lib/thinking_sphinx/active_record.rb: 184:indefine_indexes'
…ing-sphinx-2.0.10/lib/thinking_sphinx/active_record.rb: 380:in define_indexes' …emodel-3.1.1/lib/active_model/validations/callbacks.rb: 53:inrun_validations!'
…gems/activemodel-3.1.1/lib/active_model/validations.rb: 179:in `valid?'

         /app/app/controllers/records_controller.rb: 103:in `create'
  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.



  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?


  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).



  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.


  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


? 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