class Fluent::SolrOutput

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_solr.rb, line 13
def initialize
  super
  require 'msgpack'
  require 'socket'
end

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_solr.rb, line 19
def configure(conf)
  super

  @host = conf.has_key?('host') ? conf['host'] : 'localhost'
  @port = conf.has_key?('port') ? conf['port'] : '8983'
  @core = conf.has_key?('core') ? conf['core'] : ''

end
format(tag, time, record) click to toggle source
# File lib/fluent/plugin/out_solr.rb, line 37
def format(tag, time, record)
  record.to_msgpack
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_solr.rb, line 33
def shutdown
  super
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_solr.rb, line 28
def start
  super
  @connection = Solr::Connection.new('http://'+@host+':'+@port+'/solr/'+@core)
end
write(chunk) click to toggle source
# File lib/fluent/plugin/out_solr.rb, line 41
def write(chunk)
  chunk.msgpack_each  { |record|
    doc = Solr::Document.new(
      :id => record["tag"] + "_" + Socket::gethostname + "_" + record["core"] + "_" + record["thread"] + "_" + record["timestamp"].gsub(/[\s\.:-]/, ""), 
      :host_s => Socket::gethostname,
      :timestamp_s => record["timestamp"],
      :level_s => record["level"],
      :thread_s => record["thread"],
      :class_s => record["class"],
      :core_s => record["core"],
      :webapp_s => record["webapp"],
      :path_s => record["path"],
      :params_s => record["params"],
      :hits_tl => record["hits"],
      :status_ti => record["status"],
      :qtime_tl => record["qtime"],
      :time_tl => record["time"],
      :tag_s => record["tag"]
    )
    request = Solr::Request::AddDocument.new(doc)
    response = @connection.send(request)
    if response.ok?
      options={}
      options.update(:softCommit => "true")
      response = @connection.send(Solr::Request::Commit4.new(options))
    end
  }
end