Class Apache_Solr_Service

Description

Starting point for the Solr API. Represents a Solr server resource and has methods for pinging, adding, deleting, committing, optimizing and searching.

Example Usage:

  1.  ...
  2.  $solr new Apache_Solr_Service()//or explicitly new Apache_Solr_Service('localhost', 8180, '/solr')
  3.  
  4.  if ($solr->ping())
  5.  {
  6.          $solr->deleteByQuery('*:*')//deletes ALL documents - be careful :)
  7.  
  8.          $document new Apache_Solr_Document();
  9.          $document->id uniqid()//or something else suitably unique
  10.  
  11.          $document->title 'Some Title';
  12.          $document->content 'Some content for this wonderful document. Blah blah blah.';
  13.  
  14.          $solr->addDocument($document);     //if you're going to be adding documents in bulk using addDocuments
  15.                                          //with an array of documents is faster
  16.  
  17.          $solr->commit()//commit to see the deletes and the document
  18.          $solr->optimize()//merges multiple segments into one
  19.  
  20.          //and the one we all care about, search!
  21.          //any other common or custom parameters to the request handler can go in the
  22.          //optional 4th array argument.
  23.          $solr->search('content:blah'010array('sort' => 'timestamp desc'));
  24.  }
  25.  ...

  • todo: Investigate using other HTTP clients other than file_get_contents built-in handler. Could provide performance improvements when dealing with multiple requests by using HTTP's keep alive functionality

Located in /Service.php (line 62)


	
			
Class Constant Summary
 PING_SERVLET = 'admin/ping'
 SEARCH_SERVLET = 'select'
 SOLR_VERSION = '2.2'
 SOLR_WRITER = 'json'
 THREADS_SERVLET = 'admin/threads'
 UPDATE_SERVLET = 'update'
Method Summary
static string escape (string $value)
static string escapePhrase (string $value)
static string phrase (string $value)
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])
Apache_Solr_Response commit ([boolean $waitFlush = true], [boolean $waitSearcher = true])
Apache_Solr_Response delete (string $rawPost)
Apache_Solr_Response deleteById (string $id, [boolean $fromPending = true], [boolean $fromCommitted = true])
Apache_Solr_Response deleteByQuery (string $rawQuery, [boolean $fromPending = true], [boolean $fromCommitted = true])
string getHost ()
string getPath ()
integer getPort ()
Apache_Solr_Response optimize ([boolean $waitFlush = true], [boolean $waitSearcher = true])
float ping ([float $timeout = 5])
Apache_Solr_Response search (string $query, [int $offset = 0], [int $limit = 10], [array $params = array()])
Apache_Solr_Service __construct ([string $host = 'localhost'], [string $port = 8180], [string $path = '/solr/'])
void setHost (string $host)
void setPath (string $path)
void setPort (integer $port)
void setQueryDelimiter (string $queryDelimiter)
void setQueryStringDelimiter (string $queryStringDelimiter)
Methods
static method escape (line 128)

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 method escapePhrase (line 143)

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

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

Convenience function for creating phrase syntax from a value

  • access: public
static string phrase (string $value)
  • string $value
add (line 513)

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: Exception If an error occurs during the service call
  • access: public
Apache_Solr_Response add (string $rawPost)
  • string $rawPost
addDocument (line 529)

Add a Solr Document to the index

  • throws: Exception 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 553)

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

  • throws: Exception 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
commit (line 619)

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

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

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: Exception If an error occurs during the service call
  • access: public
Apache_Solr_Response delete (string $rawPost)
  • string $rawPost
deleteById (line 653)

Create a delete document based on document ID

  • throws: Exception If an error occurs during the service call
  • access: public
Apache_Solr_Response deleteById (string $id, [boolean $fromPending = true], [boolean $fromCommitted = true])
  • string $id
  • boolean $fromPending
  • boolean $fromCommitted
deleteByQuery (line 676)

Create a delete document based on a query and submit it

  • throws: Exception If an error occurs during the service call
  • access: public
Apache_Solr_Response deleteByQuery (string $rawQuery, [boolean $fromPending = true], [boolean $fromCommitted = true])
  • string $rawQuery
  • boolean $fromPending
  • boolean $fromCommitted
getHost (line 285)

Returns the set host

  • access: public
string getHost ()
getPath (line 353)

Get the set path.

  • access: public
string getPath ()
getPort (line 318)

Get the set port

  • access: public
integer getPort ()
optimize (line 699)

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

  • throws: Exception If an error occurs during the service call
  • access: public
Apache_Solr_Response optimize ([boolean $waitFlush = true], [boolean $waitSearcher = true])
  • boolean $waitFlush
  • boolean $waitSearcher
ping (line 404)

Call the /admin/ping servlet, can be used to quickly tell if a connection to the server is able to be made.

  • return: Actual time taken to ping the server, FALSE if timeout occurs
  • access: public
float ping ([float $timeout = 5])
  • float $timeout: maximum time to wait for ping in seconds, -1 for unlimited (default is 5)
search (line 720)

Simple Search interface

  • throws: Exception 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 $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
Constructor __construct (line 170)

Constructor. All parameters are optional and will take on default values if not specified.

  • access: public
Apache_Solr_Service __construct ([string $host = 'localhost'], [string $port = 8180], [string $path = '/solr/'])
  • string $host
  • string $port
  • string $path
setHost (line 295)

Set the host used. If empty will fallback to constants

  • access: public
void setHost (string $host)
  • string $host
setPath (line 363)

Set the path used. If empty will fallback to constants

  • access: public
void setPath (string $path)
  • string $path
setPort (line 328)

Set the port used. If empty will fallback to constants

  • access: public
void setPort (integer $port)
  • integer $port
setQueryDelimiter (line 381)

Set the string used to separate the path form the query string.

Defaulted to '?'

  • access: public
void setQueryDelimiter (string $queryDelimiter)
  • string $queryDelimiter
setQueryStringDelimiter (line 392)

Set the string used to separate the parameters in thequery string Defaulted to '&'

  • access: public
void setQueryStringDelimiter (string $queryStringDelimiter)
  • string $queryStringDelimiter
threads (line 499)

Call the /admin/threads servlet and retrieve information about all threads in the Solr servlet's thread group. Useful for diagnostics.

  • throws: Exception If an error occurs during the service call
  • access: public
Class Constants
PING_SERVLET = 'admin/ping' (line 79)

Servlet mappings

SEARCH_SERVLET = 'select' (line 81)
SOLR_VERSION = '2.2' (line 67)

Response version we support

SOLR_WRITER = 'json' (line 74)

Response writer we support

  • todo: Solr 1.3 release may change this to SerializedPHP or PHP implementation
THREADS_SERVLET = 'admin/threads' (line 82)
UPDATE_SERVLET = 'update' (line 80)

Documentation generated on Tue, 02 Oct 2007 12:55:39 -0400 by phpDocumentor 1.4.0