Commit 201a236362672fddff521f819d1e1795f51e508e
1 parent
648d2ef7
Exists in
nested
Started nested support
Showing
5 changed files
with
25 additions
and
4 deletions
Show diff stats
CHANGELOG.md
lib/searchkick/index_options.rb
@@ -434,6 +434,10 @@ module Searchkick | @@ -434,6 +434,10 @@ module Searchkick | ||
434 | # http://www.elasticsearch.org/guide/reference/mapping/multi-field-type/ | 434 | # http://www.elasticsearch.org/guide/reference/mapping/multi-field-type/ |
435 | multi_field = dynamic_fields["{name}"].merge(fields: dynamic_fields.except("{name}")) | 435 | multi_field = dynamic_fields["{name}"].merge(fields: dynamic_fields.except("{name}")) |
436 | 436 | ||
437 | + (options[:nested] || []).each do |field| | ||
438 | + mapping[field] = {type: "nested"} | ||
439 | + end | ||
440 | + | ||
437 | mappings = { | 441 | mappings = { |
438 | properties: mapping, | 442 | properties: mapping, |
439 | _routing: routing, | 443 | _routing: routing, |
lib/searchkick/model.rb
@@ -5,7 +5,7 @@ module Searchkick | @@ -5,7 +5,7 @@ module Searchkick | ||
5 | 5 | ||
6 | unknown_keywords = options.keys - [:_all, :_type, :batch_size, :callbacks, :case_sensitive, :conversions, :deep_paging, :default_fields, | 6 | unknown_keywords = options.keys - [:_all, :_type, :batch_size, :callbacks, :case_sensitive, :conversions, :deep_paging, :default_fields, |
7 | :filterable, :geo_shape, :highlight, :ignore_above, :index_name, :index_prefix, :inheritance, :language, | 7 | :filterable, :geo_shape, :highlight, :ignore_above, :index_name, :index_prefix, :inheritance, :language, |
8 | - :locations, :mappings, :match, :merge_mappings, :routing, :searchable, :settings, :similarity, | 8 | + :locations, :mappings, :match, :merge_mappings, :nested, :routing, :searchable, :settings, :similarity, |
9 | :special_characters, :stem, :stem_conversions, :suggest, :synonyms, :text_end, | 9 | :special_characters, :stem, :stem_conversions, :suggest, :synonyms, :text_end, |
10 | :text_middle, :text_start, :word, :wordnet, :word_end, :word_middle, :word_start] | 10 | :text_middle, :text_start, :word, :wordnet, :word_end, :word_middle, :word_start] |
11 | raise ArgumentError, "unknown keywords: #{unknown_keywords.join(", ")}" if unknown_keywords.any? | 11 | raise ArgumentError, "unknown keywords: #{unknown_keywords.join(", ")}" if unknown_keywords.any? |
test/models/product.rb
@@ -20,9 +20,10 @@ class Product | @@ -20,9 +20,10 @@ class Product | ||
20 | highlight: [:name], | 20 | highlight: [:name], |
21 | filterable: [:name, :color, :description], | 21 | filterable: [:name, :color, :description], |
22 | similarity: "BM25", | 22 | similarity: "BM25", |
23 | - match: ENV["MATCH"] ? ENV["MATCH"].to_sym : nil | 23 | + match: ENV["MATCH"] ? ENV["MATCH"].to_sym : nil, |
24 | + nested: [:categories] | ||
24 | 25 | ||
25 | - attr_accessor :conversions, :user_ids, :aisle, :details | 26 | + attr_accessor :conversions, :user_ids, :aisle, :details, :categories |
26 | 27 | ||
27 | def search_data | 28 | def search_data |
28 | serializable_hash.except("id", "_id").merge( | 29 | serializable_hash.except("id", "_id").merge( |
@@ -31,7 +32,8 @@ class Product | @@ -31,7 +32,8 @@ class Product | ||
31 | location: {lat: latitude, lon: longitude}, | 32 | location: {lat: latitude, lon: longitude}, |
32 | multiple_locations: [{lat: latitude, lon: longitude}, {lat: 0, lon: 0}], | 33 | multiple_locations: [{lat: latitude, lon: longitude}, {lat: 0, lon: 0}], |
33 | aisle: aisle, | 34 | aisle: aisle, |
34 | - details: details | 35 | + details: details, |
36 | + categories: categories | ||
35 | ) | 37 | ) |
36 | end | 38 | end |
37 | 39 |
@@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
1 | +require_relative "test_helper" | ||
2 | + | ||
3 | +class NestedTest < Minitest::Test | ||
4 | + def test_basic | ||
5 | + store [ | ||
6 | + {name: "Product A", categories: [{name: "bread roll"}, {name: "sausage meat"}]} | ||
7 | + ] | ||
8 | + assert_search "sausage", ["Product A"], fields: ["categories.name"] | ||
9 | + assert_search "sausage roll", [], fields: ["categories.name"] | ||
10 | + end | ||
11 | +end |