Class: Traject::JsonWriter
- Inherits:
-
LineWriter
- Object
- LineWriter
- Traject::JsonWriter
- Defined in:
- lib/traject/json_writer.rb
Overview
A writer for Traject::Indexer, that just writes out all the output as Json. It’s newline delimitted json, but right now no checks to make sure there is no internal newlines as whitespace in the json. TODO, add that.
Should be thread-safe (ie, multiple worker threads can be calling #put concurrently), by wrapping write to actual output file in a mutex synchronize. This does not seem to effect performance much, as far as I could tell benchmarking.
You can force pretty-printing with setting ‘json_writer.pretty_print’ of boolean true or string ‘true’. Useful mostly for human checking of output.
Output will be sent to settings string path, or else settings (ruby IO object), or else stdout.
Instance Attribute Summary
Attributes inherited from LineWriter
Instance Method Summary collapse
Methods inherited from LineWriter
#close, #initialize, #output_file, #put
Constructor Details
This class inherits a constructor from Traject::LineWriter
Instance Method Details
#serialize(context) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/traject/json_writer.rb', line 21 def serialize(context) hash = context.output_hash if settings["json_writer.pretty_print"] JSON.pretty_generate(hash) else JSON.generate(hash) end end |