Class: StreamingUpdateSolrServer

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

Overview

Sugar on top of the org.apache.solr.client.solr.impl.StreamingUpdateSolrServer

Note that several important methods, new and commit, are direct from the java and hence not represented here where I’m just opening up the class to add some sugar. Full documentation for the raw java methods is available at lucene.apache.org/solr/api/org/apache/solr/client/solrj/impl/StreamingUpdateSolrServer.html

A quick look at important java methods you can call:

suss = StreamingUpdateSolrServer.new(solrURL, queueSize, numberOfThreads)

The constructor.

[String] solrURL The URL to your solr instance (i.e., http://solr-machine:port/solr)
[Integer] queueSize The size of the queue from which consumer threads will pull
  documents ready to be added to Solr and actually do the sending.
[Integer] numberOfThreads The number of consumer threads to do the sending-to-Solr

suss.commit

Send the commit to the solr server

suss.optimize

Send the optimize commnd to the Solr server

suss.deleteById(id)

suss.deleteById([id1, id2, id3, …])

Delete the given ID or IDs

suss.deleteByQuery(query)

Delete everything that matches +query+
[String] query A valid solr query. Everything that matches will be deleted. So, you can ditch
  it all by sending, e.g., '*:*'

Author:

  • Bill Dueber

Instance Method Summary collapse

Instance Method Details

#add(doc) ⇒ Object Also known as: <<

Add a document to the SUSS that responds to #each_pair) to add. The latter must be of the form solrfield => value or solrfield => [list, of, values]. They keys must be strings.

Examples:

Create and add a SolrInputDocument

url = 'http://solrmachine:port/solr' # URL to solr
queuesize = 10 # Size of producer cache 
threads = 2 # Number of consumer threads to push docs from queue to solr

suss = StreamingUpdateSolrServer.new(url,queuesize,threads)

doc = SolrInputDocument.new
doc << ['title', 'This is the title']
doc << ['id', 1]
suss.add doc  # or suss << doc
# repeat as desired
suss.commit

Create and add as a hash

# The "hash" just needs to be an object that responds to each_pair with field,value(s)
suss = StreamingUpdateSolrServer.new(url,queuesize,threads)
doc = {}
doc['title'] = This is the title'
doc['author'] = ['Bill', 'Mike']
suss << doc
# repeat as desired
suss.commit

Parameters:

  • doc (SolrInputDocument, #each_pair)

    The SolrInputDocument or hash (or hash-like object



96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/jruby_streaming_update_solr_server.rb', line 96

def add doc
  if doc.is_a? org.apache.solr.common.SolrInputDocument
    sussadd doc
  elsif doc.respond_to? :each_pair
    newdoc = SolrInputDocument.new
    doc.each_pair do |f,v|
      newdoc << [f,v]
    end
    sussadd newdoc
  else
    raise ArgumentError "Need to pass either an org.apache.solr.common.SolrInputDocument or a hash"
  end
end

#sussaddObject

Hang onto the java #add for internal use



65
# File 'lib/jruby_streaming_update_solr_server.rb', line 65

alias_method :sussadd, :add

#useJavabin!Object

Send requests using the Javabin binary format instead of serializing to XML Requires /update/javabin to be defined in solrconfig.xml as <requestHandler name=“/update/javabin” class=“solr.BinaryUpdateRequestHandler” />



58
59
60
# File 'lib/jruby_streaming_update_solr_server.rb', line 58

def useJavabin!
  self.setRequestWriter Java::org.apache.solr.client.solrj.impl.BinaryRequestWriter.new
end