One last note... You may have to reference FauxColumn as ThinkingSphinx::Index::FauxColumn.
On Sep 7, 10:43 am, BigRefT <[email protected]> wrote: > Thanks Pat! What you gave me is close, but it's missing something. > > Here is my setup: > > Order has a define_index with indexes and attributes (nothing > special). > Now I have a plugin that will extend Order by including a module > (Order.send(:include, OrderMixin)). > > The problem I have with your suggestion is that the indexes aren't > actually created until after the mixin happens. > > So if I have this: > > class Order < ActiveRecord::Base > define_index do > ... > end > end > > module OrderMixin > def self.included(base) > source = sphinx_indexes.first.sources.first > columns = FauxColumn.coerce(:created_at) > options = {} > ThinkingSphinx::Attribute.new(source, columns, options) > end > end > > Order.sphinx_indexes is actually empty because 'define_indexes' hasn't > been called yet. Now, if I call 'define_indexes' before it try add my > new attribute it all works as expected. > > Thanks for helping out! Let me know if you think there is a problem > with calling 'define_indexes' on my own. > > On Sep 6, 10:18 am, "Pat Allan" <[email protected]> wrote: > > > > > Hi Tony > > > You're definitely wading into undocumented (and untried) waters - I've > > not done this before, nor have I heard of anyone trying to do this > > before. > > > Still, it shouldn't be too difficult (in theory). The code you want to > > keep an eye on is ThinkingSphinx::Index::Builder... but here's an > > example, adding an attribute to a given source: > > > source = Order.sphinx_indexes.first.sources.first > > columns = FauxColumn.coerce(:created_at) > > options = {:type => :datetime} # not needed in this case - TS will > > figure it out > > ThinkingSphinx::Attribute.new(source, columns, options) > > > An index can have many sources, but starts with just one, so you should > > be able to access existing sources easily enough. The columns can be > > symbols referring to columns, and the options are a hash of options you > > may pass through to a 'has' call normally. Also: the attribute will > > automatically add itself to the source. > > > Hope this helps! > > > -- > > Pat > > > On 9/1/2010, "BigRefT" <[email protected]> wrote: > > > >I have searched and searched but have yet to find any info on if this > > >is possible. I have an Order model that calls define_index in the main > > >app. I am creating a plug-in that extends the Order model and I want > > >to insert a new attribute into the index for Order. Is this possible? > > > >I have read through post after post with nothing even close, and I > > >have tried to go into the TS code base and see if I can do it > > >manually. > > > >The closest I got was this: > > > >Order.sphinx_index.first.attributes << ... > > > >Where ... would be the missing piece. I know it needs to be an > > >Attribute, but I don't where to start. > > > >Any help would be appreciated. > > > >Thanks > > >Tony > > > >-- > > >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 > > >athttp://groups.google.com/group/thinking-sphinx?hl=en. -- 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.
