Class: Caoutsearch::Filter::Base

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

Direct Known Subclasses

Boolean, Date, Default, GeoPoint, Match, Range

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, original_value, type, options = {}) ⇒ Base

Returns a new instance of Base.



12
13
14
15
16
17
# File 'lib/caoutsearch/filter/base.rb', line 12

def initialize(key, original_value, type, options = {})
  @key = key
  @original_value = original_value
  @type = type
  @options = options
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



6
7
8
# File 'lib/caoutsearch/filter/base.rb', line 6

def key
  @key
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/caoutsearch/filter/base.rb', line 6

def options
  @options
end

#original_valueObject (readonly)

Returns the value of attribute original_value.



6
7
8
# File 'lib/caoutsearch/filter/base.rb', line 6

def original_value
  @original_value
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/caoutsearch/filter/base.rb', line 6

def type
  @type
end

Class Method Details

.callObject



8
9
10
# File 'lib/caoutsearch/filter/base.rb', line 8

def self.call(...)
  new(...).as_json
end

Instance Method Details

#as_jsonObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/caoutsearch/filter/base.rb', line 24

def as_json
  filter = self.filter
  filter = group_filters(filter) if filter.is_a?(Array)

  if filter.present? && nested_query?
    filter = {
      nested: {
        path: nested_path,
        query: {bool: {filter: Array.wrap(filter)}}
      }
    }
  end

  filter
end

#filterObject

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/caoutsearch/filter/base.rb', line 40

def filter
  raise NotImplementedError
end

#valueObject



19
20
21
22
# File 'lib/caoutsearch/filter/base.rb', line 19

def value
  @value = cast_value(original_value) unless defined?(@value)
  @value
end