Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If a record doesn't qualify to be included in the index on create, it may not be added even if a later update makes it qualify #56

Open
chrisbloom7 opened this issue Oct 6, 2014 · 1 comment

Comments

@chrisbloom7
Copy link

Consider the following model:

class Category < ActiveRecord::Base
  acts_as_indexed :fields => [:name, :description], :if => Proc.new { |c| c.products.count > 0 }
  has_many :products
end

If you create a new category that doesn't have any products assigned to it, it won't be included in the index because the :if proc isn't satisfied. If you then later add a product to it and force/trigger the update_index method (changing no other indexed field), it won't be added to the index. This is because ActsAsIndexed::SearchIndex::record_unchanged? will always return true in this case, because when the proc is evaluated on old_record it sees that c.products.count > 0 and the same happens with the proc is evaluated on the old_record - i.e. it is basing the old and new state on the same virtual attribute which isn't ever going to be dirty.

@chrisbloom7 chrisbloom7 changed the title If a record doesn't qualify to be included in the index on create, it will never be added even if a later save makes it qualify If a record doesn't qualify to be included in the index on create, it may not be added even if a later update makes it qualify Oct 7, 2014
@chrisbloom7
Copy link
Author

I did some digging in the source and found that records that aren't originally in the index can be added if they later qualify, but just not in certain circumstances. I updated the issue title and description with a more accurate example.

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

No branches or pull requests

1 participant