diff --git a/Gemfile b/Gemfile index f712136..f73244f 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,6 @@ source 'https://rubygems.org' # Specify your gem's dependencies in searchkick.gemspec gemspec + +# gem "mongoid", github: "mongoid/mongoid" +# gem "mongoid", "~> 3.1.0" diff --git a/lib/searchkick.rb b/lib/searchkick.rb index a3edf3d..87a96f2 100644 --- a/lib/searchkick.rb +++ b/lib/searchkick.rb @@ -9,5 +9,5 @@ require "searchkick/tasks" require "searchkick/logger" if defined?(Rails) # TODO find better ActiveModel hook -ActiveModel::AttributeMethods::ClassMethods.send(:include, Searchkick::Model) +ActiveModel::Callbacks.send(:include, Searchkick::Model) ActiveRecord::Base.send(:extend, Searchkick::Model) if defined?(ActiveRecord) diff --git a/lib/searchkick/reindex.rb b/lib/searchkick/reindex.rb index 1012154..665198c 100644 --- a/lib/searchkick/reindex.rb +++ b/lib/searchkick/reindex.rb @@ -14,8 +14,12 @@ module Searchkick # use scope for import scope = respond_to?(:search_import) ? search_import : self - scope.find_in_batches do |batch| - index.import batch + if scope.respond_to?(:find_in_batches) + scope.find_in_batches do |batch| + index.import batch + end + else + index.import scope.all end if a = Tire::Alias.find(alias_name) diff --git a/lib/searchkick/search.rb b/lib/searchkick/search.rb index ab5b033..fd1023a 100644 --- a/lib/searchkick/search.rb +++ b/lib/searchkick/search.rb @@ -28,7 +28,7 @@ module Searchkick page = [options[:page].to_i, 1].max per_page = options[:limit] || options[:per_page] || 100000 offset = options[:offset] || (page - 1) * per_page - index_name = options[:index_name] || index.name + index_name = options[:index_name] || tire.index.name conversions_field = @searchkick_options[:conversions] personalize_field = @searchkick_options[:personalize] diff --git a/test/index_test.rb b/test/index_test.rb index b285009..e4caf63 100644 --- a/test/index_test.rb +++ b/test/index_test.rb @@ -12,7 +12,7 @@ class TestIndex < Minitest::Unit::TestCase Product.clean_indices - assert Product.index.exists? + assert Product.tire.index.exists? assert different_index.exists? assert !old_index.exists? end diff --git a/test/test_helper.rb b/test/test_helper.rb index 971d84d..0ceefca 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -35,7 +35,14 @@ Tire.configure do pretty true end +# Mongoid.configure do |config| +# config.connect_to "searchkick_test" +# end + class Product < ActiveRecord::Base + # include Mongoid::Document + # include Mongoid::Attributes::Dynamic + belongs_to :store searchkick \ @@ -64,9 +71,10 @@ class Product < ActiveRecord::Base end class Store < ActiveRecord::Base + # include Mongoid::Document end -Product.index.delete if Product.index.exists? +Product.tire.index.delete if Product.tire.index.exists? Product.reindex Product.reindex # run twice for both index paths @@ -82,7 +90,7 @@ class MiniTest::Unit::TestCase documents.shuffle.each do |document| Product.create!(document) end - Product.index.refresh + Product.tire.index.refresh end def store_names(names) -- libgit2 0.21.0