Class: Solr::Query::Request::Filter

Inherits:
Object
  • Object
show all
Includes:
Support::SchemaHelper
Defined in:
lib/solr/query/request/filter.rb

Constant Summary collapse

EQUAL_TYPE =
:equal
NOT_EQUAL_TYPE =
:not_equal

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support::SchemaHelper

#solarize_field

Constructor Details

#initialize(type:, field:, value:) ⇒ Filter

Returns a new instance of Filter.



14
15
16
17
18
# File 'lib/solr/query/request/filter.rb', line 14

def initialize(type:, field:, value:)
  @type = type
  @field = field
  @value = value
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



12
13
14
# File 'lib/solr/query/request/filter.rb', line 12

def field
  @field
end

#typeObject (readonly)

Returns the value of attribute type.



12
13
14
# File 'lib/solr/query/request/filter.rb', line 12

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



12
13
14
# File 'lib/solr/query/request/filter.rb', line 12

def value
  @value
end

Instance Method Details

#solr_fieldObject



24
25
26
# File 'lib/solr/query/request/filter.rb', line 24

def solr_field
  solarize_field(@field)
end

#solr_valueObject



28
29
30
31
32
33
34
35
36
# File 'lib/solr/query/request/filter.rb', line 28

def solr_value
  if value.is_a?(::Array)
    value.map { |v| to_primitive_solr_value(v) }.join(' OR ')
  elsif value.is_a?(::Range)
    to_interval_solr_value(value)
  else
    to_primitive_solr_value(value)
  end
end

#to_solr_sObject



20
21
22
# File 'lib/solr/query/request/filter.rb', line 20

def to_solr_s
  "#{solr_prefix}#{solr_field}:(#{solr_value})"
end