Class: Solr::Upload

Inherits:
Object
  • Object
show all
Defined in:
lib/it_tools/solr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Upload

Returns a new instance of Upload.



118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/it_tools/solr.rb', line 118

def initialize(options = {})
  @ops = { :debug => true }
  @ops.merge! options
  mesg = 'Missing param.  Example :solr_base_url => "http://192.168.0.22:8983/solr/"' 
  raise mesg unless options[:solr_base_url]
  @log = Logger.new('log.txt')
  if level = @ops[:debug_level]
    @log.level = level
  else
    @log.level = Logger::DEBUG
  end
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



117
118
119
# File 'lib/it_tools/solr.rb', line 117

def debug
  @debug
end

#opsObject

Returns the value of attribute ops.



117
118
119
# File 'lib/it_tools/solr.rb', line 117

def ops
  @ops
end

Instance Method Details

#fooObject



153
154
155
# File 'lib/it_tools/solr.rb', line 153

def foo
  puts "bar"
end

#upload_file(filename, data, file_id, search_category) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/it_tools/solr.rb', line 130

def upload_file(filename, data, file_id, search_category)
  params = { 
    "literal.id" => file_id,
    "commit" => "true",
    "uprefix" => "attr_",
    "fmap.content" => "body"
  }
  if @ops[:search_category]
    params["literal.category"] = @ops[:search_category]
  end
  url = @ops[:solr_base_url] + "update/extract"
  @log.debug "[URL]: " + url
  post = Multipart::Post.new
  post.add_params(params)
  post.add_file(filename, data)
  resp = post.post(url)
  case resp
  when Net::HTTPOK
    @log.debug "Successfully submitted file to indexer."
  else
    @log.error "Failed to submit file to indexer."
  end
end