Deltas when updating associations

6 views
Skip to first unread message

WadeWinningham

unread,
Jul 7, 2008, 11:51:44 PM7/7/08
to Thinking Sphinx
I'm not sure if there's a better way to do this...

I have a Venue model which has associated AKA's (since venue names can
change). The AKA model itself does not have a sphinx index, it's
values are only indexed through it's association with the Venue model.

When an update happens to an AKA (or one is added or deleted) I would
like the associated Venue's index to get updated. It currently does
not.

All I can think of to update the delta index is to make an update to
the Venue object to force it. Could I simply just set "delta = 1" or
is that a no-no? If not, is there a call I could use to force the
delta update?

Coilcore

unread,
Jul 8, 2008, 5:12:39 AM7/8/08
to Thinking Sphinx
At the sql level setting 'delta=1' wouldn't do much, since what you
really want is to have Sphinx rebuild its indexes (not mysql having a
flag set). Likewise you probably don't just want to call
ThinkingSphinx's delta index method because it will avoid the
mechanism for tracking these changes (e.g. delta = 1)

The best bet is to simply call AR:B.save on your record, this will
update the database with 'delta = 1' and also trigger the after_save
callback to manage your delta indexing. It also will be the most
robust for any future changes to ThinkingSphinx.

Coilcore

unread,
Jul 8, 2008, 5:16:26 AM7/8/08
to Thinking Sphinx
Keep in mind that as far sphinx is concerned your associations are
just a single field within a single document. Your has_many bascially
becomes a single concatenated string within the index. Think of it as
one big denormalized record. So even though you might see this as an
object with relationships, sphinx just sees the index entry as a
single entity.

On Jul 7, 8:51 pm, WadeWinningham <wade.winning...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages