Class: Solr::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/solr/field.rb

Constant Summary collapse

VALID_PARAMS =
[:boost]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Field

Accepts an optional :boost parameter, used to boost the relevance of a particular field.



23
24
25
26
27
28
29
# File 'lib/solr/field.rb', line 23

def initialize(params)
  @boost = params[:boost]
  name_key = (params.keys - VALID_PARAMS).first
  @name, @value = name_key.to_s, params[name_key]
  # Convert any Time values into UTC/XML schema format (which Solr requires).
  @value = @value.respond_to?(:utc) ? @value.utc.xmlschema : @value.to_s
end

Instance Attribute Details

#boostObject

Returns the value of attribute boost.



20
21
22
# File 'lib/solr/field.rb', line 20

def boost
  @boost
end

#nameObject

Returns the value of attribute name.



18
19
20
# File 'lib/solr/field.rb', line 18

def name
  @name
end

#valueObject

Returns the value of attribute value.



19
20
21
# File 'lib/solr/field.rb', line 19

def value
  @value
end

Instance Method Details

#to_xmlObject



31
32
33
34
35
36
37
# File 'lib/solr/field.rb', line 31

def to_xml
  e = Solr::XML::Element.new 'field'
  e.attributes['name'] = @name
  e.attributes['boost'] = @boost.to_s if @boost
  e.text = @value
  return e
end