Commit 8b5940a0f83052dfdf4b5df8eb75f1ee5269c24b

Authored by Andrew Kane
1 parent f1957300

Fixed dynamic mapping for inheritance - fixes autocomplete for #85

lib/searchkick/reindex.rb
... ... @@ -225,7 +225,7 @@ module Searchkick
225 225 end
226 226  
227 227 mappings = {
228   - searchkick_klass.document_type.to_sym => {
  228 + _default_: {
229 229 properties: mapping,
230 230 # https://gist.github.com/kimchy/2898285
231 231 dynamic_templates: [
... ...
test/inheritance_test.rb
... ... @@ -30,4 +30,16 @@ class TestInheritance < Minitest::Unit::TestCase
30 30 assert_equal 2, Animal.search("bear").size
31 31 end
32 32  
  33 + def test_child_autocomplete
  34 + store_names ["Max"], Cat
  35 + store_names ["Mark"], Dog
  36 + assert_equal ["Max"], Cat.search("ma", fields: [:name], autocomplete: true).map(&:name)
  37 + end
  38 +
  39 + def test_parent_autocomplete
  40 + store_names ["Max"], Cat
  41 + store_names ["Mark"], Dog
  42 + assert_equal ["Mark", "Max"], Animal.search("ma", fields: [:name], autocomplete: true).map(&:name).sort
  43 + end
  44 +
33 45 end
... ...
test/test_helper.rb
... ... @@ -122,7 +122,7 @@ class Product
122 122 end
123 123  
124 124 class Animal
125   - searchkick
  125 + searchkick autocomplete: [:name]
126 126 end
127 127  
128 128 Product.searchkick_index.delete if Product.searchkick_index.exists?
... ...