Hi Eric Thanks for sharing that, and it's great that you've got multiple indexes working successfully. The only change I'd note is that the index name is expected to be a string, not a symbol (but if it's working for you, great! I guess the implicit .to_s on symbols is keeping it all happy).
One day I'll get to writing some documentation on multiple indexes - but it is a pretty new feature, hence the lack of such docs at the moment. Cheers -- Pat On 12/02/2010, at 6:02 AM, Eric wrote: > Hi- > > I'm a big fan of both thinking sphinx and sphinx. I've been using > sphinx for several years now and thinking sphinx is a real lifesaver > for managing sphinx config files and is a wonderfully clean DSL. > > Recently I've been using sphinx for a relatively small data set but > lots of attributes that cache relationships among model objects. In > order to make indexing more performant, I split several models' > indices into sets. I read http://www.sphinxsearch.com/forum/view.html?id=3596 > which points out that the indices need to be uniform. I was able to > get multiple indices on the same model to work. This appears to be an > undocumented feature, so thought I'd sketch out what I've done: > > - Within a model; say user.rb; create a couple (or more) index blocks: > define_index :user_first do > # fields > indexes first_name, last_name, email, :sortable => true > > # attributes > has 'null', :type => :multi, :as => :favorite_user_ids > end > > define_index :user_second do > # fields > indexes first_name, last_name, email, :sortable => true > > # attributes > has favorites.user(:id), :as => :favorite_user_ids > end > > Note that :type => :multi is another type along with :string > and :integer > > Note that I've included the fields and attributes in the same order > and included them in both. It's important to tell sphinx that it is a > multi attribute (if indeed that's what it is) as well. > This is a simple example, but if you have a very complicated index on > a model and find issues with the SQL that can be solved by splitting > the SELECT statement into multiple statements, this is a good > technique. You could also resort to hand-writing a SELECT statement > but then obviously you lose out on the benefits that thinking sphinx > provides of automatic query generation. Which is particularly > valuable in the case of complex attributes. > > -- > 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. > -- 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.
