Class: SimpleSolrClient::Schema::FieldType

Inherits:
Field_or_Type show all
Includes:
Analysis
Defined in:
lib/simple_solr/schema/field_type.rb

Constant Summary

Constants inherited from Field_or_Type

SimpleSolrClient::Schema::Field_or_Type::BOOL_ATTR_MAP, SimpleSolrClient::Schema::Field_or_Type::TEXT_ATTR_MAP

Instance Attribute Summary collapse

Attributes inherited from Field_or_Type

#indexed, #multi, #name, #position_increment_gap, #precision_step, #sort_missing_last, #stored, #type_name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Analysis

#index_tokens, #query_tokens

Methods inherited from Field_or_Type

#==, #[], #[]=, #to_h, #to_xml_node

Constructor Details

#initialize(*args) ⇒ FieldType

Returns a new instance of FieldType.



19
20
21
22
# File 'lib/simple_solr/schema/field_type.rb', line 19

def initialize(*args)
  super
  @xml = nil
end

Instance Attribute Details

#coreObject

Returns the value of attribute core.



17
18
19
# File 'lib/simple_solr/schema/field_type.rb', line 17

def core
  @core
end

#solr_classObject

Returns the value of attribute solr_class.



17
18
19
# File 'lib/simple_solr/schema/field_type.rb', line 17

def solr_class
  @solr_class
end

#xmlObject

Returns the value of attribute xml.



17
18
19
# File 'lib/simple_solr/schema/field_type.rb', line 17

def xml
  @xml
end

Class Method Details

.new_from_solr_hash(h) ⇒ Object



46
47
48
49
50
# File 'lib/simple_solr/schema/field_type.rb', line 46

def self.new_from_solr_hash(h)
  ft            = super
  ft.solr_class = h['class']
  ft
end

.new_from_xml(xml) ⇒ Object

Luckily, a nokogiri node can act like a hash, so we can just re-use #new_from_solr_hash



54
55
56
57
58
# File 'lib/simple_solr/schema/field_type.rb', line 54

def self.new_from_xml(xml)
  ft     = new_from_solr_hash(Nokogiri.XML(xml).children.first)
  ft.xml = xml
  ft
end

Instance Method Details

#typeObject

Make sure the type is never set, so we don’t get stuck trying to find a type’s “type”



26
27
28
# File 'lib/simple_solr/schema/field_type.rb', line 26

def type
  nil
end

#xml_node(doc) ⇒ Object

Create a Nokogiri node out of the currently-set element attributes (indexed, stored, etc.) and the XML



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/simple_solr/schema/field_type.rb', line 33

def xml_node(doc)
  ft          = Nokogiri::XML::Element.new('fieldType', doc)
  ft['class'] = self.solr_class
  xmldoc      = Nokogiri.XML(xml)
  unless xmldoc.children.empty?
    xmldoc.children.first.children.each do |c|
      ft.add_child(c)
    end
  end

  ft
end