final class SolrClient (View source)

(PECL solr >= 0.9.2)
Class SolrClient
This class is used to send requests to a Solr server. Currently, cloning and serialization of SolrClient instances is not supported.

Constants

SEARCH_SERVLET_TYPE

UPDATE_SERVLET_TYPE

THREADS_SERVLET_TYPE

PING_SERVLET_TYPE

TERMS_SERVLET_TYPE

SYSTEM_SERVLET_TYPE

DEFAULT_SEARCH_SERVLET

DEFAULT_UPDATE_SERVLET

DEFAULT_THREADS_SERVLET

DEFAULT_PING_SERVLET

DEFAULT_TERMS_SERVLET

DEFAULT_SYSTEM_SERVLET

Methods

addDocument(SolrInputDocument $doc, bool $overwrite = true, int $commitWithin = 0)

(PECL solr >= 0.9.2)
Adds a document to the index

addDocuments(array $docs, bool $overwrite = true, int $commitWithin = 0)

(PECL solr >= 0.9.2)
Adds a collection of SolrInputDocument instances to the index

commit(bool $softCommit = false, bool $waitSearcher = true, bool $expungeDeletes = false)

(PECL solr >= 0.9.2)
Finalizes all add/deletes made to the index

__construct(array $clientOptions)

(PECL solr >= 0.9.2)
SolrClient constructor.

deleteById(string $id)

(PECL solr >= 0.9.2)
Delete by Id

deleteByIds(array $ids)

(PECL solr >= 0.9.2)
Deletes by Ids

deleteByQueries(array $queries)

(PECL solr >= 0.9.2)
Removes all documents matching any of the queries

deleteByQuery(string $query)

(PECL solr >= 0.9.2)
Deletes all documents matching the given query

__destruct()

(PECL solr >= 0.9.2)
Destructor for SolrClient

getById(string $id)

(PECL solr >= 2.2.0)
Get Document By Id. Utilizes Solr Realtime Get (RTG).

getByIds(array $ids)

(PECL solr >= 2.2.0)
Get Documents by their Ids. Utilizes Solr Realtime Get (RTG).

string
getDebug()

(PECL solr >= 0.9.7)
Returns the debug data for the last connection attempt

array
getOptions()

(PECL solr >= 0.9.6)
Returns the client options set internally

optimize(int $maxSegments = 1, bool $softCommit = true, bool $waitSearcher = true)

(PECL solr >= 0.9.2)
Defragments the index

ping()

(PECL solr >= 0.9.2)
Checks if Solr server is still up

query(SolrParams $query)

(PECL solr >= 0.9.2)
Sends a query to the server

request(string $raw_request)

(PECL solr >= 0.9.2)
Sends a raw update request

rollback()

(PECL solr >= 0.9.2)
Rollbacks all add/deletes made to the index since the last commit

setResponseWriter(string $responseWriter)

(PECL solr >= 0.9.11)
Sets the response writer used to prepare the response from Solr

bool
setServlet(int $type, string $value)

(PECL solr >= 0.9.2)
Changes the specified servlet type to a new value

system()

(PECL solr >= 2.0.0)
Retrieve Solr Server information

threads()

(PECL solr >= 0.9.2)
Checks the threads status

Details

SolrUpdateResponse addDocument(SolrInputDocument $doc, bool $overwrite = true, int $commitWithin = 0)

(PECL solr >= 0.9.2)
Adds a document to the index

Parameters

SolrInputDocument $doc

The SolrInputDocument instance.

bool $overwrite

[optional]

Whether to overwrite existing document or not. If FALSE there will be duplicates (several documents with the same ID).

Warning
PECL Solr < 2.0 $allowDups was used instead of $overwrite, which does the same functionality with exact opposite bool flag.

$allowDups = false is the same as $overwrite = true
int $commitWithin

[optional]

Number of milliseconds within which to auto commit this document. Available since Solr 1.4 . Default (0) means disabled.

When this value specified, it leaves the control of when to do the commit to Solr itself, optimizing number of commits to a minimum while still fulfilling the update latency requirements, and Solr will automatically do a commit when the oldest add in the buffer is due.

Return Value

SolrUpdateResponse

Returns a SolrUpdateResponse object or throws an Exception on failure.

Exceptions

SolrClientException
SolrServerException

SolrUpdateResponse addDocuments(array $docs, bool $overwrite = true, int $commitWithin = 0)

