Created
March 30, 2011 07:44
-
-
Save basdenooijer/894014 to your computer and use it in GitHub Desktop.
Solarium client adapter ZendHttp examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// this example assumes Solarium and Zend_Framework are in your include_path | |
// make Solarium available | |
require('Solarium/Autoloader.php'); | |
Solarium_Autoloader::register(); | |
// make Zend Framework available | |
require('Zend/Loader/Autoloader.php'); | |
Zend_Loader_Autoloader::getInstance(); | |
// create a client instance | |
$client = new Solarium_Client; | |
$client->setHost('192.168.1.2'); | |
$client->setPort(8983); | |
$client->setPath('/solr/'); | |
$client->setCore('geonames'); | |
$client->setAdapter('Solarium_Client_Adapter_ZendHttp'); | |
// you can set zendHttp options as an array | |
// see the zend_http manual for available options | |
$client->setAdapterOptions(array('useragent' => 'MySolrClient')); | |
// you can also access the zend_http instance directly | |
$zendHttp = $client->getAdapter()->getZendHttp(); | |
// and alter the request, for instance by adding a custom header | |
$zendHttp->setHeaders(array('x-myheader' => 'myvalue')); | |
// execute a basic select query and display numFound | |
$query = new Solarium_Query_Select; | |
$result = $client->select($query); | |
echo 'Number of results found: ' . $result->getNumFound(); | |
// accessing raw request and response data (you should see the custom useragent and header in the request) | |
var_dump($zendHttp->getLastRequest()); | |
var_dump($zendHttp->getLastResponse()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// this example assumes Solarium and Zend_Framework are in your include_path | |
// make Solarium available | |
require('Solarium/Autoloader.php'); | |
Solarium_Autoloader::register(); | |
// make Zend Framework available | |
require('Zend/Loader/Autoloader.php'); | |
Zend_Loader_Autoloader::getInstance(); | |
// create a client instance | |
$client = new Solarium_Client; | |
$client->setHost('192.168.1.2'); | |
$client->setPort(8983); | |
$client->setPath('/solr/'); | |
$client->setCore('geonames'); | |
// you can create a client adapter instance yourself and supply this instance to the client | |
$adapter = new Solarium_Client_Adapter_ZendHttp(array('adapteroptions' => array('useragent' => 'MySolrClient'))); | |
$zendHttp = $adapter->getZendHttp(); | |
$zendHttp->setHeaders(array('x-myheader' => 'myvalue')); | |
$client->setAdapter($adapter); | |
// execute a basic select query and display numFound | |
$query = new Solarium_Query_Select; | |
$result = $client->select($query); | |
echo 'Number of results found: ' . $result->getNumFound(); | |
// accessing raw request and response data | |
var_dump($zendHttp->getLastRequest()); | |
var_dump($zendHttp->getLastResponse()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment