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