Class Apache_Solr_Service_Balancer

Description

Reference Implementation for using multiple Solr services in a distribution. Functionality

includes: routing of read / write operations failover (on selection) for multiple read servers

Located in /Service/Balancer.php (line 51)


	
			
Class Constant Summary
 SVN_ID = '$Id: Balancer.php 54 2011-02-04 16:29:18Z donovan.jimenez $'
 SVN_REVISION = '$Revision: 54 $'
Variable Summary
Method Summary
static string escape (string $value)
static string escapePhrase (string $value)
static string phrase (string $value)
Apache_Solr_Service_Balancer __construct ([array $readableServices = array()], [array $writeableServices = array()])
Apache_Solr_Response add (string $rawPost)
Apache_Solr_Response addDocument (Apache_Solr_Document $document, [boolean $allowDups = false], [boolean $overwritePending = true], [boolean $overwriteCommitted = true])
Apache_Solr_Response addDocuments (array $documents, [boolean $allowDups = false], [boolean $overwritePending = true], [boolean $overwriteCommitted = true])
void addReadService (mixed $service)
void addWriteService (mixed $service)
Apache_Solr_Response commit ([ $optimize = true], [boolean $waitFlush = true], [boolean $waitSearcher = true], [ $timeout = 3600])
Apache_Solr_Response delete (string $rawPost, [float $timeout = 3600])
Apache_Solr_Response deleteById (string $id, [boolean $fromPending = true], [boolean $fromCommitted = true], [float $timeout = 3600])
Apache_Solr_Response deleteByMultipleIds (array $ids, [boolean $fromPending = true], [boolean $fromCommitted = true], [float $timeout = 3600])
Apache_Solr_Response deleteByQuery (string $rawQuery, [boolean $fromPending = true], [boolean $fromCommitted = true], [float $timeout = 3600])
Apache_Solr_Response extract (string $file, [array $params = array()], [Apache_Solr_Document $document = null], [string $mimetype = 'application/octet-stream'])
Apache_Solr_Response extractFromString (string $data, [array $params = array()], [Apache_Solr_Document $document = null], [string $mimetype = 'application/octet-stream'])
boolean getCreateDocuments ()
Apache_Solr_Response optimize ([boolean $waitFlush = true], [boolean $waitSearcher = true], [float $timeout = 3600])
void removeReadService (mixed $service)
void removeWriteService (mixed $service)
Apache_Solr_Response search (string $query, [int $offset = 0], [int $limit = 10], [array $params = array()], [string $method = Apache_Solr_Service::METHOD_GET])
void setCreateDocuments (boolean $createDocuments)
void setReadPingTimeout ( $timeout)
void setUseBackoff ( $enable)
void setWritePingTimeout ( $timeout)
string _getServiceId (string $host, integer $port, string $path)
Apache_Solr_Service _selectReadService ([ $forceSelect = false])
Apache_Solr_Service _selectWriteService ([ $forceSelect = false])
Apache_Solr_Service _selectWriteServiceSafe ([ $forceSelect = false])
Variables
mixed $_backoffEscalation = 2.0 (line 77)
  • access: protected
mixed $_backoffLimit = 600 (line 76)
  • access: protected
mixed $_createDocuments = true (line 63)
  • access: protected
mixed $_currentReadService = null (line 68)
  • access: protected
mixed $_currentWriteService = null (line 69)
  • access: protected
mixed $_defaultBackoff = 2.0 (line 78)
  • access: protected
mixed $_readableServices = array() (line 65)
  • access: protected
mixed $_readPingTimeout = 2 (line 71)
  • access: protected
mixed $_useBackoff = false (line 75)
  • access: protected
mixed $_writeableServices = array() (line 66)
  • access: protected
mixed $_writePingTimeout = 4 (line 72)
  • access: protected
Methods
static escape (line 88)

Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.

NOTE: inside a phrase fewer characters need escaped, use Apache_Solr_Service::escapePhrase() instead

  • access: public
static string escape (string $value)
  • string $value
static escapePhrase (line 99)

Escape a value meant to be contained in a phrase for special query characters

  • access: public
static string escapePhrase (string $value)
  • string $value
static phrase (line 110)

Convenience function for creating phrase syntax from a value

  • access: public
static string phrase (string $value)
  • string $value
Constructor __construct (line 121)

