Class: Solrizer::Suffix

Inherits:
Object
  • Object
show all
Defined in:
lib/solrizer/suffix.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*fields) ⇒ Suffix

Returns a new instance of Suffix.



6
7
8
# File 'lib/solrizer/suffix.rb', line 6

def initialize(*fields)
  @fields = fields.flatten
end

Class Method Details

.configObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/solrizer/suffix.rb', line 48

def self.config
  @config ||= OpenStruct.new :fields => [:type, :stored, :indexed, :multivalued],
    suffix_delimiter: '_',
    type_suffix: (lambda do |fields|
      type = fields.first
      case type
      when :string, :symbol # TODO `:symbol' usage ought to be deprecated
        's'
      when :text
        't'
      when :text_en
        'te'
      when :date, :time
        'dt'
      when :integer
        'i'
      when :boolean
        'b'
      when :long
        'lt'
      else
        raise Solrizer::InvalidIndexDescriptor, "Invalid datatype `#{type.inspect}'. Must be one of: :date, :time, :text, :text_en, :string, :symbol, :integer, :boolean"
      end
    end),
    stored_suffix: 's',
    indexed_suffix: 'i',
    multivalued_suffix: 'm'
end

Instance Method Details

#configObject



77
78
79
# File 'lib/solrizer/suffix.rb', line 77

def config
  @config ||= self.class.config.dup
end

#data_typeObject



26
27
28
# File 'lib/solrizer/suffix.rb', line 26

def data_type
  @fields.first
end

#has_field?(f) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/solrizer/suffix.rb', line 22

def has_field? f
  f.to_sym == :type or @fields.include? f.to_sym
end

#indexed?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/solrizer/suffix.rb', line 18

def indexed?
  has_field? :indexed
end

#multivalued?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/solrizer/suffix.rb', line 10

def multivalued?
  has_field? :multivalued
end

#stored?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/solrizer/suffix.rb', line 14

def stored?
  has_field? :stored
end

#to_sObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/solrizer/suffix.rb', line 30

def to_s

  raise Solrizer::InvalidIndexDescriptor, "Missing datatype for #{@fields}" unless data_type

  field_suffix = [config.suffix_delimiter]

  config.fields.select { |f| has_field? f }.each do |f|
    key = :"#{f}_suffix"
    field_suffix << if config.send(key).is_a? Proc
      config.send(key).call(@fields)
    else
      config.send(key)
    end
  end
  
  field_suffix.join
end