Just an update on how I eventually solved this issue. Simply defining
indexed_data_changed? in the model doesn't work. This is because
ThinkingSphinx::ActiveRecord::Delta is dynamically loaded as part of
define_index. So it is loaded AFTER the class, and its definition of
indexed_data_changed? will always be the last and take precedence. So
instead I did the following:
class << self
# Use custom logic to determine if object should be flagged for
delta index
def add_sphinx_callbacks_and_extend_with_override(delta = false)
add_sphinx_callbacks_and_extend_without_override(delta)
# redefine the method to only check for first_name and last_name
changes
define_method(:indexed_data_changed?) do
.......... # check attributes changed?
end
end
alias_method_chain :add_sphinx_callbacks_and_extend, :override
end
I had to alias_method_chain the add_sphinx_callbacks_and_extend
method. And define indexed_data_changed? every time after this method
is called.
This works for me. Hope this helps others who are trying to do
something similar.
Cheers,
Calvin
On Oct 15, 6:03 pm, Pat Allan <[email protected]> wrote:
> Yes, you just need to define that method on your model - probably best to
> keep it private, but up to you.
>
> Cheers
>
> --
> Pat
>
> On 16/10/2010, at 4:34 AM, calvin wrote:
>
>
>
> > Hi Pat,
>
> > Can you tell me the best way tooverridethe indexed_data_changed?
> > method? Is it as simple as doing
>
> > def indexed_data_changed?
> > end
>
> > in my model?
>
> > Thanks.
> > Calvin
>
> > On Oct 15, 12:17 am, Pat Allan <[email protected]> wrote:
> >> Hi Calvin
>
> >> You could definitely try overriding that method - I've not done it before,
> >> but can't see why it wouldn't work.
>
> >> The reason TS always returns true is because you've got the manual
> >> attribute contact_filter_user_id, and TS isn't able to figure out whether
> >> that needs updating or not, so assumes it should by default.
>
> >> Though I'm guessing you realise this already, given you've investigated
> >> the underlying code already – this is more for everyone else reading this
> >> :)
>
> >> I guess what you'd want to do in your new version is check whether
> >> profile.about_me has changed, and return true if it has.
>
> >> Cheers
>
> >> --
> >> Pat
>
> >> On 15/10/2010, at 5:05 PM, calvin wrote:
>
> >>> Hi,
>
> >>> Is it possible tooverrideindexed_data_changed? with my own logic? My
> >>> issue is that indexed_data_changed? is always returning true
> >>> regardless if the indexed data is actually changed. Here is how I've
> >>> defined
>
> >>> class User < ActiveRecord::Base
>
> >>> has_one :profile, :dependent => :destroy
>
> >>> define_index 'user_base' do
> >>> indexes profile.about_me
>
> >>> has '0', :type => :integer, :as => :contact_filter_user_id
>
> >>> set_property :delta => :delayed
> >>> end
>
> >>> ....
> >>> end
>
> >>> Every time I save a user, it thinks profile.about_me has chnaged and
> >>> thus flags the delta. The index still works, but it just creates a lot
> >>> of unnecessary delta indexing load.
>
> >>> Any idea what would be a good way to solve this?
>
> >>> Thanks.
> >>> Calvin
>
> >>> --
> >>> 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
> > 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.