(PECL solr >= 0.9.2)
Adds a collection of SolrInputDocument instances to the index

Parameters

array $docs

An array containing the collection of SolrInputDocument instances. This array must be an actual variable.

bool $overwrite

[optional]

Whether to overwrite existing document or not. If FALSE there will be duplicates (several documents with the same ID).

Warning
PECL Solr < 2.0 $allowDups was used instead of $overwrite, which does the same functionality with exact opposite bool flag.

$allowDups = false is the same as $overwrite = true
int $commitWithin

[optional]

Number of milliseconds within which to auto commit this document. Available since Solr 1.4 . Default (0) means disabled.

When this value specified, it leaves the control of when to do the commit to Solr itself, optimizing number of commits to a minimum while still fulfilling the update latency requirements, and Solr will automatically do a commit when the oldest add in the buffer is due.

Return Value

SolrUpdateResponse

Returns a SolrUpdateResponse object or throws an Exception on failure.

Exceptions

SolrClientException
SolrServerException

SolrUpdateResponse commit(bool $softCommit = false, bool $waitSearcher = true, bool $expungeDeletes = false)

(PECL solr >= 0.9.2)
Finalizes all add/deletes made to the index

Parameters

bool $softCommit

[optional]

This will refresh the 'view' of the index in a more performant manner, but without "on-disk" guarantees. (Solr4.0+)

A soft commit is much faster since it only makes index changes visible and does not fsync index files or write a new index descriptor. If the JVM crashes or there is a loss of power, changes that occurred after the last hard commit will be lost. Search collections that have near-real-time requirements (that want index changes to be quickly visible to searches) will want to soft commit often but hard commit less frequently.

bool $waitSearcher

[optional]

block until a new searcher is opened and registered as the main query searcher, making the changes visible.

bool $expungeDeletes

[optional]

Merge segments with deletes away. (Solr1.4+)

Return Value

SolrUpdateResponse

Returns a SolrUpdateResponse object or throws an Exception on failure.

Exceptions

SolrClientException
SolrServerException

__construct(array $clientOptions)

(PECL solr >= 0.9.2)
SolrClient constructor.

Parameters

array $clientOptions

This is an array containing one of the following keys :

  • secure: (Boolean value indicating whether or not to connect in secure mode)
  • hostname: (The hostname for the Solr server)
  • port: (The port number)
  • path: (The path to solr)
  • wt: (The name of the response writer e.g. xml, json)
  • login: (The username used for HTTP Authentication, if any)
  • password: (The HTTP Authentication password)
  • proxy_host: (The hostname for the proxy server, if any)
  • proxy_port: (The proxy port)
  • proxy_login: (The proxy username)
  • proxy_password: (The proxy password)
  • timeout: (This is maximum time in seconds allowed for the http data transfer operation. Default is 30 seconds)
  • ssl_cert: (File name to a PEM-formatted file containing the private key + private certificate (concatenated in that order) )
  • ssl_key: (File name to a PEM-formatted private key file only)
  • ssl_keypassword: (Password for private key)
  • ssl_cainfo: (Name of file holding one or more CA certificates to verify peer with)
  • ssl_capath: (Name of directory holding multiple CA certificates to verify peer with )

Please note the if the ssl_cert file only contains the private certificate, you have to specify a separate ssl_key file.

The ssl_keypassword option is required if the ssl_cert or ssl_key options are set.

Exceptions

SolrIllegalArgumentException

SolrUpdateResponse deleteById(string $id)

(PECL solr >= 0.9.2)
Delete by Id

Parameters

string $id

The value of the uniqueKey field declared in the schema

Return Value

SolrUpdateResponse

Returns a SolrUpdateResponse on success and throws an exception on failure.

Exceptions

SolrClientException
SolrServerException

SolrUpdateResponse deleteByIds(array $ids)

(PECL solr >= 0.9.2)
Deletes by Ids

Parameters

array $ids

An array of IDs representing the uniqueKey field declared in the schema for each document to be deleted. This must be an actual php variable.

Return Value

SolrUpdateResponse

Returns a SolrUpdateResponse on success and throws an exception on failure.

Exceptions

SolrClientException
SolrServerException

SolrUpdateResponse deleteByQueries(array $queries)

(PECL solr >= 0.9.2)
Removes all documents matching any of the queries

Parameters

array $queries

The array of queries. This must be an actual php variable.

Return Value

SolrUpdateResponse

Returns a SolrUpdateResponse on success and throws an exception on failure.

