Commit 2a98c07a authored by Bas de Nooijer's avatar Bas de Nooijer

Merge branch 'release/3.0.0'

parents 5c7afe1c 18c31bf7
.idea .idea
build build
phpunit.xml phpunit.xml
composer.phar
composer.lock
vendor
\ No newline at end of file
language: php language: php
phps: phps:
- 5.4 - 5.4
- 5.3 - 5.3
script: phpunit -c phpunit.xml.dist
before_script:
- wget http://getcomposer.org/composer.phar
- php composer.phar install
script: phpunit -c phpunit.xml.travis
# Solarium PHP Solr client library # Solarium PHP Solr client library
Solarium is a PHP Solr client that not only facilitates Solr communication but
also tries to accurately model Solr concepts. ## What is Solarium?
Solarium is a PHP Solr client library that accurately model Solr concepts. Where many other Solr libraries only handle
the communication with Solr, Solarium also relieves you of handling all the complex Solr query parameters using a
well documented API.
Please see the project website for a more detailed description. Please see the project website for a more detailed description.
## Project website ## Requirements
http://www.solarium-project.org/
Solarium only supports PHP 5.3 and up.
It's highly recommended to have Curl enabled in your PHP environment. However if you don't have Curl available you can
switch from using Curl (the default) to another client adapter. The other adapters don't support all the features of the
Curl adapter.
## Getting started
The preferred way to install Solarium is by using Composer. Solarium is available on Packagist.
For more info see
http://wiki.solarium-project.org/index.php/V3:Installation#Getting_Solarium
## More information
* Manual
http://wiki.solarium-project.org/index.php/Solarium_3.x_manual
* Project website
http://www.solarium-project.org/
## License: * API docs
See the COPYING file or view online http://api.solarium-project.org/
https://github.com/basdenooijer/solarium/blob/master/COPYING
## Issue tracker * Issue tracker
http://github.com/basdenooijer/solarium/issues http://github.com/basdenooijer/solarium/issues
## Contributors * Contributors
https://github.com/basdenooijer/solarium/contributors https://github.com/basdenooijer/solarium/contributors
## API docs * License
http://api.solarium-project.org/ See the COPYING file or view online:
https://github.com/basdenooijer/solarium/blob/master/COPYING
## Travis Continuous Integration status ## Travis Continuous Integration status
......
...@@ -57,7 +57,7 @@ you could also write the switches here) ...@@ -57,7 +57,7 @@ you could also write the switches here)
<!-- Generate checkstyle.xml --> <!-- Generate checkstyle.xml -->
<target name="phpcs"> <target name="phpcs">
<exec executable="phpcs" output="/dev/null"> <exec executable="phpcs" output="/dev/null">
<arg line="--report=checkstyle --report-file=${basedir}/build/logs/checkstyle.xml --standard=Zend library" /> <arg line="--report=checkstyle --report-file=${basedir}/build/logs/checkstyle.xml --standard=Symfony2 library" />
</exec> </exec>
</target> </target>
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
"description": "PHP Solr client", "description": "PHP Solr client",
"keywords": ["solr", "search", "php"], "keywords": ["solr", "search", "php"],
"homepage": "http://www.solarium-project.org", "homepage": "http://www.solarium-project.org",
"version": "2.4.0",
"license": "NewBSD", "license": "NewBSD",
"authors": [ "authors": [
{ {
...@@ -13,9 +12,15 @@ ...@@ -13,9 +12,15 @@
} }
], ],
"require": { "require": {
"php": ">=5.2.0" "php": ">=5.3.2",
"symfony/event-dispatcher": "2.1.4"
}, },
"autoload": { "autoload": {
"psr-0": { "Solarium": "library/" } "psr-0": { "Solarium": "library/" }
},
"extra": {
"branch-alias": {
"dev-develop": "3.0-dev"
}
} }
} }
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// check solarium version available // check solarium version available
echo 'Solarium library version: ' . Solarium_Version::VERSION . ' - '; echo 'Solarium library version: ' . Solarium\Client::VERSION . ' - ';
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// create a ping query // create a ping query
$ping = $client->createPing(); $ping = $client->createPing();
...@@ -18,7 +18,7 @@ try{ ...@@ -18,7 +18,7 @@ try{
echo 'Ping query successful'; echo 'Ping query successful';
echo '<br/><pre>'; echo '<br/><pre>';
var_dump($result->getData()); var_dump($result->getData());
}catch(Solarium_Exception $e){ }catch(Solarium\Exception $e){
echo 'Ping query failed'; echo 'Ping query failed';
} }
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createQuery($client::QUERY_SELECT);
// this executes the query and returns the result // this executes the query and returns the result
$resultset = $client->select($query); $resultset = $client->execute($query);
// display the total number of documents found by solr // display the total number of documents found by solr
echo 'NumFound: '.$resultset->getNumFound(); echo 'NumFound: '.$resultset->getNumFound();
...@@ -25,7 +25,7 @@ foreach ($resultset as $document) { ...@@ -25,7 +25,7 @@ foreach ($resultset as $document) {
{ {
// this converts multivalue fields to a comma-separated string // this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value); if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
} }
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
if ($_POST) { if ($_POST) {
// if data is posted add it to solr // if data is posted add it to solr
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get an update query instance // get an update query instance
$update = $client->createUpdate(); $update = $client->createUpdate();
...@@ -18,7 +18,7 @@ if ($_POST) { ...@@ -18,7 +18,7 @@ if ($_POST) {
$doc->id = $_POST['id']; $doc->id = $_POST['id'];
$doc->name = $_POST['name']; $doc->name = $_POST['name'];
$doc->price = $_POST['price']; $doc->price = $_POST['price'];
// add the document and a commit command to the update query // add the document and a commit command to the update query
$update->addDocument($doc); $update->addDocument($doc);
$update->addCommit(); $update->addCommit();
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
...@@ -19,7 +20,7 @@ $query->setStart(2)->setRows(20); ...@@ -19,7 +20,7 @@ $query->setStart(2)->setRows(20);
$query->setFields(array('id','name','price')); $query->setFields(array('id','name','price'));
// sort the results by price ascending // sort the results by price ascending
$query->addSort('price', Solarium_Query_Select::SORT_ASC); $query->addSort('price', $query::SORT_ASC);
// this executes the query and returns the result // this executes the query and returns the result
$resultset = $client->select($query); $resultset = $client->select($query);
...@@ -37,7 +38,7 @@ foreach ($resultset as $document) { ...@@ -37,7 +38,7 @@ foreach ($resultset as $document) {
{ {
// this converts multivalue fields to a comma-separated string // this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value); if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
} }
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// this is the custom result document class // this is the custom result document class
class myDoc extends Solarium_Document_ReadOnly{ class myDoc extends Solarium\QueryType\Select\Result\Document{
public function getSpecialPrice() public function getSpecialPrice()
{ {
...@@ -16,7 +16,7 @@ class myDoc extends Solarium_Document_ReadOnly{ ...@@ -16,7 +16,7 @@ class myDoc extends Solarium_Document_ReadOnly{
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
...@@ -33,7 +33,7 @@ foreach ($resultset as $document) { ...@@ -33,7 +33,7 @@ foreach ($resultset as $document) {
{ {
// this converts multivalue fields to a comma-separated string // this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value); if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
} }
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
...@@ -32,7 +32,7 @@ foreach ($resultset as $document) { ...@@ -32,7 +32,7 @@ foreach ($resultset as $document) {
{ {
// this converts multivalue fields to a comma-separated string // this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value); if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
} }
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
...@@ -32,7 +32,7 @@ foreach ($resultset as $document) { ...@@ -32,7 +32,7 @@ foreach ($resultset as $document) {
{ {
// this converts multivalue fields to a comma-separated string // this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value); if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
} }
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
// get the dismax component and set a boost query // get the dismax component and set a boost query
$dismax = $query->getDisMax(); $edismax = $query->getEDisMax();
// override the default setting of 'dismax' to enable 'edismax'
$dismax->setQueryParser('edismax');
// this query is now a dismax query // this query is now a dismax query
$query->setQuery('memory -printer'); $query->setQuery('memory -printer');
...@@ -34,7 +31,7 @@ foreach ($resultset as $document) { ...@@ -34,7 +31,7 @@ foreach ($resultset as $document) {
{ {
// this converts multivalue fields to a comma-separated string // this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value); if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
} }
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
...@@ -33,7 +33,7 @@ foreach($groups AS $groupKey => $fieldGroup) { ...@@ -33,7 +33,7 @@ foreach($groups AS $groupKey => $fieldGroup) {
echo '<h2>'.(int)$valueGroup->getValue().'</h2>'; echo '<h2>'.(int)$valueGroup->getValue().'</h2>';
foreach($valueGroup AS $document) { foreach($valueGroup AS $document) {
echo '<hr/><table>'; echo '<hr/><table>';
// the documents are also iterable, to get all fields // the documents are also iterable, to get all fields
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
...@@ -22,7 +22,6 @@ $spellcheck->setCollateExtendedResults(true); ...@@ -22,7 +22,6 @@ $spellcheck->setCollateExtendedResults(true);
$resultset = $client->select($query); $resultset = $client->select($query);
$spellcheckResult = $resultset->getSpellcheck(); $spellcheckResult = $resultset->getSpellcheck();
echo '<h1>Correctly spelled?</h1>'; echo '<h1>Correctly spelled?</h1>';
if ($spellcheckResult->getCorrectlySpelled()) { if ($spellcheckResult->getCorrectlySpelled()) {
echo 'yes'; echo 'yes';
...@@ -41,13 +40,16 @@ foreach($spellcheckResult as $suggestion) { ...@@ -41,13 +40,16 @@ foreach($spellcheckResult as $suggestion) {
echo '<hr/>'; echo '<hr/>';
} }
$collation = $spellcheckResult->getCollation(); $collations = $spellcheckResult->getCollations();
echo '<h1>Collation</h1>'; echo '<h1>Collations</h1>';
echo 'Query: '.$collation->getQuery().'<br/>'; foreach($collations as $collation) {
echo 'Hits: '.$collation->getHits().'<br/>'; echo 'Query: '.$collation->getQuery().'<br/>';
echo 'Hits: '.$collation->getHits().'<br/>';
echo '<hr/>';
}
echo 'Corrections:<br/>'; echo 'Corrections:<br/>';
foreach($collation->getCorrections() as $input => $correction) { foreach($collation->getCorrections() as $input => $correction) {
echo $input . ' => ' . $correction .'<br/>'; echo $input . ' => ' . $correction .'<br/>';
} }
htmlFooter(); htmlFooter();
\ No newline at end of file
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance and a query helper instance // get a select query instance and a query helper instance
$query = $client->createSelect(); $query = $client->createSelect();
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
use Solarium\Client;
use Solarium\QueryType\Select\Query\Query as Select;
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Client($config);
// first create a base query as a query class // first create a base query as a query class
class PriceQuery extends Solarium_Query_Select class PriceQuery extends Select
{ {
protected function _init() protected function init()
{ {
parent::init();
// set a query (all prices starting from 12) // set a query (all prices starting from 12)
$this->setQuery('price:[12 TO *]'); $this->setQuery('price:[12 TO *]');
...@@ -37,10 +42,10 @@ if(isset($_GET['start']) && is_numeric($_GET['start'])){ ...@@ -37,10 +42,10 @@ if(isset($_GET['start']) && is_numeric($_GET['start'])){
// in this example this class isn't actually used, but you can simple replace // in this example this class isn't actually used, but you can simple replace
// the var $query with an instance of this class... // the var $query with an instance of this class...
class LowerPriceQuery extends PriceQuery{ class LowerPriceQuery extends PriceQuery{
protected function _init() protected function init()
{ {
// this call makes sure we get all the settings of the parent class // this call makes sure we get all the settings of the parent class
parent::_init(); parent::init();
$this->setQuery('price:[5 TO *]'); $this->setQuery('price:[5 TO *]');
} }
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get an update query instance // get an update query instance
$update = $client->createUpdate(); $update = $client->createUpdate();
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get an update query instance // get an update query instance
$update = $client->createUpdate(); $update = $client->createUpdate();
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get an update query instance // get an update query instance
$update = $client->createUpdate(); $update = $client->createUpdate();
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get an update query instance // get an update query instance
$update = $client->createUpdate(); $update = $client->createUpdate();
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get an update query instance // get an update query instance
$update = $client->createUpdate(); $update = $client->createUpdate();
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
use Solarium\Client;
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Client($config);
// get a morelikethis query instance // get a morelikethis query instance
$query = $client->createMoreLikeThis(); $query = $client->createMoreLikeThis();
...@@ -44,7 +46,7 @@ foreach ($resultset as $document) { ...@@ -44,7 +46,7 @@ foreach ($resultset as $document) {
{ {
// this converts multivalue fields to a comma-separated string // this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value); if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
} }
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a morelikethis query instance // get a morelikethis query instance
$query = $client->createMoreLikeThis(); $query = $client->createMoreLikeThis();
...@@ -45,7 +45,7 @@ foreach ($resultset as $document) { ...@@ -45,7 +45,7 @@ foreach ($resultset as $document) {
{ {
// this converts multivalue fields to a comma-separated string // this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value); if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
} }
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get an analysis document query // get an analysis document query
$query = $client->createAnalysisDocument(); $query = $client->createAnalysisDocument();
...@@ -12,7 +12,7 @@ $query = $client->createAnalysisDocument(); ...@@ -12,7 +12,7 @@ $query = $client->createAnalysisDocument();
$query->setShowMatch(true); $query->setShowMatch(true);
$query->setQuery('ipod'); $query->setQuery('ipod');
$doc = new Solarium_Document_ReadWrite( $doc = new Solarium\QueryType\Update\Query\Document(
array( array(
'id' => 'MA147LL', 'id' => 'MA147LL',
'name' => 'Apple 60 GB iPod with Video Playback Black', 'name' => 'Apple 60 GB iPod with Video Playback Black',
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get an analysis document query // get an analysis document query
$query = $client->createAnalysisField(); $query = $client->createAnalysisField();
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a terms query instance // get a terms query instance
$query = $client->createTerms(); $query = $client->createTerms();
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a suggester query instance // get a suggester query instance
$query = $client->createSuggester(); $query = $client->createSuggester();
......
<?php
require(__DIR__.'/init.php');
htmlHeader();
// create a client instance
$client = new Solarium\Client($config);
// get an extract query instance and add settings
$query = $client->createExtract();
$query->addFieldMapping('content', 'text');
$query->setUprefix('attr_');
$query->setFile(__DIR__.'/index.html');
$query->setCommit(true);
$query->setOmitHeader(false);
// add document
$doc = $query->createDocument();
$doc->id = 'extract-test';
$doc->some = 'more fields';
$query->setDocument($doc);
// this executes the query and returns the result
$result = $client->extract($query);
echo '<b>Extract query executed</b><br/>';
echo 'Query status: ' . $result->getStatus(). '<br/>';
echo 'Query time: ' . $result->getQueryTime();
htmlFooter();
\ No newline at end of file
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
...@@ -13,7 +14,7 @@ $query = $client->createSelect(); ...@@ -13,7 +14,7 @@ $query = $client->createSelect();
$query->setQuery('*:*'); $query->setQuery('*:*');
$query->setStart(2)->setRows(20); $query->setStart(2)->setRows(20);
$query->setFields(array('id','name','price')); $query->setFields(array('id','name','price'));
$query->addSort('price', Solarium_Query_Select::SORT_ASC); $query->addSort('price', $query::SORT_ASC);
// create a filterquery using the API // create a filterquery using the API
$fq = $query->createFilterQuery('maxprice')->setQuery('price:[1 TO 300]'); $fq = $query->createFilterQuery('maxprice')->setQuery('price:[1 TO 300]');
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
...@@ -29,7 +29,7 @@ $select = array( ...@@ -29,7 +29,7 @@ $select = array(
); );
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance based on the config // get a select query instance based on the config
$query = $client->createSelect($select); $query = $client->createSelect($select);
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
use Solarium\Client;
use Solarium\QueryType\Select\Query\Query as Select;
htmlHeader(); htmlHeader();
// In most cases using the API or config is advisable, however in some cases it can make sense to extend classes. // In most cases using the API or config is advisable, however in some cases it can make sense to extend classes.
// This makes it possible to create 'query inheritance' like in this example // This makes it possible to create 'query inheritance' like in this example
class ProductQuery extends Solarium_Query_Select{ class ProductQuery extends Select{
protected function _init() protected function init()
{ {
parent::_init(); parent::init();
// basic params // basic params
$this->setQuery('*:*'); $this->setQuery('*:*');
$this->setStart(2)->setRows(20); $this->setStart(2)->setRows(20);
$this->setFields(array('id','name','price')); $this->setFields(array('id','name','price'));
$this->addSort('price', Solarium_Query_Select::SORT_ASC); $this->addSort('price', self::SORT_ASC);
// create a facet field instance and set options // create a facet field instance and set options
$facetSet = $this->getFacetSet(); $facetSet = $this->getFacetSet();
...@@ -24,13 +27,13 @@ class ProductQuery extends Solarium_Query_Select{ ...@@ -24,13 +27,13 @@ class ProductQuery extends Solarium_Query_Select{
} }
// This query inherits all of the query params of it's parent (using parent::_init) and adds some more // This query inherits all of the query params of its parent (using parent::init) and adds some more
// Ofcourse it could also alter or remove settings // Ofcourse it could also alter or remove settings
class ProductPriceLimitedQuery extends ProductQuery{ class ProductPriceLimitedQuery extends ProductQuery{
protected function _init() protected function init()
{ {
parent::_init(); parent::init();
// create a filterquery // create a filterquery
$this->createFilterQuery('maxprice')->setQuery('price:[1 TO 300]'); $this->createFilterQuery('maxprice')->setQuery('price:[1 TO 300]');
...@@ -39,7 +42,7 @@ class ProductPriceLimitedQuery extends ProductQuery{ ...@@ -39,7 +42,7 @@ class ProductPriceLimitedQuery extends ProductQuery{
} }
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Client($config);
// create a query instance // create a query instance
$query = new ProductPriceLimitedQuery; $query = new ProductPriceLimitedQuery;
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// This example shows how to manually execute the query flow. // This example shows how to manually execute the query flow.
...@@ -10,7 +10,7 @@ htmlHeader(); ...@@ -10,7 +10,7 @@ htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// create a select query instance // create a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
...@@ -41,7 +41,7 @@ foreach ($result as $document) { ...@@ -41,7 +41,7 @@ foreach ($result as $document) {
{ {
// this converts multivalue fields to a comma-separated string // this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value); if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
} }
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
use Solarium\Client;
use Solarium\QueryType\Select\Query\Query as Select;
htmlHeader(); htmlHeader();
// This is a custom query class that could have some customized logic // This is a custom query class that could have some customized logic
class MyQuery extends Solarium_Query_Select class MyQuery extends Select
{ {
// ...customization here... // ...customization here...
} }
...@@ -12,26 +15,16 @@ class MyQuery extends Solarium_Query_Select ...@@ -12,26 +15,16 @@ class MyQuery extends Solarium_Query_Select
// And this is the extended client, that modifies the default query mapping // And this is the extended client, that modifies the default query mapping
// for select queries to our custom query class. // for select queries to our custom query class.
// BTW, the same could also be done using a plugin, see example 5.3.2 // BTW, the same could also be done using a plugin, see example 5.3.2
class MyClient extends Solarium_Client class MyClient extends Client
{ {
/** /**
* Querytype mappings * Querytype mappings
*/ */
protected $_queryTypes = array( protected $_queryTypes = array(
self::QUERYTYPE_SELECT => array( self::QUERY_SELECT => array(
'query' => 'MyQuery', 'query' => 'MyQuery',
'requestbuilder' => 'Solarium_Client_RequestBuilder_Select', 'requestbuilder' => 'Solarium\QueryType\Select\RequestBuilder\RequestBuilder',
'responseparser' => 'Solarium_Client_ResponseParser_Select' 'responseparser' => 'Solarium\QueryType\Select\ResponseParser\ResponseParser'
),
self::QUERYTYPE_UPDATE => array(
'query' => 'Solarium_Query_Update',
'requestbuilder' => 'Solarium_Client_RequestBuilder_Update',
'responseparser' => 'Solarium_Client_ResponseParser_Update'
),
self::QUERYTYPE_PING => array(
'query' => 'Solarium_Query_Ping',
'requestbuilder' => 'Solarium_Client_RequestBuilder_Ping',
'responseparser' => 'Solarium_Client_ResponseParser_Ping'
), ),
); );
} }
...@@ -62,7 +55,7 @@ foreach ($result as $document) { ...@@ -62,7 +55,7 @@ foreach ($result as $document) {
{ {
// this converts multivalue fields to a comma-separated string // this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value); if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
} }
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
use Solarium\Core\Event\Events;
// this very simple plugin shows a timing for each event and display some request debug info // this very simple plugin shows a timing for each event and display some request debug info
class basicDebug extends Solarium_Plugin_Abstract class basicDebug extends Solarium\Core\Plugin\Plugin
{ {
protected $_start; protected $start;
protected $_output = array(); protected $output = array();
public function _initPlugin() protected function initPluginType()
{ {
$this->_start = microtime(true); $this->start = microtime(true);
$dispatcher = $this->client->getEventDispatcher();
$dispatcher->addListener(Events::PRE_CREATE_REQUEST, array($this, 'preCreateRequest'));
$dispatcher->addListener(Events::POST_CREATE_REQUEST, array($this, 'postCreateRequest'));
$dispatcher->addListener(Events::PRE_EXECUTE_REQUEST, array($this, 'preExecuteRequest'));
$dispatcher->addListener(Events::POST_EXECUTE_REQUEST, array($this, 'postExecuteRequest'));
$dispatcher->addListener(Events::PRE_CREATE_RESULT, array($this, 'preCreateResult'));
$dispatcher->addListener(Events::POST_CREATE_RESULT, array($this, 'postCreateResult'));
$dispatcher->addListener(Events::PRE_EXECUTE, array($this, 'preExecute'));
$dispatcher->addListener(Events::POST_EXECUTE, array($this, 'postExecute'));
$dispatcher->addListener(Events::PRE_CREATE_QUERY, array($this, 'preCreateQuery'));
$dispatcher->addListener(Events::POST_CREATE_QUERY, array($this, 'postCreateQuery'));
} }
protected function _timer($event) protected function timer($event)
{ {
$time = round(microtime(true) - $this->_start, 5); $time = round(microtime(true) - $this->start, 5);
$this->_output[] = '['.$time.'] ' . $event; $this->output[] = '['.$time.'] ' . $event;
} }
public function display() public function display()
{ {
echo implode('<br/>', $this->_output); echo implode('<br/>', $this->output);
} }
public function preCreateRequest() public function preCreateRequest()
{ {
$this->_timer('preCreateRequest'); $this->timer('preCreateRequest');
} }
public function postCreateRequest() public function postCreateRequest()
{ {
$this->_timer('postCreateRequest'); $this->timer('postCreateRequest');
} }
// This method uses the aviable param(s) (see plugin abstract class) // This method uses the aviable param(s) (see plugin abstract class)
// You can access or modify data this way // You can access or modify data this way
public function preExecuteRequest($request) public function preExecuteRequest($event)
{ {
$this->_timer('preExecuteRequest'); $this->timer('preExecuteRequest');
// this dummy param will be visible in the debug output but will also be used in the actual Solr request // this dummy param will be visible in the debug output but will also be used in the actual Solr request
$request->addParam('dummyparam', 'dummyvalue'); $event->getRequest()->addParam('dummyparam', 'dummyvalue');
$this->_output[] = 'Request URI: ' . $request->getUri(); $this->output[] = 'Request URI: ' . $event->getRequest()->getUri();
} }
public function postExecuteRequest() public function postExecuteRequest()
{ {
$this->_timer('postExecuteRequest'); $this->timer('postExecuteRequest');
} }
public function preCreateResult() public function preCreateResult()
{ {
$this->_timer('preCreateResult'); $this->timer('preCreateResult');
} }
public function postCreateResult() public function postCreateResult()
{ {
$this->_timer('postCreateResult'); $this->timer('postCreateResult');
} }
public function preExecute() public function preExecute()
{ {
$this->_timer('preExecute'); $this->timer('preExecute');
} }
public function postExecute() public function postExecute()
{ {
$this->_timer('postExecute'); $this->timer('postExecute');
} }
public function preCreateQuery() public function preCreateQuery()
{ {
$this->_timer('preCreateResult'); $this->timer('preCreateResult');
} }
public function postCreateQuery() public function postCreateQuery()
{ {
$this->_timer('postCreateResult'); $this->timer('postCreateResult');
} }
} }
...@@ -90,7 +101,7 @@ htmlHeader(); ...@@ -90,7 +101,7 @@ htmlHeader();
// create a client instance and register the plugin // create a client instance and register the plugin
$plugin = new basicDebug(); $plugin = new basicDebug();
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
$client->registerPlugin('debugger', $plugin); $client->registerPlugin('debugger', $plugin);
// execute a select query and display the results // execute a select query and display the results
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
use Solarium\Client;
use Solarium\Core\Plugin\Plugin;
use Solarium\QueryType\Select\Query\Query as Select;
// This is a custom query class that could have some customized logic // This is a custom query class that could have some customized logic
class MyQuery extends Solarium_Query_Select class MyQuery extends Select
{ {
// ...customization here... // ...customization here...
} }
// this very simple plugin that modifies the default querytype mapping // this very simple plugin that modifies the default querytype mapping
class queryCustomizer extends Solarium_Plugin_Abstract class queryCustomizer extends Plugin
{ {
protected function _initPlugin() public function initPlugin($client, $options)
{ {
$this->_client->registerQueryType( $client->registerQueryType(
Solarium_Client::QUERYTYPE_SELECT, Client::QUERY_SELECT,
'MyQuery', 'MyQuery',
'Solarium_Client_RequestBuilder_Select', 'Solarium\QueryType\Select\RequestBuilder\RequestBuilder',
'Solarium_Client_ResponseParser_Select' 'Solarium\QueryType\Select\ResponseParser\ResponseParser'
); );
} }
} }
htmlHeader(); htmlHeader();
// create a client instance and register the plugin // create a client instance and register the plugin
$client = new Solarium_Client($config); $client = new Client($config);
$client->registerPlugin('querycustomizer', 'queryCustomizer'); $client->registerPlugin('querycustomizer', 'queryCustomizer');
// create a select query instance // create a select query instance
......
...@@ -3,14 +3,14 @@ ...@@ -3,14 +3,14 @@
require_once 'Zend/Loader/Autoloader.php'; require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance(); $loader = Zend_Loader_Autoloader::getInstance();
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// set the adapter to zendhttp and get a zendhttp client instance reference // set the adapter to zendhttp and get a zendhttp client instance reference
$client->setAdapter('Solarium_Client_Adapter_ZendHttp'); $client->setAdapter('Solarium\Core\Client\Adapter\ZendHttp');
$zendHttp = $client->getAdapter()->getZendHttp(); $zendHttp = $client->getAdapter()->getZendHttp();
// you can use any of the zend_http features, like http-authentication // you can use any of the zend_http features, like http-authentication
...@@ -35,7 +35,7 @@ foreach ($resultset as $document) { ...@@ -35,7 +35,7 @@ foreach ($resultset as $document) {
{ {
// this converts multivalue fields to a comma-separated string // this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value); if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
} }
......
...@@ -3,14 +3,14 @@ ...@@ -3,14 +3,14 @@
require_once 'Zend/Loader/Autoloader.php'; require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance(); $loader = Zend_Loader_Autoloader::getInstance();
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// set the adapter to peclhttp // set the adapter to peclhttp
$client->setAdapter('Solarium_Client_Adapter_PeclHttp'); $client->setAdapter('Solarium\Core\Client\Adapter\PeclHttp');
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
...@@ -31,7 +31,7 @@ foreach ($resultset as $document) { ...@@ -31,7 +31,7 @@ foreach ($resultset as $document) {
{ {
// this converts multivalue fields to a comma-separated string // this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value); if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
} }
......
...@@ -3,14 +3,16 @@ ...@@ -3,14 +3,16 @@
require_once 'Zend/Loader/Autoloader.php'; require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance(); $loader = Zend_Loader_Autoloader::getInstance();
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// set the adapter to curl // set the adapter to curl
$client->setAdapter('Solarium_Client_Adapter_Curl'); // note that this is only shown for documentation purposes, normally you don't need
// to do this as curl is the default adapter
$client->setAdapter('Solarium\Core\Client\Adapter\Curl');
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
......
<?php
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
require(__DIR__.'/init.php');
htmlHeader();
// create a client instance
$client = new Solarium\Client($config);
// set the adapter to curl
$client->setAdapter('Solarium\Core\Client\Adapter\Http');
// get a select query instance
$query = $client->createSelect();
// this executes the query and returns the result
$resultset = $client->select($query);
// display the total number of documents found by solr
echo 'NumFound: '.$resultset->getNumFound();
// show documents using the resultset iterator
foreach ($resultset as $document) {
echo '<hr/><table>';
// the documents are also iterable, to get all fields
foreach($document AS $field => $value)
{
// this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
}
echo '</table>';
}
htmlFooter();
\ No newline at end of file
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
...@@ -33,7 +33,7 @@ foreach ($resultset as $document) { ...@@ -33,7 +33,7 @@ foreach ($resultset as $document) {
{ {
// this converts multivalue fields to a comma-separated string // this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value); if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
} }
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
...@@ -35,7 +35,7 @@ foreach ($resultset as $document) { ...@@ -35,7 +35,7 @@ foreach ($resultset as $document) {
{ {
// this converts multivalue fields to a comma-separated string // this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value); if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
} }
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance and get a select query instance // create a client instance and get a select query instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance and get loadbalancer plugin instance // create a client instance and create endpoints
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
$loadbalancer = $client->getPlugin('loadbalancer'); $endpoint1 = $client->createEndpoint('local1'); //normally you would add endpoint specific settings...
$endpoint2 = $client->createEndpoint('local2');
$endpoint3 = $client->createEndpoint('local3');
// apply loadbalancer settings // get loadbalancer plugin instance and add endpoints
$optionsSolrOne = array('host' => '127.0.0.1', 'port' => 8983); $loadbalancer = $client->getPlugin('loadbalancer');
$optionsSolrTwo = array('host' => '127.0.0.1', 'port' => 7574); $loadbalancer->addEndpoint($endpoint1, 100);
$loadbalancer->addServer('solr1', $optionsSolrOne, 100); $loadbalancer->addEndpoint($endpoint2, 100);
$loadbalancer->addServer('solr2', $optionsSolrTwo, 200); $loadbalancer->addEndpoint($endpoint3, 1);
$loadbalancer->addServer('solr3', $optionsSolrTwo, 1);
// create a basic query to execute // create a basic query to execute
$query = $client->createSelect(); $query = $client->createSelect();
...@@ -22,26 +23,27 @@ for($i=1; $i<=8; $i++) { ...@@ -22,26 +23,27 @@ for($i=1; $i<=8; $i++) {
$resultset = $client->select($query); $resultset = $client->select($query);
echo 'Query execution #' . $i . '<br/>'; echo 'Query execution #' . $i . '<br/>';
echo 'NumFound: ' . $resultset->getNumFound(). '<br/>'; echo 'NumFound: ' . $resultset->getNumFound(). '<br/>';
echo 'Server: ' . $loadbalancer->getLastServerKey() .'<hr/>'; echo 'Server: ' . $loadbalancer->getLastEndpoint() .'<hr/>';
} }
// force a server for a query (normally solr 3 is extremely unlikely based on it's weight) // force a server for a query (normally solr 3 is extremely unlikely based on its weight)
$loadbalancer->setForcedServerForNextQuery('solr3'); $loadbalancer->setForcedEndpointForNextQuery('local3');
$resultset = $client->select($query); $resultset = $client->select($query);
echo 'Query execution with server forced to solr3<br/>'; echo 'Query execution with server forced to local3<br/>';
echo 'NumFound: ' . $resultset->getNumFound(). '<br/>'; echo 'NumFound: ' . $resultset->getNumFound(). '<br/>';
echo 'Server: ' . $loadbalancer->getLastServerKey() .'<hr/>'; echo 'Server: ' . $loadbalancer->getLastEndpoint() .'<hr/>';
// test a ping query // test a ping query
$query = $client->createPing(); $query = $client->createPing();
$client->ping($query); $client->ping($query);
echo 'Loadbalanced ping query, should display a loadbalancing server:<br/>'; echo 'Loadbalanced ping query, should display a loadbalancing server:<br/>';
echo 'Ping server: ' . $loadbalancer->getLastServerKey() .'<hr/>'; echo 'Ping server: ' . $loadbalancer->getLastEndpoint() .'<hr/>';
// exclude ping query from loadbalancing // exclude ping query from loadbalancing
$loadbalancer->addBlockedQueryType(Solarium_Client::QUERYTYPE_PING); $loadbalancer->addBlockedQueryType(Solarium\Client::QUERY_PING);
$client->ping($query); $client->ping($query);
echo 'Non-loadbalanced ping query, should not display a loadbalancing server:<br/>'; echo 'Non-loadbalanced ping query, should not display a loadbalancing server:<br/>';
echo 'Ping server: ' . $loadbalancer->getLastServerKey() .'<hr/>'; echo 'Ping server: ' . $loadbalancer->getLastEndpoint() .'<hr/>';
htmlFooter(); htmlFooter();
\ No newline at end of file
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance and autoload the postbigrequest plugin // create a client instance and autoload the postbigrequest plugin
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
$client->getPlugin('postbigrequest'); $client->getPlugin('postbigrequest');
// create a basic query to execute // create a basic query to execute
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance and autoload the customize request plugin // create a client instance and autoload the customize request plugin
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
$customizer = $client->getPlugin('customizerequest'); $customizer = $client->getPlugin('customizerequest');
// add a persistent HTTP header (using array input values) // add a persistent HTTP header (using array input values)
......
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance and autoload the customize request plugin // create a client instance and autoload the customize request plugin
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
$parallel = $client->getPlugin('parallelexecution'); $parallel = $client->getPlugin('parallelexecution');
// Add a delay param to better show the effect, as an example Solr install with // Add a delay param to better show the effect, as an example Solr install with
...@@ -48,4 +48,4 @@ htmlFooter(); ...@@ -48,4 +48,4 @@ htmlFooter();
// Note: for this example on a default Solr index (with a tiny index) running on localhost the performance gain is // Note: for this example on a default Solr index (with a tiny index) running on localhost the performance gain is
// minimal to none, sometimes even slightly slower! // minimal to none, sometimes even slightly slower!
// In a realworld scenario with network latency, a bigger dataset, more complex queries or multiple solr instances the // In a realworld scenario with network latency, a bigger dataset, more complex queries or multiple solr instances the
// performance gain is much more. // performance gain is much more.
\ No newline at end of file
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
// this very simple plugin is used to show some events use Solarium\Plugin\BufferedAdd\Event\Events;
class simpleDebug extends Solarium_Plugin_Abstract use Solarium\Plugin\BufferedAdd\Event\PreFlush as PreFlushEvent;
{
protected $_output = array();
public function display()
{
echo implode('<br/>', $this->_output);
}
public function eventBufferedAddFlushStart($buffer) {
$this->_output[] = 'Flushing buffer (' . count($buffer) . 'docs)';
}
}
htmlHeader(); htmlHeader();
// create a client instance and autoload the buffered add plugin // create a client instance and autoload the buffered add plugin
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
$buffer = $client->getPlugin('bufferedadd'); $buffer = $client->getPlugin('bufferedadd');
$buffer->setBufferSize(10); // this is quite low, in most cases you can use a much higher value $buffer->setBufferSize(10); // this is quite low, in most cases you can use a much higher value
// also register a plugin for outputting events // also register an event hook to display what is happening
$debug = new simpleDebug(); $client->getEventDispatcher()->addListener(
$client->registerPlugin('debugger', $debug); Events::PRE_FLUSH,
function(PreFlushEvent $event){
echo 'Flushing buffer (' . count($event->getBuffer()) . 'docs)<br/>';
}
);
// let's insert 25 docs // let's insert 25 docs
for ($i=1; $i<=25; $i++) { for ($i=1; $i<=25; $i++) {
...@@ -45,7 +37,6 @@ for ($i=1; $i<=25; $i++) { ...@@ -45,7 +37,6 @@ for ($i=1; $i<=25; $i++) {
// manually flush the remainder. Alternatively you can use the commit method if you want to include a commit command. // manually flush the remainder. Alternatively you can use the commit method if you want to include a commit command.
$buffer->flush(); $buffer->flush();
// In total 3 flushes (requests) have been sent to Solr. This should be visible in this output: // In total 3 flushes (requests) have been sent to Solr. This should be visible in the output of the event hook.
$debug->display();
htmlFooter(); htmlFooter();
\ No newline at end of file
<?php <?php
require('init.php'); require(__DIR__.'/init.php');
htmlHeader(); htmlHeader();
// create a client instance // create a client instance
$client = new Solarium_Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createSelect(); $query = $client->createSelect();
......
<?php
require('../library/Solarium/Autoloader.php');
Solarium_Autoloader::register();
\ No newline at end of file
<?php <?php
$config = array( $config = array(
'adapteroptions' => array( 'endpoint' => array(
'host' => '127.0.0.1', 'localhost' => array(
'port' => 8983, 'host' => '127.0.0.1',
'path' => '/solr/', 'port' => 8983,
'path' => '/solr/',
)
) )
); );
...@@ -85,6 +85,7 @@ ...@@ -85,6 +85,7 @@
<li><a href="2.5-terms-query.php">2.5 Terms query</a></li> <li><a href="2.5-terms-query.php">2.5 Terms query</a></li>
<li><a href="2.6-suggester-query.php">2.6 Suggester query</a></li> <li><a href="2.6-suggester-query.php">2.6 Suggester query</a></li>
<li><a href="2.7-extract-query.php">2.7 Extract query</a></li>
</ul> </ul>
<li>4. Usage modes</li> <li>4. Usage modes</li>
...@@ -112,6 +113,7 @@ ...@@ -112,6 +113,7 @@
<li><a href="6.1.1-zend-http-adapter.php">6.1.1 Zend_Http adapter</a></li> <li><a href="6.1.1-zend-http-adapter.php">6.1.1 Zend_Http adapter</a></li>
<li><a href="6.1.2-pecl-http-adapter.php">6.1.2 Pecl_Http adapter</a></li> <li><a href="6.1.2-pecl-http-adapter.php">6.1.2 Pecl_Http adapter</a></li>
<li><a href="6.1.3-curl-adapter.php">6.1.3 Curl adapter</a></li> <li><a href="6.1.3-curl-adapter.php">6.1.3 Curl adapter</a></li>
<li><a href="6.1.4-http-adapter.php">6.1.4 Http adapter (PHP stream)</a></li>
</ul> </ul>
<li><a href="6.2-escaping.php">6.2 Escaping</a></li> <li><a href="6.2-escaping.php">6.2 Escaping</a></li>
<li><a href="6.3-placeholder-syntax.php">6.3 Placeholder syntax</a></li> <li><a href="6.3-placeholder-syntax.php">6.3 Placeholder syntax</a></li>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
error_reporting(E_ALL); error_reporting(E_ALL);
ini_set('display_errors', true); ini_set('display_errors', true);
require('autoload.php'); require __DIR__.'/../vendor/autoload.php';
if (file_exists('config.php')) { if (file_exists('config.php')) {
require('config.php'); require('config.php');
......
...@@ -31,20 +31,25 @@ ...@@ -31,20 +31,25 @@
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*
* @package Solarium
*/ */
/**
* @namespace
*/
namespace Solarium;
/** /**
* Autoloader * Autoloader
* *
* This class is included to allow for easy usage of Solarium. If you already * This class is included to allow for easy usage of Solarium in environments missing a PSR-O autoloader.
* have your own autoloader that follows the Zend Framework class/file naming *
* you can use that to autoload Solarium (for instance Zend_Loader). * It's recommended to install Solarium using composer, which will also provide autoloading for you. In that
* case you don't need to use this autoloader.
* *
* @package Solarium * Solarium is PSR-0 compliant, so you can also use any other compatible autoloader
* (most modern frameworks include one)
*/ */
class Solarium_Autoloader class Autoloader
{ {
/** /**
...@@ -59,7 +64,7 @@ class Solarium_Autoloader ...@@ -59,7 +64,7 @@ class Solarium_Autoloader
* @static * @static
* @return void * @return void
*/ */
static public function register() public static function register()
{ {
spl_autoload_register(array(new self, 'load')); spl_autoload_register(array(new self, 'load'));
} }
...@@ -71,23 +76,23 @@ class Solarium_Autoloader ...@@ -71,23 +76,23 @@ class Solarium_Autoloader
* The autoloader only acts for classnames that start with 'Solarium'. * The autoloader only acts for classnames that start with 'Solarium'.
* *
* @static * @static
* @param string $class * @param string $class
* @return void * @return void
*/ */
static public function load($class) public static function load($class)
{ {
if (substr($class, 0, 8) == 'Solarium') { if (substr($class, 0, 8) == 'Solarium') {
$class = str_replace( $class = str_replace(
array('Solarium', '_'), array('Solarium', '\\'),
array('', '/'), array('', '/'),
$class $class
); );
$file = dirname(__FILE__) . '/' . $class . '.php'; $file = dirname(__FILE__) . $class . '.php';
require($file); require($file);
} }
} }
} }
\ No newline at end of file
This diff is collapsed.
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Client\Adapter;
use Solarium\Core\ConfigurableInterface;
use Solarium\Core\Client\Request;
use Solarium\Core\Client\Response;
use Solarium\Core\Client\Endpoint;
/**
* Interface for client adapters
*
* The goal of an adapter is to accept a query, execute it and return the right
* result object. This is actually quite a complex task as it involves the
* handling of all Solr communication.
*
* The adapter structure allows for varying implementations of this task.
*
* Most adapters will use some sort of HTTP client. In that case the
* query request builders and query response parsers can be used to simplify
* HTTP communication.
*
* However an adapter may also implement all logic by itself if needed.
*/
interface AdapterInterface extends ConfigurableInterface
{
/**
* Execute a request
*
* @param Request $request
* @param Endpoint $endpoint
* @return Response
*/
public function execute($request, $endpoint);
}
...@@ -31,58 +31,69 @@ ...@@ -31,58 +31,69 @@
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/ */
/**
* @namespace
*/
namespace Solarium\Core\Client\Adapter;
use Solarium\Core\Configurable;
use Solarium\Core\Client\Request;
use Solarium\Core\Client\Response;
use Solarium\Core\Client\Endpoint;
use Solarium\Exception\InvalidArgumentException;
use Solarium\Exception\RuntimeException;
use Solarium\Exception\HttpException;
/** /**
* cURL HTTP adapter * cURL HTTP adapter
* *
* @author Intervals <info@myintervals.com> * @author Intervals <info@myintervals.com>
* @package Solarium
* @subpackage Client
*/ */
class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter class Curl extends Configurable implements AdapterInterface
{ {
/** /**
* Initialization hook * Initialization hook
* *
* Checks the availability of Curl_http * Checks the availability of Curl_http
*
* @throws RuntimeException
*/ */
protected function _init() protected function init()
{ {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
if (!function_exists('curl_init')) { if (!function_exists('curl_init')) {
throw new Solarium_Exception('cURL is not available, install it to use the CurlHttp adapter'); throw new RuntimeException('cURL is not available, install it to use the CurlHttp adapter');
} }
parent::_init(); parent::init();
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} }
/** /**
* Execute a Solr request using the cURL Http * Execute a Solr request using the cURL Http
* *
* @param Solarium_Client_Request $request * @param Request $request
* @return Solarium_Client_Response * @param Endpoint $endpoint
* @return Response
*/ */
public function execute($request) public function execute($request, $endpoint)
{ {
return $this->_getData($request); return $this->getData($request, $endpoint);
} }
/** /**
* Execute request * Execute request
* *
* @param Solarium_Client_Request $request * @param Request $request
* @return array * @param Endpoint $endpoint
* @return Response
*/ */
protected function _getData($request) protected function getData($request, $endpoint)
{ {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
$handle = $this->createHandle($request); $handle = $this->createHandle($request, $endpoint);
$httpResponse = curl_exec($handle); $httpResponse = curl_exec($handle);
return $this->getResponse($handle, $httpResponse); return $this->getResponse($handle, $httpResponse);
...@@ -92,9 +103,9 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter ...@@ -92,9 +103,9 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter
/** /**
* Get the response for a curl handle * Get the response for a curl handle
* *
* @param resource $handle * @param resource $handle
* @param string $httpResponse * @param string $httpResponse
* @return Solarium_Client_Response * @return Response
*/ */
public function getResponse($handle, $httpResponse) public function getResponse($handle, $httpResponse)
{ {
...@@ -111,22 +122,25 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter ...@@ -111,22 +122,25 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter
curl_close($handle); curl_close($handle);
$this->check($data, $headers); $this->check($data, $headers);
return new Solarium_Client_Response($data, $headers);
return new Response($data, $headers);
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} }
/** /**
* Create curl handle for a request * Create curl handle for a request
* *
* @param Solarium_Client_Request $request * @throws InvalidArgumentException
* @param Request $request
* @param Endpoint $endpoint
* @return resource * @return resource
*/ */
public function createHandle($request) public function createHandle($request, $endpoint)
{ {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
$uri = $this->getBaseUri() . $request->getUri(); $uri = $endpoint->getBaseUri() . $request->getUri();
$method = $request->getMethod(); $method = $request->getMethod();
$options = $this->_createOptions($request); $options = $this->createOptions($request, $endpoint);
$handler = curl_init(); $handler = curl_init();
curl_setopt($handler, CURLOPT_URL, $uri); curl_setopt($handler, CURLOPT_URL, $uri);
...@@ -134,10 +148,20 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter ...@@ -134,10 +148,20 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter
curl_setopt($handler, CURLOPT_FOLLOWLOCATION, true); curl_setopt($handler, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($handler, CURLOPT_TIMEOUT, $options['timeout']); curl_setopt($handler, CURLOPT_TIMEOUT, $options['timeout']);
if ( $proxy = $this->getOption('proxy') ) {
curl_setopt($handler, CURLOPT_PROXY, $proxy);
}
if (!isset($options['headers']['Content-Type'])) { if (!isset($options['headers']['Content-Type'])) {
$options['headers']['Content-Type'] = 'text/xml; charset=utf-8'; $options['headers']['Content-Type'] = 'text/xml; charset=utf-8';
} }
$authData = $request->getAuthentication();
if ( !empty($authData['username']) && !empty($authData['password'])) {
curl_setopt($handler, CURLOPT_USERPWD, $authData['username']. ':' . $authData['password'] );
curl_setopt($handler, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
}
if (count($options['headers'])) { if (count($options['headers'])) {
$headers = array(); $headers = array();
foreach ($options['headers'] as $key => $value) { foreach ($options['headers'] as $key => $value) {
...@@ -146,15 +170,19 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter ...@@ -146,15 +170,19 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter
curl_setopt($handler, CURLOPT_HTTPHEADER, $headers); curl_setopt($handler, CURLOPT_HTTPHEADER, $headers);
} }
if ($method == Solarium_Client_Request::METHOD_POST) { if ($method == Request::METHOD_POST) {
curl_setopt($handler, CURLOPT_POST, true); curl_setopt($handler, CURLOPT_POST, true);
curl_setopt($handler, CURLOPT_POSTFIELDS, $request->getRawData()); if ($request->getFileUpload()) {
} else if ($method == Solarium_Client_Request::METHOD_GET) { curl_setopt($handler, CURLOPT_POSTFIELDS, array('content' => '@'.$request->getFileUpload()));
} else {
curl_setopt($handler, CURLOPT_POSTFIELDS, $request->getRawData());
}
} elseif ($method == Request::METHOD_GET) {
curl_setopt($handler, CURLOPT_HTTPGET, true); curl_setopt($handler, CURLOPT_HTTPGET, true);
} else if ($method == Solarium_Client_Request::METHOD_HEAD) { } elseif ($method == Request::METHOD_HEAD) {
curl_setopt($handler, CURLOPT_CUSTOMREQUEST, 'HEAD'); curl_setopt($handler, CURLOPT_CUSTOMREQUEST, 'HEAD');
} else { } else {
throw new Solarium_Exception("unsupported method: $method"); throw new InvalidArgumentException("unsupported method: $method");
} }
return $handler; return $handler;
...@@ -164,14 +192,15 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter ...@@ -164,14 +192,15 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter
/** /**
* Create http request options from request. * Create http request options from request.
* *
* @param Solarium_Client_Request $request * @param Request $request
* @param Endpoint $endpoint
* @return array * @return array
*/ */
protected function _createOptions($request) protected function createOptions($request, $endpoint)
{ {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
$options = array( $options = array(
'timeout' => $this->getTimeout() 'timeout' => $endpoint->getTimeout()
); );
foreach ($request->getHeaders() as $headerLine) { foreach ($request->getHeaders() as $headerLine) {
list($header, $value) = explode(':', $headerLine); list($header, $value) = explode(':', $headerLine);
...@@ -179,6 +208,7 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter ...@@ -179,6 +208,7 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter
$options['headers'][$header] = trim($value); $options['headers'][$header] = trim($value);
} }
} }
return $options; return $options;
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} }
...@@ -186,9 +216,9 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter ...@@ -186,9 +216,9 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter
/** /**
* Check result of a request * Check result of a request
* *
* @throws Solarium_Client_HttpException * @throws HttpException
* @param string $data * @param string $data
* @param array $headers * @param array $headers
* @return void * @return void
*/ */
public function check($data, $headers) public function check($data, $headers)
...@@ -196,7 +226,7 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter ...@@ -196,7 +226,7 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter
// if there is no data and there are no headers it's a total failure, // if there is no data and there are no headers it's a total failure,
// a connection to the host was impossible. // a connection to the host was impossible.
if (empty($data) && count($headers) == 0) { if (empty($data) && count($headers) == 0) {
throw new Solarium_Client_HttpException("HTTP request failed"); throw new HttpException("HTTP request failed");
} }
} }
} }
...@@ -31,45 +31,50 @@ ...@@ -31,45 +31,50 @@
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/ */
/**
* @namespace
*/
namespace Solarium\Core\Client\Adapter;
use Solarium\Core\Configurable;
use Solarium\Core\Client\Request;
use Solarium\Core\Client\Response;
use Solarium\Core\Client\Endpoint;
use Solarium\Exception\HttpException;
/** /**
* Basic HTTP adapter using a stream * Basic HTTP adapter using a stream
*
* @package Solarium
* @subpackage Client
*/ */
class Solarium_Client_Adapter_Http extends Solarium_Client_Adapter class Http extends Configurable implements AdapterInterface
{ {
/** /**
* Handle Solr communication * Handle Solr communication
* *
* @throws Solarium_Exception * @throws HttpException
* @param Solarium_Client_Request $request * @param Request $request
* @return Solarium_Client_Response * @param Endpoint $endpoint
* @return Response
*/ */
public function execute($request) public function execute($request, $endpoint)
{ {
$context = $this->createContext($request); $context = $this->createContext($request, $endpoint);
$uri = $this->getBaseUri() . $request->getUri(); $uri = $endpoint->getBaseUri() . $request->getUri();
list($data, $headers) = $this->_getData($uri, $context); list($data, $headers) = $this->getData($uri, $context);
$this->check($data, $headers); $this->check($data, $headers);
return new Solarium_Client_Response($data, $headers); return new Response($data, $headers);
} }
/** /**
* Check result of a request * Check result of a request
* *
* @throws Solarium_Client_HttpException * @throws HttpException
* @param string $data * @param string $data
* @param array $headers * @param array $headers
* @return void * @return void
*/ */
public function check($data, $headers) public function check($data, $headers)
...@@ -77,40 +82,56 @@ class Solarium_Client_Adapter_Http extends Solarium_Client_Adapter ...@@ -77,40 +82,56 @@ class Solarium_Client_Adapter_Http extends Solarium_Client_Adapter
// if there is no data and there are no headers it's a total failure, // if there is no data and there are no headers it's a total failure,
// a connection to the host was impossible. // a connection to the host was impossible.
if (false === $data && count($headers) == 0) { if (false === $data && count($headers) == 0) {
throw new Solarium_Client_HttpException("HTTP request failed"); throw new HttpException("HTTP request failed");
} }
} }
/** /**
* Create a stream context for a request * Create a stream context for a request
* *
* @param Solarium_Client_Request $request * @param Request $request
* @param Endpoint $endpoint
* @return resource * @return resource
*/ */
public function createContext($request) public function createContext($request, $endpoint)
{ {
$method = $request->getMethod(); $method = $request->getMethod();
$context = stream_context_create( $context = stream_context_create(
array('http' => array( array('http' => array(
'method' => $method, 'method' => $method,
'timeout' => $this->getTimeout() 'timeout' => $endpoint->getTimeout()
)) ))
); );
if ($method == Solarium_Client_Request::METHOD_POST) { if ($method == Request::METHOD_POST) {
$data = $request->getRawData(); if ($request->getFileUpload()) {
if (null !== $data) {
stream_context_set_option( stream_context_set_option(
$context, $context,
'http', 'http',
'content', 'content',
$data file_get_contents($request->getFileUpload())
); );
$request->addHeader('Content-Type: multipart/form-data');
} else {
$data = $request->getRawData();
if (null !== $data) {
stream_context_set_option(
$context,
'http',
'content',
$data
);
$request->addHeader('Content-Type: text/xml; charset=UTF-8'); $request->addHeader('Content-Type: text/xml; charset=UTF-8');
}
} }
} }
$authData = $request->getAuthentication();
if ( !empty($authData['username']) && !empty($authData['password'])) {
$request->addHeader('Authorization: Basic ' . base64_encode($authData['username']. ':' . $authData['password'] ));
}
$headers = $request->getHeaders(); $headers = $request->getHeaders();
if (count($headers) > 0) { if (count($headers) > 0) {
stream_context_set_option( stream_context_set_option(
...@@ -127,11 +148,11 @@ class Solarium_Client_Adapter_Http extends Solarium_Client_Adapter ...@@ -127,11 +148,11 @@ class Solarium_Client_Adapter_Http extends Solarium_Client_Adapter
/** /**
* Execute request * Execute request
* *
* @param string $uri * @param string $uri
* @param resource $context * @param resource $context
* @return array * @return array
*/ */
protected function _getData($uri, $context) protected function getData($uri, $context)
{ {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
$data = @file_get_contents($uri, false, $context); $data = @file_get_contents($uri, false, $context);
...@@ -146,4 +167,4 @@ class Solarium_Client_Adapter_Http extends Solarium_Client_Adapter ...@@ -146,4 +167,4 @@ class Solarium_Client_Adapter_Http extends Solarium_Client_Adapter
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} }
} }
\ No newline at end of file
...@@ -32,56 +32,67 @@ ...@@ -32,56 +32,67 @@
* @copyright Copyright 2011 Gasol Wu <gasol.wu@gmail.com> * @copyright Copyright 2011 Gasol Wu <gasol.wu@gmail.com>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/ */
/**
* @namespace
*/
namespace Solarium\Core\Client\Adapter;
use Solarium\Core\Configurable;
use Solarium\Core\Client\Request;
use Solarium\Core\Client\Response;
use Solarium\Core\Client\Endpoint;
use Solarium\Exception\RuntimeException;
use Solarium\Exception\HttpException;
use Solarium\Exception\InvalidArgumentException;
/** /**
* Pecl HTTP adapter * Pecl HTTP adapter
* *
* @author Gasol Wu <gasol.wu@gmail.com> * @author Gasol Wu <gasol.wu@gmail.com>
* @package Solarium
* @subpackage Client
*/ */
class Solarium_Client_Adapter_PeclHttp extends Solarium_Client_Adapter class PeclHttp extends Configurable implements AdapterInterface
{ {
/** /**
* Initialization hook * Initialization hook
* *
* Checks the availability of pecl_http * Checks the availability of pecl_http
*
* @throws RuntimeException
*/ */
protected function _init() protected function init()
{ {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
if (!class_exists('HttpRequest', false)) { if (!class_exists('HttpRequest', false)) {
throw new Solarium_Exception('Pecl_http is not available, install it to use the PeclHttp adapter'); throw new RuntimeException('Pecl_http is not available, install it to use the PeclHttp adapter');
} }
parent::_init(); parent::init();
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} }
/** /**
* Execute a Solr request using the Pecl Http * Execute a Solr request using the Pecl Http
* *
* @param Solarium_Client_Request $request * @throws HttpException
* @return Solarium_Client_Response * @param Request $request
* @param Endpoint $endpoint
* @return Response
*/ */
public function execute($request) public function execute($request, $endpoint)
{ {
$httpRequest = $this->toHttpRequest($request); $httpRequest = $this->toHttpRequest($request, $endpoint);
try { try {
$httpMessage = $httpRequest->send(); $httpMessage = $httpRequest->send();
} catch (Exception $e) { } catch (\Exception $e) {
throw new Solarium_Client_HttpException($e->getMessage()); throw new HttpException($e->getMessage());
} }
return new Solarium_Client_Response( return new Response(
$httpMessage->getBody(), $httpMessage->getBody(),
$this->_toRawHeaders($httpMessage) $this->toRawHeaders($httpMessage)
); );
} }
...@@ -98,10 +109,10 @@ class Solarium_Client_Adapter_PeclHttp extends Solarium_Client_Adapter ...@@ -98,10 +109,10 @@ class Solarium_Client_Adapter_PeclHttp extends Solarium_Client_Adapter
* $headers[0] = 'Content-Type: text/plain'; * $headers[0] = 'Content-Type: text/plain';
* </code> * </code>
* *
* @param $message HttpMessage * @param $message \HttpMessage
* @return array * @return array
*/ */
protected function _toRawHeaders($message) protected function toRawHeaders($message)
{ {
$headers[] = 'HTTP/' . $message->getHttpVersion() $headers[] = 'HTTP/' . $message->getHttpVersion()
. ' ' . $message->getResponseCode() . ' ' . $message->getResponseCode()
...@@ -116,18 +127,20 @@ class Solarium_Client_Adapter_PeclHttp extends Solarium_Client_Adapter ...@@ -116,18 +127,20 @@ class Solarium_Client_Adapter_PeclHttp extends Solarium_Client_Adapter
/** /**
* *
* adapt Solarium_Client_Request to HttpRequest * adapt Request to HttpRequest
* *
* {@link http://us.php.net/manual/en/http.constants.php * {@link http://us.php.net/manual/en/http.constants.php
* HTTP Predefined Constant} * HTTP Predefined Constant}
* *
* @param Solarium_Client_Request $request * @throws InvalidArgumentException
* @param Request $request
* @param Endpoint $endpoint
* @param HttpRequest * @param HttpRequest
*/ */
public function toHttpRequest($request) public function toHttpRequest($request, $endpoint)
{ {
$url = $this->getBaseUri() . $request->getUri(); $url = $endpoint->getBaseUri() . $request->getUri();
$httpRequest = new HttpRequest($url); $httpRequest = new \HttpRequest($url);
$headers = array(); $headers = array();
foreach ($request->getHeaders() as $headerLine) { foreach ($request->getHeaders() as $headerLine) {
...@@ -137,28 +150,41 @@ class Solarium_Client_Adapter_PeclHttp extends Solarium_Client_Adapter ...@@ -137,28 +150,41 @@ class Solarium_Client_Adapter_PeclHttp extends Solarium_Client_Adapter
} }
} }
switch($request->getMethod()) { $authData = $request->getAuthentication();
case Solarium_Client_Request::METHOD_GET: if ( !empty($authData['username']) && !empty($authData['password'])) {
$method = HTTP_METH_GET; $headers['Authorization'] = 'Basic ' . base64_encode($authData['username']. ':' . $authData['password'] );
break; }
case Solarium_Client_Request::METHOD_POST:
$method = HTTP_METH_POST; switch ($request->getMethod()) {
$httpRequest->setBody($request->getRawData()); case Request::METHOD_GET:
if (!isset($headers['Content-Type'])) { $method = HTTP_METH_GET;
$headers['Content-Type'] = 'text/xml; charset=utf-8'; break;
} case Request::METHOD_POST:
break; $method = HTTP_METH_POST;
case Solarium_Client_Request::METHOD_HEAD: if ($request->getFileUpload()) {
$method = HTTP_METH_HEAD; $httpRequest->addPostFile(
break; 'content',
default: $request->getFileUpload(),
throw new Solarium_Exception( 'application/octet-stream; charset=binary'
'Unsupported method: ' . $request->getMethod() );
); } else {
$httpRequest->setBody($request->getRawData());
if (!isset($headers['Content-Type'])) {
$headers['Content-Type'] = 'text/xml; charset=utf-8';
}
}
break;
case Request::METHOD_HEAD:
$method = HTTP_METH_HEAD;
break;
default:
throw new InvalidArgumentException(
'Unsupported method: ' . $request->getMethod()
);
} }
$httpRequest->setMethod($method); $httpRequest->setMethod($method);
$httpRequest->setOptions(array('timeout' => $this->getTimeout())); $httpRequest->setOptions(array('timeout' => $endpoint->getTimeout()));
$httpRequest->setHeaders($headers); $httpRequest->setHeaders($headers);
return $httpRequest; return $httpRequest;
......
<?php <?php
/** /**
* Copyright 2011 Bas de Nooijer. All rights reserved. * Copyright 2011 Bas de Nooijer. All rights reserved.
* Copyright 2012 Alexander Brausewetter. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -29,13 +30,24 @@ ...@@ -29,13 +30,24 @@
* policies, either expressed or implied, of the copyright holder. * policies, either expressed or implied, of the copyright holder.
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @copyright Copyright 2012 Alexander Brausewetter <alex@helpdeskhq.com>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/ */
/**
* @namespace
*/
namespace Solarium\Core\Client\Adapter;
use Solarium\Core\Configurable;
use Solarium\Core\Client;
use Solarium\Core\Client\Request;
use Solarium\Core\Client\Response;
use Solarium\Core\Client\Endpoint;
use Solarium\Exception\HttpException;
use Solarium\Exception\OutOfBoundsException;
/** /**
* Adapter that uses a Zend_Http_Client * Adapter that uses a Zend_Http_Client
* *
...@@ -44,25 +56,27 @@ ...@@ -44,25 +56,27 @@
* {@link http://framework.zend.com/manual/en/zend.http.html} * {@link http://framework.zend.com/manual/en/zend.http.html}
* *
* To use this adapter you need to have the Zend Framework available (autoloading) * To use this adapter you need to have the Zend Framework available (autoloading)
*
* @package Solarium
* @subpackage Client
*/ */
class Solarium_Client_Adapter_ZendHttp extends Solarium_Client_Adapter class ZendHttp extends Configurable implements AdapterInterface
{ {
/** /**
* Zend Http instance for communication with Solr * Zend Http instance for communication with Solr
* *
* @var Zend_Http_Client * @var \Zend_Http_Client
*/ */
protected $_zendHttp; protected $zendHttp;
/**
* @var int
*/
protected $timeout;
/** /**
* Set options * Set options
* *
* Overrides any existing values. * Overrides any existing values.
* *
* If the options array has an 'options' entry it is forwarded to the * If the options array has an 'options' entry it is forwarded to the
* Zend_Http_Client. See the Zend_Http_Clientdocs for the many config * Zend_Http_Client. See the Zend_Http_Clientdocs for the many config
* options available. * options available.
...@@ -70,26 +84,26 @@ class Solarium_Client_Adapter_ZendHttp extends Solarium_Client_Adapter ...@@ -70,26 +84,26 @@ class Solarium_Client_Adapter_ZendHttp extends Solarium_Client_Adapter
* The $options param should be an array or an object that has a toArray * The $options param should be an array or an object that has a toArray
* method, like Zend_Config * method, like Zend_Config
* *
* @param array|object $options * @param array|object $options
* @param boolean $overwrite * @param boolean $overwrite
* @return Solarium_Client_Adapter_ZendHttp Provides fluent interface * @return self Provides fluent interface
*/ */
public function setOptions($options, $overwrite = false) public function setOptions($options, $overwrite = false)
{ {
parent::setOptions($options, $overwrite); parent::setOptions($options, $overwrite);
// forward options to zendHttp instance // forward options to zendHttp instance
if (null !== $this->_zendHttp) { if (null !== $this->zendHttp) {
// forward timeout setting // forward timeout setting
$adapterOptions = array('timeout' => $this->getTimeout()); $adapterOptions = array();
// forward adapter options if available // forward adapter options if available
if (isset($this->_options['options'])) { if (isset($this->options['options'])) {
$adapterOptions = array_merge($adapterOptions, $this->_options['options']); $adapterOptions = array_merge($adapterOptions, $this->options['options']);
} }
$this->_zendHttp->setConfig($adapterOptions); $this->zendHttp->setConfig($adapterOptions);
} }
return $this; return $this;
...@@ -102,12 +116,13 @@ class Solarium_Client_Adapter_ZendHttp extends Solarium_Client_Adapter ...@@ -102,12 +116,13 @@ class Solarium_Client_Adapter_ZendHttp extends Solarium_Client_Adapter
* upon first use, using default and/or custom options (the most common use * upon first use, using default and/or custom options (the most common use
* case) * case)
* *
* @param Zend_Http_Client $zendHttp * @param \Zend_Http_Client $zendHttp
* @return Solarium_Client_Adapter_ZendHttp Provides fluent interface * @return self Provides fluent interface
*/ */
public function setZendHttp($zendHttp) public function setZendHttp($zendHttp)
{ {
$this->_zendHttp = $zendHttp; $this->zendHttp = $zendHttp;
return $this; return $this;
} }
...@@ -121,53 +136,94 @@ class Solarium_Client_Adapter_ZendHttp extends Solarium_Client_Adapter ...@@ -121,53 +136,94 @@ class Solarium_Client_Adapter_ZendHttp extends Solarium_Client_Adapter
* options, get the last response and use many other features offered by the * options, get the last response and use many other features offered by the
* Zend_Http_Client API. * Zend_Http_Client API.
* *
* @return Zend_Http_Client * @return \Zend_Http_Client
*/ */
public function getZendHttp() public function getZendHttp()
{ {
if (null == $this->_zendHttp) { if (null == $this->zendHttp) {
$options = array('timeout' => $this->getOption('timeout')); $options = array();
// forward zendhttp options // forward zendhttp options
if (isset($this->_options['options'])) { if (isset($this->options['options'])) {
$options = array_merge( $options = array_merge(
$options, $options,
$this->_options['options'] $this->options['options']
); );
} }
$this->_zendHttp = new Zend_Http_Client(null, $options); $this->zendHttp = new \Zend_Http_Client(null, $options);
} }
return $this->_zendHttp; return $this->zendHttp;
} }
/** /**
* Execute a Solr request using the Zend_Http_Client instance * Execute a Solr request using the Zend_Http_Client instance
* *
* @param Solarium_Client_Request $request * @throws HttpException
* @return Solarium_Client_Response * @param Request $request
* @param Endpoint $endpoint
* @return Response
*/ */
public function execute($request) public function execute($request, $endpoint)
{ {
$client = $this->getZendHttp(); $client = $this->getZendHttp();
$client->resetParameters();
switch ($request->getMethod()) {
case Request::METHOD_GET:
$client->setMethod(\Zend_Http_Client::GET);
$client->setParameterGet($request->getParams());
break;
case Request::METHOD_POST:
$client->setMethod(\Zend_Http_Client::POST);
if ($request->getFileUpload()) {
$this->prepareFileUpload($client, $request);
} else {
$client->setParameterGet($request->getParams());
$client->setRawData($request->getRawData());
$request->addHeader('Content-Type: text/xml; charset=UTF-8');
}
break;
case Request::METHOD_HEAD:
$client->setMethod(\Zend_Http_Client::HEAD);
$client->setParameterGet($request->getParams());
break;
default:
throw new OutOfBoundsException('Unsupported method: ' . $request->getMethod());
break;
}
$client->setMethod($request->getMethod()); $client->setUri($endpoint->getBaseUri() . $request->getUri());
$client->setUri($this->getBaseUri() . $request->getUri());
$client->setHeaders($request->getHeaders()); $client->setHeaders($request->getHeaders());
$client->setRawData($request->getRawData()); $this->timeout = $endpoint->getTimeout();
$response = $client->request(); $response = $client->request();
// throw an exception in case of a HTTP error return $this->prepareResponse(
$request,
$response
);
}
/**
* Prepare a solarium response from the given request and client
* response
*
* @param Request $request
* @param \Zend_Http_Response $response
* @return Response
*/
protected function prepareResponse($request, $response)
{
if ($response->isError()) { if ($response->isError()) {
throw new Solarium_Client_HttpException( throw new HttpException(
$response->getMessage(), $response->getMessage(),
$response->getStatus() $response->getStatus()
); );
} }
if ($request->getMethod() == Solarium_Client_Request::METHOD_HEAD) { if ($request->getMethod() == Request::METHOD_HEAD) {
$data = ''; $data = '';
} else { } else {
$data = $response->getBody(); $data = $response->getBody();
...@@ -176,7 +232,24 @@ class Solarium_Client_Adapter_ZendHttp extends Solarium_Client_Adapter ...@@ -176,7 +232,24 @@ class Solarium_Client_Adapter_ZendHttp extends Solarium_Client_Adapter
// this is used because getHeaders doesn't return the HTTP header... // this is used because getHeaders doesn't return the HTTP header...
$headers = explode("\n", $response->getHeadersAsString()); $headers = explode("\n", $response->getHeadersAsString());
return new Solarium_Client_Response($data, $headers); return new Response($data, $headers);
} }
} /**
\ No newline at end of file * Prepare the client to send the file and params in request
*
* @param \Zend_Http_Client $client
* @param Request $request
* @return void
*/
protected function prepareFileUpload($client, $request)
{
$filename = $request->getFileUpload();
$client->setFileUpload(
'content',
'content',
file_get_contents($filename),
'application/octet-stream; charset=binary'
);
}
}
This diff is collapsed.
...@@ -31,32 +31,20 @@ ...@@ -31,32 +31,20 @@
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/ */
/** /**
* Base class for all adapters * @namespace
*
* The goal of an adapter is to accept a query, execute it and return the right
* result object. This is actually quite a complex task as it involves the
* handling of all Solr communication.
*
* The adapter structure allows for varying implementations of this task.
*
* Most adapters will use some sort of HTTP client. In that case the
* Solarium_Client_Request request builders and Solarium_Client_Response
* response parsers can be used to simplify HTTP communication.
* See {@link Solarium_Client_Adapter_Http} as an example.
*
* However an adapter may also implement all logic by itself if needed.
*
* @package Solarium
* @subpackage Client
*/ */
abstract class Solarium_Client_Adapter extends Solarium_Configurable namespace Solarium\Core\Client;
use Solarium\Core\Configurable;
/**
* Class for describing an endpoint
*/
class Endpoint extends Configurable
{ {
/** /**
* Default options * Default options
* *
...@@ -65,7 +53,7 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable ...@@ -65,7 +53,7 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable
* *
* @var array * @var array
*/ */
protected $_options = array( protected $options = array(
'host' => '127.0.0.1', 'host' => '127.0.0.1',
'port' => 8983, 'port' => 8983,
'path' => '/solr', 'path' => '/solr',
...@@ -79,9 +67,9 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable ...@@ -79,9 +67,9 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable
* In this case the path needs to be cleaned of trailing slashes. * In this case the path needs to be cleaned of trailing slashes.
* @see setPath() * @see setPath()
*/ */
protected function _init() protected function init()
{ {
foreach ($this->_options AS $name => $value) { foreach ($this->options as $name => $value) {
switch ($name) { switch ($name) {
case 'path': case 'path':
$this->setPath($value); $this->setPath($value);
...@@ -90,15 +78,36 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable ...@@ -90,15 +78,36 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable
} }
} }
/**
* Get key value
*
* @return string
*/
public function getKey()
{
return $this->getOption('key');
}
/**
* Set key value
*
* @param string $value
* @return self Provides fluent interface
*/
public function setKey($value)
{
return $this->setOption('key', $value);
}
/** /**
* Set host option * Set host option
* *
* @param string $host This can be a hostname or an IP address * @param string $host This can be a hostname or an IP address
* @return Solarium_Client Provides fluent interface * @return self Provides fluent interface
*/ */
public function setHost($host) public function setHost($host)
{ {
return $this->_setOption('host', $host); return $this->setOption('host', $host);
} }
/** /**
...@@ -114,12 +123,12 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable ...@@ -114,12 +123,12 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable
/** /**
* Set port option * Set port option
* *
* @param int $port Common values are 80, 8080 and 8983 * @param int $port Common values are 80, 8080 and 8983
* @return Solarium_Client Provides fluent interface * @return self Provides fluent interface
*/ */
public function setPort($port) public function setPort($port)
{ {
return $this->_setOption('port', $port); return $this->setOption('port', $port);
} }
/** /**
...@@ -137,14 +146,16 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable ...@@ -137,14 +146,16 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable
* *
* If the path has a trailing slash it will be removed. * If the path has a trailing slash it will be removed.
* *
* @param string $path * @param string $path
* @return Solarium_Client Provides fluent interface * @return self Provides fluent interface
*/ */
public function setPath($path) public function setPath($path)
{ {
if (substr($path, -1) == '/') $path = substr($path, 0, -1); if (substr($path, -1) == '/') {
$path = substr($path, 0, -1);
}
return $this->_setOption('path', $path); return $this->setOption('path', $path);
} }
/** /**
...@@ -160,12 +171,12 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable ...@@ -160,12 +171,12 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable
/** /**
* Set core option * Set core option
* *
* @param string $core * @param string $core
* @return Solarium_Client Provides fluent interface * @return self Provides fluent interface
*/ */
public function setCore($core) public function setCore($core)
{ {
return $this->_setOption('core', $core); return $this->setOption('core', $core);
} }
/** /**
...@@ -181,12 +192,12 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable ...@@ -181,12 +192,12 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable
/** /**
* Set timeout option * Set timeout option
* *
* @param int $timeout * @param int $timeout
* @return Solarium_Client Provides fluent interface * @return self Provides fluent interface
*/ */
public function setTimeout($timeout) public function setTimeout($timeout)
{ {
return $this->_setOption('timeout', $timeout); return $this->setOption('timeout', $timeout);
} }
/** /**
...@@ -199,17 +210,6 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable ...@@ -199,17 +210,6 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable
return $this->getOption('timeout'); return $this->getOption('timeout');
} }
/**
* Execute a request
*
* Abstract method to require an implementation inside all adapters.
*
* @abstract
* @param Solarium_Client_Request $request
* @return Solarium_Client_Response
*/
abstract public function execute($request);
/** /**
* Get the base url for all requests * Get the base url for all requests
* *
...@@ -228,4 +228,4 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable ...@@ -228,4 +228,4 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable
return $uri; return $uri;
} }
} }
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment