Hi Roger

I think this is technically possible... I've not tested it, but here's a few 
notes:

* The block of the index definition is evaluated within a class that inherits 
from BasicObject, not Object. So, a lot of the common methods that are mixed 
into Object don't exist (e.g. puts).
* self, however, does exist - probably because it's a language construct rather 
than a normal method.
* Any references to constants/classes within an index definition should be 
fully namespaced, including the :: prefix.
* Column/association references are built using method_missing magic.

So, I would expect something like this to work:

  ThinkingSphinx::Index.define :article, :with => :active_record do
    ::CommonIndexStructure.apply self
  end

  class CommonIndexStructure
    def self.apply(interpreter)
      interpreter.indexes interpreter.name
    end
  end

I've called the variable interpreter because it'll be an instance of 
ThinkingSphinx::Core::Interpreter.

See how you go - I'm definitely keen to hear if it works for you. If it 
doesn't, I'll try to investigate further locally.

Cheers

-- 
Pat

On 10 Jul 2014, at 4:22 pm, Roger Kind Kristiansen 
<[email protected]> wrote:

> I've got a few indices now where many of the fields and attribute definitions 
> are the same across them. Is there a no-fuzz way of extracting these 
> definitions into one place and include it in the index definition?
> 
> Cheers,
> Roger
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/thinking-sphinx.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/d/optout.

Reply via email to