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 | 434 | # http://www.elasticsearch.org/guide/reference/mapping/multi-field-type/ |
435 | 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 | 441 | mappings = { |
438 | 442 | properties: mapping, |
439 | 443 | _routing: routing, | ... | ... |
lib/searchkick/model.rb
... | ... | @@ -5,7 +5,7 @@ module Searchkick |
5 | 5 | |
6 | 6 | unknown_keywords = options.keys - [:_all, :_type, :batch_size, :callbacks, :case_sensitive, :conversions, :deep_paging, :default_fields, |
7 | 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 | 9 | :special_characters, :stem, :stem_conversions, :suggest, :synonyms, :text_end, |
10 | 10 | :text_middle, :text_start, :word, :wordnet, :word_end, :word_middle, :word_start] |
11 | 11 | raise ArgumentError, "unknown keywords: #{unknown_keywords.join(", ")}" if unknown_keywords.any? | ... | ... |
test/models/product.rb
... | ... | @@ -20,9 +20,10 @@ class Product |
20 | 20 | highlight: [:name], |
21 | 21 | filterable: [:name, :color, :description], |
22 | 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 | 28 | def search_data |
28 | 29 | serializable_hash.except("id", "_id").merge( |
... | ... | @@ -31,7 +32,8 @@ class Product |
31 | 32 | location: {lat: latitude, lon: longitude}, |
32 | 33 | multiple_locations: [{lat: latitude, lon: longitude}, {lat: 0, lon: 0}], |
33 | 34 | aisle: aisle, |
34 | - details: details | |
35 | + details: details, | |
36 | + categories: categories | |
35 | 37 | ) |
36 | 38 | end |
37 | 39 | ... | ... |
... | ... | @@ -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 | ... | ... |