Class: TrajectPlus::Indexer::ToFieldStep

Inherits:
Traject::Indexer::ToFieldStep
  • Object
show all
Defined in:
lib/traject_plus/indexer/step.rb

Direct Known Subclasses

ComposeStep

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fieldname, procs, block, source_location, single: false) ⇒ ToFieldStep

Returns a new instance of ToFieldStep.

Parameters:

  • single (Bool) (defaults to: false)

    if true, this outputs a scalar value (rather than an Array) by default Traject only outputs arrays.



6
7
8
9
10
# File 'lib/traject_plus/indexer/step.rb', line 6

def initialize(fieldname, procs, block, source_location, single: false)
  super(fieldname, procs, block, source_location)

  @single = single
end

Class Method Details

.add_accumulator_to_context!(field, field_name, accumulator, context) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/traject_plus/indexer/step.rb', line 25

def self.add_accumulator_to_context!(field, field_name, accumulator, context)
  accumulator.compact! unless context.settings[ALLOW_NIL_VALUES]
  return if accumulator.empty? and not (context.settings[ALLOW_EMPTY_FIELDS])

  # field_name can actually be an array of field names
  Array(field_name).each do |a_field_name|
    if field.single?
      context.output_hash[a_field_name] = accumulator.first if accumulator.length > 0
    else
      context.output_hash[a_field_name] ||= []

      existing_accumulator = context.output_hash[a_field_name].concat(accumulator)
      existing_accumulator.uniq! unless context.settings[ALLOW_DUPLICATE_VALUES]
    end
  end
end

Instance Method Details

#add_accumulator_to_context!(accumulator, context) ⇒ Object



21
22
23
# File 'lib/traject_plus/indexer/step.rb', line 21

def add_accumulator_to_context!(accumulator, context)
  self.class.add_accumulator_to_context!(self, field_name, accumulator, context)
end

#single?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/traject_plus/indexer/step.rb', line 12

def single?
  !!@single
end

#to_field_step?Boolean

disable to_field_step? so we can implement our own version of add_accumulator_to_context

Returns:

  • (Boolean)


17
18
19
# File 'lib/traject_plus/indexer/step.rb', line 17

def to_field_step?
  false
end