<commit_before>require 'rsolr'
require 'date' # NameError deep in Solrizer without this.
require 'singleton'
require 'logger'
require_relative 'converter'
require_relative '../../lib/solr'
require_relative 'log_roller'

class Ingester
  include Singleton
  include LogRoller

  def initialize
    @solr = Solr.instance.connect
  end

  def ingest(filename, cache_path = nil)
    errors = []
    if cache_path
      Converter.new(File.read(filename), cache_path)
    else
      Converter.new(File.read(filename))
    end.each do |asset|
      begin
        @solr.add(asset.to_solr)
        $LOG.info("Added #{asset.id}")
      rescue => e
        errors.push(asset.id)
        $LOG.warn("Error on #{asset.id}: #{e}")
      end
    end
    @solr.commit
    $LOG.info("Commit")
    $LOG.info("#{errors.count} errors")
  end

end

if __FILE__ == $PROGRAM_NAME
  ARGV.each do |filename|
    Ingester.instance.ingest(filename)
  end
end<commit_msg>Fix failed test<commit_after>require 'rsolr'
require 'date' # NameError deep in Solrizer without this.
require 'singleton'
require 'logger'
require_relative 'converter'
require_relative '../../lib/solr'
require_relative 'log_roller'

class Ingester
  include Singleton
  include LogRoller

  def initialize
    @solr = Solr.instance.connect
  end

  def ingest(filename, cache_path = nil)
    errors = []
    if cache_path
      Converter.new(File.read(filename), cache_path)
    else
      Converter.new(File.read(filename))
    end.each do |asset|
      begin
        @solr.add(asset.to_solr)
        log.info("Added #{asset.id}")
      rescue => e
        errors.push(asset.id)
        log.warn("Error on #{asset.id}: #{e}")
      end
    end
    @solr.commit
    log.info("Commit")
    log.info("#{errors.count} errors")
  end

end

if __FILE__ == $PROGRAM_NAME
  ARGV.each do |filename|
    Ingester.instance.ingest(filename)
  end
end
{'fraction_non_alphanumeric': 0.12114771519659936, 'fraction_numerical': 0.0, 'mean_word_length': 3.032119914346895, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7356067', 'n_tokens_mistral': 639, 'n_tokens_neox': 632, 'n_words': 147}