Class: Sunspot::Schema
- Inherits:
-
Object
- Object
- Sunspot::Schema
- Defined in:
- lib/sunspot/schema.rb
Overview
Object that encapsulates schema information for building a Solr schema.xml file. This class is used by the schema:compile task as well as the sunspot-configure-solr executable.
Defined Under Namespace
Classes: DynamicField, FieldType, FieldVariant
Constant Summary collapse
- DEFAULT_TOKENIZER =
'solr.StandardTokenizerFactory'
- DEFAULT_FILTERS =
%w(solr.StandardFilterFactory solr.LowerCaseFilterFactory)
- FIELD_TYPES =
[ FieldType.new('boolean', 'Bool', 'b'), FieldType.new('sfloat', 'SortableFloat', 'f'), FieldType.new('date', 'Date', 'd'), FieldType.new('sint', 'SortableInt', 'i'), FieldType.new('string', 'Str', 's'), FieldType.new('sdouble', 'SortableDouble', 'e'), FieldType.new('slong', 'SortableLong', 'l'), FieldType.new('tint', 'TrieInteger', 'it'), FieldType.new('tfloat', 'TrieFloat', 'ft'), FieldType.new('tdate', 'TrieInt', 'dt') ]
- FIELD_VARIANTS =
[ FieldVariant.new('multiValued', 'm'), FieldVariant.new('stored', 's') ]
Instance Attribute Summary collapse
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#tokenizer ⇒ Object
Returns the value of attribute tokenizer.
Instance Method Summary collapse
-
#add_filter(filter) ⇒ Object
Add a filter for text field tokenization.
-
#dynamic_fields ⇒ Object
DynamicField instances representing all the available types and variants.
-
#initialize ⇒ Schema
constructor
A new instance of Schema.
-
#to_xml ⇒ Object
Return an XML representation of this schema using the ERB template.
-
#types ⇒ Object
Attribute field types defined in the schema.
Constructor Details
#initialize ⇒ Schema
Returns a new instance of Schema.
37 38 39 40 |
# File 'lib/sunspot/schema.rb', line 37 def initialize @tokenizer = DEFAULT_TOKENIZER @filters = DEFAULT_FILTERS.dup end |
Instance Attribute Details
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
35 36 37 |
# File 'lib/sunspot/schema.rb', line 35 def filters @filters end |
#tokenizer ⇒ Object
Returns the value of attribute tokenizer.
35 36 37 |
# File 'lib/sunspot/schema.rb', line 35 def tokenizer @tokenizer end |
Instance Method Details
#add_filter(filter) ⇒ Object
Add a filter for text field tokenization
77 78 79 80 81 82 83 84 |
# File 'lib/sunspot/schema.rb', line 77 def add_filter(filter) @filters << if filter =~ /\./ filter else "solr.#{filter}FilterFactory" end end |
#dynamic_fields ⇒ Object
DynamicField instances representing all the available types and variants
52 53 54 55 56 57 58 59 60 |
# File 'lib/sunspot/schema.rb', line 52 def dynamic_fields fields = [] variant_combinations.each do |field_variants| FIELD_TYPES.each do |type| fields << DynamicField.new(type, field_variants) end end fields end |
#to_xml ⇒ Object
Return an XML representation of this schema using the ERB template
89 90 91 92 |
# File 'lib/sunspot/schema.rb', line 89 def to_xml template = File.join(File.dirname(__FILE__), '..', '..', 'templates', 'schema.xml.erb') ERB.new(File.read(template), nil, '-').result(binding) end |
#types ⇒ Object
Attribute field types defined in the schema
45 46 47 |
# File 'lib/sunspot/schema.rb', line 45 def types FIELD_TYPES end |