Class: Sunspot::Schema
- Inherits:
-
Object
- Object
- Sunspot::Schema
- Defined in:
- sunspot/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
- 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)
-
- (Object) filters
readonly
Returns the value of attribute filters.
-
- (Object) tokenizer
Returns the value of attribute tokenizer.
Instance Method Summary (collapse)
-
- (Object) add_filter(filter)
Add a filter for text field tokenization.
-
- (Object) dynamic_fields
DynamicField instances representing all the available types and variants.
-
- (Schema) initialize
constructor
A new instance of Schema.
-
- (Object) to_xml
Return an XML representation of this schema using the ERB template.
-
- (Object) types
Attribute field types defined in the schema.
Constructor Details
- (Schema) initialize
A new instance of Schema
37 38 39 40 |
# File 'sunspot/lib/sunspot/schema.rb', line 37 def initialize @tokenizer = DEFAULT_TOKENIZER @filters = DEFAULT_FILTERS.dup end |
Instance Attribute Details
- (Object) filters (readonly)
Returns the value of attribute filters
35 36 37 |
# File 'sunspot/lib/sunspot/schema.rb', line 35 def filters @filters end |
- (Object) tokenizer
Returns the value of attribute tokenizer
35 36 37 |
# File 'sunspot/lib/sunspot/schema.rb', line 35 def tokenizer @tokenizer end |
Instance Method Details
- (Object) add_filter(filter)
Add a filter for text field tokenization
77 78 79 80 81 82 83 84 |
# File 'sunspot/lib/sunspot/schema.rb', line 77 def add_filter(filter) @filters << if filter =~ /\./ filter else "solr.#{filter}FilterFactory" end end |
- (Object) dynamic_fields
DynamicField instances representing all the available types and variants
52 53 54 55 56 57 58 59 60 |
# File 'sunspot/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 |
- (Object) to_xml
Return an XML representation of this schema using the ERB template
89 90 91 92 |
# File 'sunspot/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 |
- (Object) types
Attribute field types defined in the schema
45 46 47 |
# File 'sunspot/lib/sunspot/schema.rb', line 45 def types FIELD_TYPES end |