ruby-on-railsrubysunspotsunspot-railssunspot-solr

Sunspot Gem Using in STI TABLE


i have Account Model,Asset, Capital and Revenue this table are all inherited in my Account model. i have 3 kind of attributes in my Account model. name, code and type. when i create an account where will be to insert will happen one in my account and the other one is in my type for example

Account.create(name: "test123", code:"test123", type:"Asset")

sql will run Two Insert one for Account model and one for Asset Table

and my sunspot work well it will reindex my database and i can search my params

but when i update my model Account my sql run one insert and one update

my question is how can i reindex my model when i update. with a particular data. i can do Sunspot.reindex but this is will load all data in my sql. that will cause me to slow


Solution

  • i put this to my model

     after_update do
      Sunspot.index Account.where(id: self.id)
    end