Constructor. Takes arrays of read and write service instances or descriptions

  • access: public
Apache_Solr_Service_Balancer __construct ([array $readableServices = array()], [array $writeableServices = array()])
  • array $readableServices
  • array $writeableServices
add (line 491)

Raw Add Method. Takes a raw post body and sends it to the update service. Post body should be a complete and well formed "add" xml document.

  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • access: public
Apache_Solr_Response add (string $rawPost)
  • string $rawPost
addDocument (line 526)

Add a Solr Document to the index

  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • access: public
Apache_Solr_Response addDocument (Apache_Solr_Document $document, [boolean $allowDups = false], [boolean $overwritePending = true], [boolean $overwriteCommitted = true])
  • Apache_Solr_Document $document
  • boolean $allowDups
  • boolean $overwritePending
  • boolean $overwriteCommitted
addDocuments (line 561)

Add an array of Solr Documents to the index all at once

  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • access: public
Apache_Solr_Response addDocuments (array $documents, [boolean $allowDups = false], [boolean $overwritePending = true], [boolean $overwriteCommitted = true])
  • array $documents: Should be an array of Apache_Solr_Document instances
  • boolean $allowDups
  • boolean $overwritePending
  • boolean $overwriteCommitted
addReadService (line 172)

Adds a service instance or service descriptor (if it is already not added)

  • throws: Apache_Solr_InvalidArgumentException If service descriptor is not valid
  • access: public
void addReadService (mixed $service)
  • mixed $service
addWriteService (line 240)

Adds a service instance or service descriptor (if it is already not added)

  • throws: Apache_Solr_InvalidArgumentException If service descriptor is not valid
  • access: public
void addWriteService (mixed $service)
  • mixed $service
commit (line 595)

Send a commit command. Will be synchronous unless both wait parameters are set to false.

  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • access: public
Apache_Solr_Response commit ([ $optimize = true], [boolean $waitFlush = true], [boolean $waitSearcher = true], [ $timeout = 3600])
  • boolean $waitFlush
  • boolean $waitSearcher
  • $optimize
  • $timeout
delete (line 629)

Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be a complete and well formed "delete" xml document

  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • access: public
Apache_Solr_Response delete (string $rawPost, [float $timeout = 3600])
  • string $rawPost
  • float $timeout: Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
deleteById (line 664)

Create a delete document based on document ID

  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • access: public
Apache_Solr_Response deleteById (string $id, [boolean $fromPending = true], [boolean $fromCommitted = true], [float $timeout = 3600])
  • string $id
  • boolean $fromPending
  • boolean $fromCommitted
  • float $timeout: Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
deleteByMultipleIds (line 699)

Create and post a delete document based on multiple document IDs.

  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • access: public
Apache_Solr_Response deleteByMultipleIds (array $ids, [boolean $fromPending = true], [boolean $fromCommitted = true], [float $timeout = 3600])
  • array $ids: Expected to be utf-8 encoded strings
  • boolean $fromPending
  • boolean $fromCommitted
  • float $timeout: Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
deleteByQuery (line 734)

Create a delete document based on a query and submit it

  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • access: public
Apache_Solr_Response deleteByQuery (string $rawQuery, [boolean $fromPending = true], [boolean $fromCommitted = true], [float $timeout = 3600])
  • string $rawQuery
  • boolean $fromPending
  • boolean $fromCommitted
  • float $timeout: Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
extract (line 776)

Use Solr Cell to extract document contents. See http://wiki.apache.org/solr/ExtractingRequestHandler for information on how to use Solr Cell and what parameters are available.

NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost." as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also pass in a document isntance with an "id" field" - the document's value(s) will take precedence).

  • throws: Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
  • access: public
Apache_Solr_Response extract (string $file, [array $params = array()], [Apache_Solr_Document $document = null], [string $mimetype = 'application/octet-stream'])
  • string $file: Path to file to extract data from
  • array $params: optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
  • Apache_Solr_Document $document: optional document that will be used to generate post parameters (literal.* and boost.* params)
  • string $mimetype: optional mimetype specification (for the file being extracted)
extractFromString (line 820)

Use Solr Cell to extract document contents. See http://wiki.apache.org/solr/ExtractingRequestHandler for information on how to use Solr Cell and what parameters are available.

NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost." as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also pass in a document isntance with an "id" field" - the document's value(s) will take precedence).

  • todo: Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
  • throws: Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
  • access: public
Apache_Solr_Response extractFromString (string $data, [array $params = array()], [Apache_Solr_Document $document = null], [string $mimetype = 'application/octet-stream'])
  • string $data: Data that will be passed to Solr Cell
  • array $params: optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
  • Apache_Solr_Document $document: optional document that will be used to generate post parameters (literal.* and boost.* params)
  • string $mimetype: optional mimetype specification (for the file being extracted)
getCreateDocuments (line 477)

Get the current state of teh create documents flag.

  • access: public
boolean getCreateDocuments ()
optimize (line 855)

Send an optimize command. Will be synchronous unless both wait parameters are set to false.

  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • access: public
Apache_Solr_Response optimize ([boolean $waitFlush = true], [boolean $waitSearcher = true], [float $timeout = 3600])
  • boolean $waitFlush
  • boolean $waitSearcher
  • float $timeout: Maximum expected duration of the optimize operation on the server (otherwise, will throw a communication exception)
removeReadService (line 202)

Removes a service instance or descriptor from the available services

  • throws: Apache_Solr_InvalidArgumentException If service descriptor is not valid
  • access: public
void removeReadService (mixed $service)
  • mixed $service
removeWriteService (line 270)

Removes a service instance or descriptor from the available services

  • throws: Apache_Solr_InvalidArgumentException If service descriptor is not valid
  • access: public
void removeWriteService (mixed $service)
  • mixed $service
search (line 891)

Simple Search interface

  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • access: public
Apache_Solr_Response search (string $query, [int $offset = 0], [int $limit = 10], [array $params = array()], [string $method = Apache_Solr_Service::METHOD_GET])
  • string $query: The raw query string
  • int $offset: The starting offset for result documents
  • int $limit: The maximum number of result documents to return
  • array $params: key / value pairs for query parameters, use arrays for multivalued parameters
  • string $method: The HTTP method (Apache_Solr_Service::METHOD_GET or Apache_Solr_Service::METHOD::POST)
setCreateDocuments (line 460)

Set the create documents flag. This determines whether Apache_Solr_Response objects will parse the response and create Apache_Solr_Document instances in place.

  • access: public
void setCreateDocuments (boolean $createDocuments)
  • boolean $createDocuments
setReadPingTimeout (line 136)
  • access: public
void setReadPingTimeout ( $timeout)
  • $timeout
setUseBackoff (line 146)
  • access: public
void setUseBackoff ( $enable)
  • $enable
setWritePingTimeout (line 141)
  • access: public
void setWritePingTimeout ( $timeout)
  • $timeout
_getServiceId (line 159)

Generates a service ID

  • access: protected
string _getServiceId (string $host, integer $port, string $path)
  • string $host
  • integer $port
  • string $path
_selectReadService (line 308)

Iterate through available read services and select the first with a ping that satisfies configured timeout restrictions (or the default)

  • throws: Apache_Solr_NoServiceAvailableException If there are no read services that meet requirements
  • access: protected
Apache_Solr_Service _selectReadService ([ $forceSelect = false])
  • $forceSelect
_selectWriteService (line 356)

Iterate through available write services and select the first with a ping that satisfies configured timeout restrictions (or the default)

  • throws: Apache_Solr_NoServiceAvailableException If there are no write services that meet requirements
  • access: protected
Apache_Solr_Service _selectWriteService ([ $forceSelect = false])
  • $forceSelect
_selectWriteServiceSafe (line 412)

Iterate through available write services and select the first with a ping

that satisfies configured timeout restrictions (or the default). The timeout period will increase until a connection is made or the limit is reached. This will allow for increased reliability with heavily loaded server(s).

  • throws: Apache_Solr_NoServiceAvailableException If there are no write services that meet requirements
  • access: protected
Apache_Solr_Service _selectWriteServiceSafe ([ $forceSelect = false])
  • $forceSelect
Class Constants
SVN_ID = '$Id: Balancer.php 54 2011-02-04 16:29:18Z donovan.jimenez $' (line 61)

SVN ID meta data for this class

SVN_REVISION = '$Revision: 54 $' (line 56)

SVN Revision meta data for this class

Documentation generated on Wed, 04 May 2011 11:01:10 -0400 by phpDocumentor 1.4.3