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, lambda, block, source_location, single: false) ⇒ ToFieldStep

Returns a new instance of ToFieldStep.



4
5
6
7
8
# File 'lib/traject_plus/indexer/step.rb', line 4

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

  @single = single
end

Class Method Details

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



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/traject_plus/indexer/step.rb', line 23

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])

  if field.single?
    context.output_hash[field_name] = accumulator.first if accumulator.length > 0
  else
    context.output_hash[field_name] ||= []

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

Instance Method Details

#add_accumulator_to_context!(accumulator, context) ⇒ Object



19
20
21
# File 'lib/traject_plus/indexer/step.rb', line 19

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

#single?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/traject_plus/indexer/step.rb', line 10

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)


15
16
17
# File 'lib/traject_plus/indexer/step.rb', line 15

def to_field_step?
  false
end