Commit 36db36808008022da93502b096878d32ff697f7f

Authored by Andrew Kane
1 parent c2c48a84

Fixes for Mongoid 3.1.4

@@ -2,3 +2,6 @@ source 'https://rubygems.org' @@ -2,3 +2,6 @@ source 'https://rubygems.org'
2 2
3 # Specify your gem's dependencies in searchkick.gemspec 3 # Specify your gem's dependencies in searchkick.gemspec
4 gemspec 4 gemspec
  5 +
  6 +# gem "mongoid", github: "mongoid/mongoid"
  7 +# gem "mongoid", "~> 3.1.0"
lib/searchkick.rb
@@ -9,5 +9,5 @@ require "searchkick/tasks" @@ -9,5 +9,5 @@ require "searchkick/tasks"
9 require "searchkick/logger" if defined?(Rails) 9 require "searchkick/logger" if defined?(Rails)
10 10
11 # TODO find better ActiveModel hook 11 # TODO find better ActiveModel hook
12 -ActiveModel::AttributeMethods::ClassMethods.send(:include, Searchkick::Model) 12 +ActiveModel::Callbacks.send(:include, Searchkick::Model)
13 ActiveRecord::Base.send(:extend, Searchkick::Model) if defined?(ActiveRecord) 13 ActiveRecord::Base.send(:extend, Searchkick::Model) if defined?(ActiveRecord)
lib/searchkick/reindex.rb
@@ -14,8 +14,12 @@ module Searchkick @@ -14,8 +14,12 @@ module Searchkick
14 14
15 # use scope for import 15 # use scope for import
16 scope = respond_to?(:search_import) ? search_import : self 16 scope = respond_to?(:search_import) ? search_import : self
17 - scope.find_in_batches do |batch|  
18 - index.import batch 17 + if scope.respond_to?(:find_in_batches)
  18 + scope.find_in_batches do |batch|
  19 + index.import batch
  20 + end
  21 + else
  22 + index.import scope.all
19 end 23 end
20 24
21 if a = Tire::Alias.find(alias_name) 25 if a = Tire::Alias.find(alias_name)
lib/searchkick/search.rb
@@ -28,7 +28,7 @@ module Searchkick @@ -28,7 +28,7 @@ module Searchkick
28 page = [options[:page].to_i, 1].max 28 page = [options[:page].to_i, 1].max
29 per_page = options[:limit] || options[:per_page] || 100000 29 per_page = options[:limit] || options[:per_page] || 100000
30 offset = options[:offset] || (page - 1) * per_page 30 offset = options[:offset] || (page - 1) * per_page
31 - index_name = options[:index_name] || index.name 31 + index_name = options[:index_name] || tire.index.name
32 32
33 conversions_field = @searchkick_options[:conversions] 33 conversions_field = @searchkick_options[:conversions]
34 personalize_field = @searchkick_options[:personalize] 34 personalize_field = @searchkick_options[:personalize]
test/index_test.rb
@@ -12,7 +12,7 @@ class TestIndex < Minitest::Unit::TestCase @@ -12,7 +12,7 @@ class TestIndex < Minitest::Unit::TestCase
12 12
13 Product.clean_indices 13 Product.clean_indices
14 14
15 - assert Product.index.exists? 15 + assert Product.tire.index.exists?
16 assert different_index.exists? 16 assert different_index.exists?
17 assert !old_index.exists? 17 assert !old_index.exists?
18 end 18 end
test/test_helper.rb
@@ -35,7 +35,14 @@ Tire.configure do @@ -35,7 +35,14 @@ Tire.configure do
35 pretty true 35 pretty true
36 end 36 end
37 37
  38 +# Mongoid.configure do |config|
  39 +# config.connect_to "searchkick_test"
  40 +# end
  41 +
38 class Product < ActiveRecord::Base 42 class Product < ActiveRecord::Base
  43 + # include Mongoid::Document
  44 + # include Mongoid::Attributes::Dynamic
  45 +
39 belongs_to :store 46 belongs_to :store
40 47
41 searchkick \ 48 searchkick \
@@ -64,9 +71,10 @@ class Product &lt; ActiveRecord::Base @@ -64,9 +71,10 @@ class Product &lt; ActiveRecord::Base
64 end 71 end
65 72
66 class Store < ActiveRecord::Base 73 class Store < ActiveRecord::Base
  74 + # include Mongoid::Document
67 end 75 end
68 76
69 -Product.index.delete if Product.index.exists? 77 +Product.tire.index.delete if Product.tire.index.exists?
70 Product.reindex 78 Product.reindex
71 Product.reindex # run twice for both index paths 79 Product.reindex # run twice for both index paths
72 80
@@ -82,7 +90,7 @@ class MiniTest::Unit::TestCase @@ -82,7 +90,7 @@ class MiniTest::Unit::TestCase
82 documents.shuffle.each do |document| 90 documents.shuffle.each do |document|
83 Product.create!(document) 91 Product.create!(document)
84 end 92 end
85 - Product.index.refresh 93 + Product.tire.index.refresh
86 end 94 end
87 95
88 def store_names(names) 96 def store_names(names)