From 9ecd12ed839a10b5031fd52efbbef550802ad70e Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Sun, 15 Jan 2017 05:18:39 -0800 Subject: [PATCH] Moved partial reindexing to performance section [skip ci] --- README.md | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index bcda49e..6b08839 100644 --- a/README.md +++ b/README.md @@ -1158,6 +1158,33 @@ Reindex and search with: Business.search "ice cream", routing: params[:city_id] ``` +### Partial Reindexing + +Reindex a subset of attributes to reduce time spent generating search data and cut down on network traffic. + +```ruby +class Product < ActiveRecord::Base + def search_data + { + name: name + }.merge(search_prices) + end + + def search_prices + { + price: price, + sale_price: sale_price + } + end +end +``` + +And use: + +```ruby +Product.reindex(:search_prices) +``` + ### Performant Conversions Split out conversions into a separate method so you can use partial reindexing, and cache conversions to prevent N+1 queries. Be sure to use a centralized cache store like Memcached or Redis. @@ -1396,21 +1423,6 @@ Reindex associations store.products.reindex ``` -Reindex a subset of attributes (partial reindex) - -```ruby -class Product < ActiveRecord::Base - def search_prices - { - price: price, - sale_price: sale_price - } - end -end - -Product.reindex(:search_prices) -``` - Remove old indices ```ruby -- libgit2 0.21.0