acts_as_solr isn't updating associated models in Rails
- by Trey Bean
I'm using acts_as_solr for searching in a project. Unfortunately, the index doesn't seem to be updated for the associated models when a model is saved.
Example:
I have three models:
class Merchant < ActiveRecord::Base
acts_as_solr :fields => [:name, :domain, :description], :include => [:coupons, :tags]
...
end
class Coupon < ActiveRecord::Base
acts_as_solr :fields => [:store_name, :url, :code, :description]
...
end
class Tag < ActiveRecord::Base
acts_as_solr :fields => [:name]
...
end
I use the following line to perform a search:
Merchant.paginate_by_solr(params[:q], :per_page => PER_PAGE, :page => [(params[:page] || 1).to_i, 1].max)
For some reason though, after I add a coupon that contains the word 'shoes' in the description, a query for 'shoes' doesn't return the merchant associated with the coupon. The association all work and if I run rake solr:reindex, the search then returns the new coupon.
Do I need to update the index for Merchant each time a new coupon is created? Do I have to update the index for the whole class or can I just update the associated merchant?
Shouldn't this be done automatically?
Thanks for any input.