Class: SolrInputDocument
- Inherits:
-
Object
- Object
- SolrInputDocument
- Defined in:
- lib/jruby_streaming_update_solr_server.rb
Overview
SolrInputDocument is a wrapper around the Java SolrInputDocument. In addition to the methods below, you can call the java methods directly. Common ones are:
-
‘#clear` to empty the document
-
‘#size` to get the number of k-v pairs
-
‘#boost` and `#boost=` to get and set the document-level boost
Instance Method Summary collapse
-
#<<(fv) ⇒ Array<String>
An alternate syntax for #add.
-
#[](field) ⇒ Array<String>
Get a list of the currently-set values for the passed field.
-
#[]=(field, value) ⇒ Undefined
Set the value(s) for the given field, destroying any values that were already in there.
-
#add(field, val, boost = nil) ⇒ Undefined
Add a value to a field.
-
#delete(key) ⇒ Array<String>
Delete a key/value pair.
-
#fieldBoost(field) ⇒ Float
get the field boost.
-
#has_key?(field) ⇒ Boolean
Does this doc contain the given key?.
-
#has_value?(val) ⇒ Boolean
Does this doc have the given value?.
-
#keys ⇒ Array<String>
Get the list of keys for this document.
-
#merge!(h) ⇒ Object
(also: #additive_merge!)
Add keys and values from a hash or hash-like object to the document without removing any already-added values.
-
#oldvalues ⇒ Array<String] An array of all the values in all the keys (flattened out)
Get the values as an array.
-
#setFieldBoost(field, boost) ⇒ Float
Boost a field.
-
#to_s ⇒ Object
pretty-print.
- #values ⇒ Object
Instance Method Details
#<<(fv) ⇒ Array<String>
An alternate syntax for #add.
194 195 196 |
# File 'lib/jruby_streaming_update_solr_server.rb', line 194 def << fv self.add(fv[0], fv[1]) end |
#[](field) ⇒ Array<String>
Get a list of the currently-set values for the passed field
Note that this will always return either nil (not found) or an array, even of one element
205 206 207 208 209 |
# File 'lib/jruby_streaming_update_solr_server.rb', line 205 def [] field f = self.get(field) return nil if (f == nil) return f.values.to_a end |
#[]=(field, value) ⇒ Undefined
Set the value(s) for the given field, destroying any values that were already in there
Note that this is destructive; see #<< to add multiple values to a field
226 227 228 229 |
# File 'lib/jruby_streaming_update_solr_server.rb', line 226 def []= field, value self.removeField(field) self.add(field, value) unless value.nil? end |
#add(field, val, boost = nil) ⇒ Undefined
Add a value to a field. Will add all elements of an array in turn
172 173 174 175 176 177 178 179 180 |
# File 'lib/jruby_streaming_update_solr_server.rb', line 172 def add(field, val, boost=nil) return if val == nil if val.is_a? Array val.each {|v| self.add(field, v)} else self.addField(field, val) end self.boost = boost if boost end |
#delete(key) ⇒ Array<String>
Delete a key/value pair
313 314 315 316 317 |
# File 'lib/jruby_streaming_update_solr_server.rb', line 313 def delete key rv = self[key] self.removeField key return rv end |
#fieldBoost(field) ⇒ Float
get the field boost
157 158 159 160 161 162 163 164 |
# File 'lib/jruby_streaming_update_solr_server.rb', line 157 def fieldBoost field f = self.get(field) if f return f.getBoost else return nil end end |
#has_key?(field) ⇒ Boolean
Does this doc contain the given key?
294 295 296 |
# File 'lib/jruby_streaming_update_solr_server.rb', line 294 def has_key? field return self.containsKey(field) end |
#has_value?(val) ⇒ Boolean
Does this doc have the given value?
302 303 304 305 306 307 |
# File 'lib/jruby_streaming_update_solr_server.rb', line 302 def has_value? val self.keys.each do |k| return true if self[k].include? val end return false end |
#keys ⇒ Array<String>
Get the list of keys for this document
275 276 277 |
# File 'lib/jruby_streaming_update_solr_server.rb', line 275 def keys return self.keySet.to_a end |
#merge!(h) ⇒ Object Also known as: additive_merge!
Add keys and values from a hash or hash-like object to the document without removing any already-added values.
field=>value or field=>
250 251 252 253 254 255 256 257 |
# File 'lib/jruby_streaming_update_solr_server.rb', line 250 def merge! h unless h.respond_to? :each_pair raise ArgumentError, "Argument must respond to #each_pair" end h.each_pair do |k,v| self.add(k, v) end end |
#oldvalues ⇒ Array<String] An array of all the values in all the keys (flattened out)
Get the values as an array
282 |
# File 'lib/jruby_streaming_update_solr_server.rb', line 282 alias_method :oldvalues, :values |
#setFieldBoost(field, boost) ⇒ Float
Boost a field. Does nothing if the field does not exist
143 144 145 146 147 148 149 150 151 |
# File 'lib/jruby_streaming_update_solr_server.rb', line 143 def setFieldBoost field, boost f = self.get(field) if f f.setBoost(boost) return boost else return nil end end |
#to_s ⇒ Object
pretty-print
263 264 265 266 267 268 269 |
# File 'lib/jruby_streaming_update_solr_server.rb', line 263 def to_s rv = [] self.keys.sort.each do |k| rv << [self['id'][0], k, self[k].join('|')].join("\t") end return rv.join("\n") end |
#values ⇒ Object
283 284 285 286 287 288 |
# File 'lib/jruby_streaming_update_solr_server.rb', line 283 def values rv = self.keys.map {|k| self[k]} rv.uniq! rv.flatten! return rv end |