From d13662ace10b32a749fcae00c370aae4f90d15ad Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Mon, 22 Jul 2013 23:32:53 -0700 Subject: [PATCH] Added search data --- lib/searchkick/model.rb | 4 ++++ lib/searchkick/search.rb | 2 +- test/searchkick_test.rb | 8 +++++++- test/test_helper.rb | 3 +++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/searchkick/model.rb b/lib/searchkick/model.rb index 677000b..9dbbdae 100644 --- a/lib/searchkick/model.rb +++ b/lib/searchkick/model.rb @@ -8,6 +8,10 @@ module Searchkick extend Searchkick::Reindex include Tire::Model::Search include Tire::Model::Callbacks + + def to_indexed_json + respond_to?(:search_data) ? search_data.to_json : super + end end end diff --git a/lib/searchkick/search.rb b/lib/searchkick/search.rb index 6382f84..87e8373 100644 --- a/lib/searchkick/search.rb +++ b/lib/searchkick/search.rb @@ -8,7 +8,7 @@ module Searchkick def search(term, options = {}) fields = options[:fields] || ["_all"] operator = options[:partial] ? "or" : "and" - tire.search do + tire.search load: true do query do boolean do must do diff --git a/test/searchkick_test.rb b/test/searchkick_test.rb index 3761051..b2d0f33 100644 --- a/test/searchkick_test.rb +++ b/test/searchkick_test.rb @@ -14,6 +14,12 @@ class Product < ActiveRecord::Base number_of_shards: 1 }, conversions: true + + serialize :conversions, JSON + + def search_data + as_json(except: [:updated_at]) + end end class TestSearchkick < Minitest::Unit::TestCase @@ -259,7 +265,7 @@ class TestSearchkick < Minitest::Unit::TestCase def store(documents) documents.each do |document| - Product.index.store ({_type: "product"}).merge(document) + Product.create!(document) end Product.index.refresh end diff --git a/test/test_helper.rb b/test/test_helper.rb index fa02745..c48e85d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -19,6 +19,9 @@ ActiveRecord::Migration.create_table :products, :force => true do |t| t.integer :store_id t.boolean :in_stock t.boolean :backordered + t.text :conversions + t.integer :_boost + t.string :color t.timestamps end -- libgit2 0.21.0