Commit 7f8d8361182ed126bdd46d5de349ea7e6d20efec
1 parent
d9c4cb6e
Exists in
master
and in
21 other branches
Added section on keeping association data in sync - for #352
Showing
1 changed file
with
16 additions
and
0 deletions
Show diff stats
README.md
... | ... | @@ -356,6 +356,22 @@ There are three strategies for keeping the index synced with your database. |
356 | 356 | end |
357 | 357 | ``` |
358 | 358 | |
359 | +#### Associations | |
360 | + | |
361 | +Data is **not** automatically synced when an association is updated. If this is desired, add a callback to reindex: | |
362 | + | |
363 | +```ruby | |
364 | +class Image < ActiveRecord::Base | |
365 | + belongs_to :product | |
366 | + | |
367 | + after_commit :reindex_product | |
368 | + | |
369 | + def reindex_product | |
370 | + product.reindex | |
371 | + end | |
372 | +end | |
373 | +``` | |
374 | + | |
359 | 375 | ### Keep Getting Better |
360 | 376 | |
361 | 377 | Searchkick uses conversion data to learn what users are looking for. If a user searches for “ice cream” and adds Ben & Jerry’s Chunky Monkey to the cart (our conversion metric at Instacart), that item gets a little more weight for similar searches. | ... | ... |