Hi James,

Thanks for your prompt response!

I'm using the gem:

          freelancing-god-thinking-sphinx-1.1.12

Excerp from config/environment.rb:
====================
Rails::Initializer.run do |config|
  config.gem 'freelancing-god-thinking-sphinx', :version => '>=
1.1.12',
                                :lib => 'thinking_sphinx',
                                :source => 'http://gems.github.com'
end
====================

Test on the console:
====================
har...@laptop: ~/sandbox/app$ script/console
Loading development environment (Rails 2.3.2)
>> ThinkingSphinx.indexed_models
=> []
>> Order.new
=> #<Order id: nil, ........>
>> ThinkingSphinx.indexed_models
=> ["Order"]
=======================

>From Order.rb
=====================
class Order < ActiveRecord::Base
        # Thinking Sphinx Config
        define_index do
                # Columns
                indexes :po_no
                indexes tracking
                indexes ptm_no
                indexes description
                indexes issued_to_history
                indexes location
                indexes work_orders

                # Associations
                indexes unit(:description), :as => :unit_name
                indexes vendor(:name), :as => :supplier

               # Delta indexing
                set_property :delta => :datetime,
                        :threshold => 1.minute,
                        :delta_column => :updated_at
          end
=======================

As you can see, unless I specifically call Order, it doesn't load the
model into #indexed_models. And on a rake task, this doesn't happen.

>From thinking_sphinx.rb
=================
  # The collection of indexed models. Keep in mind that Rails lazily
loads
  # its classes, so this may not actually be populated with _all_ the
models
  # that have Sphinx indexes.
  def self.indexed_models
    @@indexed_models ||= []
  end
=================

 I assume the issue I am running into is the "lazy loading" it is
talking about, but how can I get around this?

Any thoughts?


On Aug 3, 6:31 pm, James Healy <[email protected]> wrote:
> Harmon wrote:
> > I looked into the delta task, and found that it calls this:
>
> > ThinkingSphinx.indexed_models      # a class accessor for
> > @@indexed_models
>
> > which, running by itself, returns an empty array. This array of
> > classes only gets populated when the models are required. So running
> > the task alone doesn't do anything for me. Is there a way to get this
> > @@indexed_models class attribute to populate with all the indexed
> > models, so that the rake task will work properly?
>
> Thinking Sphinx *should* require all your models when the rails stack
> (re)loads (see rails/init.rb).
>
> How are you using TS - a system gem? a vendored gem? a plugin?
>
> -- James Healy <jimmy-at-deefa-dot-com>  Tue, 04 Aug 2009 11:29:51 +1000
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to