Class: Caoutsearch::Mappings

Inherits:
Object
  • Object
show all
Defined in:
lib/caoutsearch/mappings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mappings) ⇒ Mappings

Build an index mapping

Caoutsearch::Mapping.new({ properties: [...], )


11
12
13
# File 'lib/caoutsearch/mappings.rb', line 11

def initialize(mappings)
  @mappings = mappings.deep_symbolize_keys
end

Instance Attribute Details

#index_nameObject (readonly)

Returns the value of attribute index_name.



5
6
7
# File 'lib/caoutsearch/mappings.rb', line 5

def index_name
  @index_name
end

Instance Method Details

#find(*args) ⇒ Object



28
29
30
# File 'lib/caoutsearch/mappings.rb', line 28

def find(*args)
  each_path(*args).map { |hash, _| hash }.last
end

#find_type(*args) ⇒ Object



32
33
34
35
# File 'lib/caoutsearch/mappings.rb', line 32

def find_type(*args)
  definition = find(*args)
  definition[:type]&.to_s if definition.present?
end

#include?(*args) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/caoutsearch/mappings.rb', line 24

def include?(*args)
  find(*args).present?
end

#include_in_parent?(*args) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
45
46
# File 'lib/caoutsearch/mappings.rb', line 41

def include_in_parent?(*args)
  path = nested_path(*args)
  return nil unless path

  !!find(path)[:include_in_parent]
end

#nested?(*args) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/caoutsearch/mappings.rb', line 37

def nested?(*args)
  nested_path(*args).present?
end

#nested_path(*args) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/caoutsearch/mappings.rb', line 48

def nested_path(*args)
  return nil unless include?(*args)

  each_path(*args) do |hash, current_path|
    break nil unless hash
    return current_path if hash[:type] == "nested"
  end

  nil
end

#to_hashObject Also known as: as_json



15
16
17
# File 'lib/caoutsearch/mappings.rb', line 15

def to_hash
  @mappings
end

#to_jsonObject



20
21
22
# File 'lib/caoutsearch/mappings.rb', line 20

def to_json(*)
  MultiJson.dump(as_json)
end