Commit eb5d865ca3a8488ee747a4973141dca899b495e5
1 parent
03cb0c65
Exists in
master
and in
21 other branches
Better example for search_data
Showing
1 changed file
with
5 additions
and
4 deletions
Show diff stats
README.md
... | ... | @@ -338,12 +338,13 @@ Control what data is indexed with the `search_data` method. Call `Product.reinde |
338 | 338 | |
339 | 339 | ```ruby |
340 | 340 | class Product < ActiveRecord::Base |
341 | + belongs_to :department | |
342 | + | |
341 | 343 | def search_data |
342 | - as_json only: [:name, :active] | |
343 | - # or equivalently | |
344 | 344 | { |
345 | 345 | name: name, |
346 | - active: active | |
346 | + department_name: department.name, | |
347 | + on_sale: sale_price.present? | |
347 | 348 | } |
348 | 349 | end |
349 | 350 | end |
... | ... | @@ -353,7 +354,7 @@ Searchkick uses `find_in_batches` to import documents. To eager load associatio |
353 | 354 | |
354 | 355 | ```ruby |
355 | 356 | class Product < ActiveRecord::Base |
356 | - scope :search_import, -> { includes(:searches) } | |
357 | + scope :search_import, -> { includes(:department) } | |
357 | 358 | end |
358 | 359 | ``` |
359 | 360 | ... | ... |