Exceptions

SolrClientException
SolrServerException

SolrUpdateResponse deleteByQuery(string $query)

(PECL solr >= 0.9.2)
Deletes all documents matching the given query

Parameters

string $query

The query

Return Value

SolrUpdateResponse

Returns a SolrUpdateResponse on success and throws an exception on failure.

Exceptions

SolrClientException
SolrServerException

__destruct()

(PECL solr >= 0.9.2)
Destructor for SolrClient

SolrQueryResponse getById(string $id)

(PECL solr >= 2.2.0)
Get Document By Id. Utilizes Solr Realtime Get (RTG).

Parameters

string $id

Document ID

Return Value

SolrQueryResponse

SolrQueryResponse getByIds(array $ids)

(PECL solr >= 2.2.0)
Get Documents by their Ids. Utilizes Solr Realtime Get (RTG).

Parameters

array $ids

Document ids

Return Value

SolrQueryResponse

string getDebug()

(PECL solr >= 0.9.7)
Returns the debug data for the last connection attempt

Return Value

string

Returns a string on success and null if there is nothing to return.

array getOptions()

(PECL solr >= 0.9.6)
Returns the client options set internally

Return Value

array

Returns an array containing all the options for the SolrClient object set internally.

SolrUpdateResponse optimize(int $maxSegments = 1, bool $softCommit = true, bool $waitSearcher = true)

(PECL solr >= 0.9.2)
Defragments the index

Parameters

int $maxSegments

Optimizes down to at most this number of segments. Since Solr 1.3

bool $softCommit

This will refresh the 'view' of the index in a more performant manner, but without "on-disk" guarantees. (Solr4.0+)

bool $waitSearcher

Block until a new searcher is opened and registered as the main query searcher, making the changes visible.

Return Value

SolrUpdateResponse

Returns a SolrUpdateResponse on success and throws an exception on failure.

Exceptions

SolrClientException
SolrServerException

SolrPingResponse ping()

(PECL solr >= 0.9.2)
Checks if Solr server is still up

Return Value

SolrPingResponse

Returns a SolrPingResponse object on success and throws an exception on failure.

Exceptions

SolrClientException
SolrServerException

SolrQueryResponse query(SolrParams $query)

(PECL solr >= 0.9.2)
Sends a query to the server

Parameters

SolrParams $query

A SolrParams object. It is recommended to use SolrQuery for advanced queries.

Return Value

SolrQueryResponse

Returns a SolrUpdateResponse on success and throws an exception on failure.

Exceptions

SolrClientException
SolrServerException

SolrUpdateResponse request(string $raw_request)

(PECL solr >= 0.9.2)
Sends a raw update request

Parameters

string $raw_request

An XML string with the raw request to the server.

Return Value

SolrUpdateResponse

Returns a SolrUpdateResponse on success and throws an exception on failure.

Exceptions

SolrIllegalArgumentException
SolrClientException
SolrServerException

SolrUpdateResponse rollback()

(PECL solr >= 0.9.2)
Rollbacks all add/deletes made to the index since the last commit

Return Value

SolrUpdateResponse

Returns a SolrUpdateResponse on success and throws an exception on failure.

Exceptions

SolrClientException
SolrServerException

setResponseWriter(string $responseWriter)

(PECL solr >= 0.9.11)
Sets the response writer used to prepare the response from Solr

Parameters

string $responseWriter

One of the following:

  • json
  • phps
  • xml

bool setServlet(int $type, string $value)

(PECL solr >= 0.9.2)
Changes the specified servlet type to a new value

Parameters

int $type

One of the following :

  • SolrClient::SEARCH_SERVLET_TYPE
  • SolrClient::UPDATE_SERVLET_TYPE
  • SolrClient::THREADS_SERVLET_TYPE
  • SolrClient::PING_SERVLET_TYPE
  • SolrClient::TERMS_SERVLET_TYPE
string $value

The new value for the servlet

Return Value

bool

Returns TRUE on success or FALSE on failure.

SolrGenericResponse system()

(PECL solr >= 2.0.0)
Retrieve Solr Server information

Return Value

SolrGenericResponse

Returns a SolrGenericResponse object on success.

Exceptions

SolrClientException
SolrServerException

SolrGenericResponse threads()

(PECL solr >= 0.9.2)
Checks the threads status

Return Value

SolrGenericResponse

Returns a SolrGenericResponse object on success.

Exceptions

SolrClientException
SolrServerException