Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

ActiveRecord indexed objects are removed when updating them if they don't match the asari_should_index? method #18

Open
mmeys opened this issue Oct 2, 2013 · 2 comments

Comments

@mmeys
Copy link
Contributor

mmeys commented Oct 2, 2013

Hi,

I was wondering why an ActiveRecord object indexed using the asari_index method is removed from cloud search after and update if it doesn't match the asari_should_index? method?

The behavior I want is to update on cloud search the indexed object only when some attributes changed. Indeed I index users of my app with their name and their avatar. So I don't want to update them on cloud search if theses attributes doesn't change...and I don't want them to be deleted from cloud search neither.

That's why I suggest to remove the self.asari_remove_item(obj)line from the asari_update_item method.

def asari_update_item(obj)
  if self.asari_when
    unless asari_should_index?(obj)
      self.asari_remove_item(obj) # I suggest to remove this line
      return
    end
  end
  data = {}
  self.asari_fields.each do |field|
    data[field] = obj.send(field)
  end
  self.asari_instance.update_item(obj.send(:id), data)
rescue Asari::DocumentUpdateException => e
  self.asari_on_error(e)
end
@zmoshansky
Copy link

1.) Updating the index only when the indexed fields changed would be duplicate of Issue #11
2.) Removing this line would prevent objects from being deleted from the index when they are updated. Which is likely a use case.

For your problem, perhaps look into using a when block that returns false on update if the fields haven't changed. Perhaps using http://stackoverflow.com/questions/1586536/how-to-detect-attribute-changes-from-model

@mmeys
Copy link
Contributor Author

mmeys commented Apr 4, 2014

1.) I agree.
2.) Indeed. I don't understand why this has never been corrected.

Thanks for the suggestion, that's what I did!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants