Commit d13662ace10b32a749fcae00c370aae4f90d15ad

Authored by Andrew Kane
1 parent 5fc2a512

Added search data

lib/searchkick/model.rb
... ... @@ -8,6 +8,10 @@ module Searchkick
8 8 extend Searchkick::Reindex
9 9 include Tire::Model::Search
10 10 include Tire::Model::Callbacks
  11 +
  12 + def to_indexed_json
  13 + respond_to?(:search_data) ? search_data.to_json : super
  14 + end
11 15 end
12 16 end
13 17  
... ...
lib/searchkick/search.rb
... ... @@ -8,7 +8,7 @@ module Searchkick
8 8 def search(term, options = {})
9 9 fields = options[:fields] || ["_all"]
10 10 operator = options[:partial] ? "or" : "and"
11   - tire.search do
  11 + tire.search load: true do
12 12 query do
13 13 boolean do
14 14 must do
... ...
test/searchkick_test.rb
... ... @@ -14,6 +14,12 @@ class Product < ActiveRecord::Base
14 14 number_of_shards: 1
15 15 },
16 16 conversions: true
  17 +
  18 + serialize :conversions, JSON
  19 +
  20 + def search_data
  21 + as_json(except: [:updated_at])
  22 + end
17 23 end
18 24  
19 25 class TestSearchkick < Minitest::Unit::TestCase
... ... @@ -259,7 +265,7 @@ class TestSearchkick &lt; Minitest::Unit::TestCase
259 265  
260 266 def store(documents)
261 267 documents.each do |document|
262   - Product.index.store ({_type: "product"}).merge(document)
  268 + Product.create!(document)
263 269 end
264 270 Product.index.refresh
265 271 end
... ...
test/test_helper.rb
... ... @@ -19,6 +19,9 @@ ActiveRecord::Migration.create_table :products, :force =&gt; true do |t|
19 19 t.integer :store_id
20 20 t.boolean :in_stock
21 21 t.boolean :backordered
  22 + t.text :conversions
  23 + t.integer :_boost
  24 + t.string :color
22 25 t.timestamps
23 26 end
24 27  
... ...