Commit ad6bcdbc authored by Bas de Nooijer's avatar Bas de Nooijer

Merge branch 'release/2.3'

parents 7dcb0b21 2db071c4
......@@ -16,7 +16,7 @@
you could also write the switches here)
-->
<target name="phpunit">
<exec executable="phpunit" failonerror="true" />
<exec executable="phpunit" />
</target>
<!-- Run pdepend, phpmd, phpcpd, and phpcs in parallel -->
......@@ -33,7 +33,10 @@ you could also write the switches here)
<!-- Generate jdepend.xml and software metrics charts -->
<target name="pdepend">
<exec executable="pdepend">
<arg line="--jdepend-xml=${basedir}/build/logs/jdepend.xml library" />
<arg line="--overview-pyramid=${basedir}/build/pdepend/overview-pyramid.svg" />
<arg line="--jdepend-chart=${basedir}/build/pdepend/dependencies.svg" />
<arg line="--jdepend-xml=${basedir}/build/logs/jdepend.xml" />
<arg line="library" />
</exec>
</target>
......
{
"name": "solarium/solarium",
"type": "library",
"description": "PHP Solr client",
"keywords": ["solr", "search"],
"homepage": "http://www.solarium-project.org",
"version": "2.3.0",
"license": "NewBSD",
"authors": [
{
"name": "Bas de Nooijer",
"email": "github@raspberry.nl"
},
{
"name": "Gasol Wu",
"email": "gasol.wu@gmail.com"
}
],
"require": {
"php": ">=5.2.0"
},
"autoload": {
"psr-0": { "Solarium": "library/" }
}
}
<?php
require('init.php');
htmlHeader();
// create a client instance
$client = new Solarium_Client($config);
// get a select query instance
$query = $client->createSelect();
$query->setRows(0);
// add stats settings
$stats = $query->getStats();
$stats->addFacet('inStock');
$stats->createField('popularity');
$stats->createField('price')->addFacet('price')->addFacet('popularity');
// this executes the query and returns the result
$resultset = $client->select($query);
$statsResult = $resultset->getStats();
// display the stats results
foreach ($statsResult as $field) {
echo '<h1>' . $field->getName() . '</h1>';
echo 'Min: ' . $field->getMin() . '<br/>';
echo 'Max: ' . $field->getMax() . '<br/>';
echo 'Sum: ' . $field->getSum() . '<br/>';
echo 'Count: ' . $field->getCount() . '<br/>';
echo 'Missing: ' . $field->getMissing() . '<br/>';
echo 'SumOfSquares: ' . $field->getSumOfSquares() . '<br/>';
echo 'Mean: ' . $field->getMean() . '<br/>';
echo 'Stddev: ' . $field->getStddev() . '<br/>';
echo '<h2>Field facets</h2>';
foreach ($field->getFacets() as $field => $facet) {
echo '<h3>Facet ' . $field . '</h3>';
foreach ($facet AS $facetStats) {
echo '<h4>Value: ' . $facetStats->getValue() . '</h4>';
echo 'Min: ' . $facetStats->getMin() . '<br/>';
echo 'Max: ' . $facetStats->getMax() . '<br/>';
echo 'Sum: ' . $facetStats->getSum() . '<br/>';
echo 'Count: ' . $facetStats->getCount() . '<br/>';
echo 'Missing: ' . $facetStats->getMissing() . '<br/>';
echo 'SumOfSquares: ' . $facetStats->getSumOfSquares() . '<br/>';
echo 'Mean: ' . $facetStats->getMean() . '<br/>';
echo 'Stddev: ' . $facetStats->getStddev() . '<br/>';
}
}
echo '<hr/>';
}
htmlFooter();
\ No newline at end of file
<?php
require('init.php');
htmlHeader();
// create a client instance
$client = new Solarium_Client($config);
// get a select query instance
$query = $client->createSelect();
$query->setQuery('ipod');
// add debug settings
$debug = $query->getDebug();
$debug->setExplainOther('id:MA*');
// this executes the query and returns the result
$resultset = $client->select($query);
$debugResult = $resultset->getDebug();
// display the debug results
echo '<h1>Debug data</h1>';
echo 'Querystring: ' . $debugResult->getQueryString() . '<br/>';
echo 'Parsed query: ' . $debugResult->getParsedQuery() . '<br/>';
echo 'Query parser: ' . $debugResult->getQueryParser() . '<br/>';
echo 'Other query: ' . $debugResult->getOtherQuery() . '<br/>';
echo '<h2>Explain data</h2>';
foreach ($debugResult->getExplain() as $key => $explanation) {
echo '<h3>Document key: ' . $key . '</h3>';
echo 'Value: ' . $explanation->getValue() . '<br/>';
echo 'Match: ' . (($explanation->getMatch() == true) ? 'true' : 'false') . '<br/>';
echo 'Description: ' . $explanation->getDescription() . '<br/>';
echo '<h4>Details</h4>';
foreach ($explanation AS $detail) {
echo 'Value: ' . $detail->getValue() . '<br/>';
echo 'Match: ' . (($detail->getMatch() == true) ? 'true' : 'false') . '<br/>';
echo 'Description: ' . $detail->getDescription() . '<br/>';
echo '<hr/>';
}
}
echo '<h2>ExplainOther data</h2>';
foreach ($debugResult->getExplainOther() as $key => $explanation) {
echo '<h3>Document key: ' . $key . '</h3>';
echo 'Value: ' . $explanation->getValue() . '<br/>';
echo 'Match: ' . (($explanation->getMatch() == true) ? 'true' : 'false') . '<br/>';
echo 'Description: ' . $explanation->getDescription() . '<br/>';
echo '<h4>Details</h4>';
foreach ($explanation AS $detail) {
echo 'Value: ' . $detail->getValue() . '<br/>';
echo 'Match: ' . (($detail->getMatch() == true) ? 'true' : 'false') . '<br/>';
echo 'Description: ' . $detail->getDescription() . '<br/>';
echo '<hr/>';
}
}
echo '<h2>Timings (in ms)</h2>';
echo 'Total time: ' . $debugResult->getTiming()->getTime() . '<br/>';
echo '<h3>Phases</h3>';
foreach ($debugResult->getTiming()->getPhases() as $phaseName => $phaseData) {
echo '<h4>' . $phaseName . '</h4>';
foreach ($phaseData as $class => $time) {
echo $class . ': ' . $time . '<br/>';
}
echo '<hr/>';
}
htmlFooter();
\ No newline at end of file
<?php
require('init.php');
htmlHeader();
// create a client instance
$client = new Solarium_Client($config);
// get a terms query instance
$query = $client->createTerms();
$query->setFields('features,name');
$query->setLowerbound('i');
// this executes the query and returns the result
$resultset = $client->terms($query);
// display terms
foreach ($resultset as $field => $terms) {
echo '<h3>' . $field . '</h3>';
foreach ($terms as $term => $count) {
echo $term . ' (' . $count . ')<br/>';
}
echo '<hr/>';
}
htmlFooter();
\ No newline at end of file
<?php
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
require('init.php');
htmlHeader();
// create a client instance
$client = new Solarium_Client($config);
// set the adapter to curl
$client->setAdapter('Solarium_Client_Adapter_Curl');
// 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
require('init.php');
htmlHeader();
// create a client instance and get loadbalancer plugin instance
$client = new Solarium_Client($config);
$loadbalancer = $client->getPlugin('loadbalancer');
// apply loadbalancer settings
$optionsSolrOne = array('host' => '127.0.0.1', 'port' => 8983);
$optionsSolrTwo = array('host' => '127.0.0.1', 'port' => 7574);
$loadbalancer->addServer('solr1', $optionsSolrOne, 100);
$loadbalancer->addServer('solr2', $optionsSolrTwo, 200);
$loadbalancer->addServer('solr3', $optionsSolrTwo, 1);
// create a basic query to execute
$query = $client->createSelect();
// execute the query multiple times, displaying the server for each execution
for($i=1; $i<=8; $i++) {
$resultset = $client->select($query);
echo 'Query execution #' . $i . '<br/>';
echo 'NumFound: ' . $resultset->getNumFound(). '<br/>';
echo 'Server: ' . $loadbalancer->getLastServerKey() .'<hr/>';
}
// force a server for a query (normally solr 3 is extremely unlikely based on it's weight)
$loadbalancer->setForcedServerForNextQuery('solr3');
$resultset = $client->select($query);
echo 'Query execution with server forced to solr3<br/>';
echo 'NumFound: ' . $resultset->getNumFound(). '<br/>';
echo 'Server: ' . $loadbalancer->getLastServerKey() .'<hr/>';
// test a ping query
$query = $client->createPing();
$client->ping($query);
echo 'Loadbalanced ping query, should display a loadbalancing server:<br/>';
echo 'Ping server: ' . $loadbalancer->getLastServerKey() .'<hr/>';
// exclude ping query from loadbalancing
$loadbalancer->addBlockedQueryType(Solarium_Client::QUERYTYPE_PING);
$client->ping($query);
echo 'Non-loadbalanced ping query, should not display a loadbalancing server:<br/>';
echo 'Ping server: ' . $loadbalancer->getLastServerKey() .'<hr/>';
htmlFooter();
\ No newline at end of file
<?php
require('init.php');
htmlHeader();
// create a client instance and autoload the postbigrequest plugin
$client = new Solarium_Client($config);
$client->getPlugin('postbigrequest');
// create a basic query to execute
$query = $client->createSelect();
// add a huge filterquery to create a very long query string
// note: normally you would use a range for this, it's just an easy way to create a very big querystring as a test
$fq = '';
for($i=1; $i<=1000; $i++) {
$fq .= ' OR price:'.$i;
}
$fq = substr($fq, 4);
$query->createFilterQuery('fq')->setQuery($fq);
// without the plugin this query would fail as it is bigger than the default servlet container header buffer
$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
require('init.php');
htmlHeader();
// create a client instance and autoload the customize request plugin
$client = new Solarium_Client($config);
$customizer = $client->getPlugin('customizerequest');
// add a persistent HTTP header (using array input values)
$customizer->createCustomization(array(
'key' => 'auth',
'type' => 'header',
'name' => 'X-my-auth',
'value' => 'mypassword',
'persistent' => true
));
// add a persistent GET param (using fluent interface)
$customizer->createCustomization('session')
->setType('param')
->setName('ssid')
->setValue('md7Nhd86adye6sad46d')
->setPersistent(true);
// add a GET param thats only used for a single request (the default setting is no persistence)
$customizer->createCustomization('id')
->setType('param')
->setName('id')
->setValue(4576);
// create a basic query to execute
$query = $client->createSelect();
// execute query (you should be able to see the extra params in the solr log file)
$resultset = $client->select($query);
// display the total number of documents found by solr
echo 'NumFound: '.$resultset->getNumFound() . '<br/>';
// execute the same query again (this time the 'id' param should no longer show up in the logs)
$resultset = $client->select($query);
// display the total number of documents found by solr
echo 'NumFound: '.$resultset->getNumFound();
htmlFooter();
\ No newline at end of file
......@@ -54,6 +54,8 @@
<li><a href="2.1.5.7-grouping-by-query.php">2.1.5.7 Grouping by query</a></li>
<li><a href="2.1.5.8-distributed-search.php">2.1.5.8 Distributed search (sharding)</a></li>
<li><a href="2.1.5.9-spellcheck.php">2.1.5.9 Spellcheck</a></li>
<li><a href="2.1.5.10-stats.php">2.1.5.10 Stats</a></li>
<li><a href="2.1.5.11-debug.php">2.1.5.11 Debug (DebugQuery)</a></li>
</ul>
<li><a href="2.1.6-helper-functions.php">2.1.6 Helper functions</a></li>
<li><a href="2.1.7-query-reuse.php">2.1.7 Query re-use</a></li>
......@@ -79,6 +81,8 @@
<li><a href="2.4.1-analysis-document.php">2.4.1 Analysis query for a document</a></li>
<li><a href="2.4.2-analysis-field.php">2.4.2 Analysis query for a field</a></li>
</ul>
<li><a href="2.5-terms-query.php">2.5 Terms query</a></li>
</ul>
<li>4. Usage modes</li>
......@@ -103,13 +107,21 @@
<ul style="list-style:none;">
<li>6.1 Client adapters</li>
<ul style="list-style:none;">
<li><a href="6.1.1-zend-http-adapter.php">6.1 Zend_Http adapter</a></li>
<li><a href="6.1.2-pecl-http-adapter.php">6.2 Pecl_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.3-curl-adapter.php">6.1.3 Curl adapter</a></li>
</ul>
<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>
</ul>
<li>7. Plugins</li>
<ul style="list-style:none;">
<li><a href="7.1-plugin-loadbalancer.php">7.1 Loadbalancer</a></li>
<li><a href="7.2-plugin-postbigrequest.php">7.2 Post Big Requests</a></li>
<li><a href="7.3-plugin-customizerequest.php">7.3 customize Requests</a></li>
</ul>
</ul>
</body>
</html>
\ No newline at end of file
......@@ -87,6 +87,11 @@ class Solarium_Client extends Solarium_Configurable
*/
const QUERYTYPE_ANALYSIS_DOCUMENT = 'analysis-document';
/**
* Querytype terms
*/
const QUERYTYPE_TERMS = 'terms';
/**
* Default options
*
......@@ -132,6 +137,22 @@ class Solarium_Client extends Solarium_Configurable
'requestbuilder' => 'Solarium_Client_RequestBuilder_Analysis_Field',
'responseparser' => 'Solarium_Client_ResponseParser_Analysis_Field'
),
self::QUERYTYPE_TERMS => array(
'query' => 'Solarium_Query_Terms',
'requestbuilder' => 'Solarium_Client_RequestBuilder_Terms',
'responseparser' => 'Solarium_Client_ResponseParser_Terms'
),
);
/**
* Plugin types
*
* @var array
*/
protected $_pluginTypes = array(
'loadbalancer' => 'Solarium_Plugin_Loadbalancer',
'postbigrequest' => 'Solarium_Plugin_PostBigRequest',
'customizerequest' => 'Solarium_Plugin_CustomizeRequest',
);
/**
......@@ -139,7 +160,7 @@ class Solarium_Client extends Solarium_Configurable
*
* @var array
*/
protected $_plugins = array();
protected $_pluginInstances = array();
/**
* Adapter instance
......@@ -329,7 +350,7 @@ class Solarium_Client extends Solarium_Configurable
$plugin->init($this, $options);
$this->_plugins[$key] = $plugin;
$this->_pluginInstances[$key] = $plugin;
return $this;
}
......@@ -363,19 +384,27 @@ class Solarium_Client extends Solarium_Configurable
*/
public function getPlugins()
{
return $this->_plugins;
return $this->_pluginInstances;
}
/**
* Get a plugin instance
*
* @param string $key
* @param boolean $autocreate
* @return Solarium_Plugin_Abstract|null
*/
public function getPlugin($key)
public function getPlugin($key, $autocreate = true)
{
if (isset($this->_plugins[$key])) {
return $this->_plugins[$key];
if (isset($this->_pluginInstances[$key])) {
return $this->_pluginInstances[$key];
} elseif ($autocreate) {
if (array_key_exists($key, $this->_pluginTypes)) {
$this->registerPlugin($key, $this->_pluginTypes[$key]);
return $this->_pluginInstances[$key];
} else {
throw new Solarium_Exception('Cannot autoload plugin of unknown type: ' . $key);
}
} else {
return null;
}
......@@ -392,20 +421,43 @@ class Solarium_Client extends Solarium_Configurable
public function removePlugin($plugin)
{
if (is_object($plugin)) {
foreach ($this->_plugins as $key => $instance) {
foreach ($this->_pluginInstances as $key => $instance) {
if ($instance === $plugin) {
unset($this->_plugins[$key]);
unset($this->_pluginInstances[$key]);
break;
}
}
} else {
if (isset($this->_plugins[$plugin])) {
unset($this->_plugins[$plugin]);
if (isset($this->_pluginInstances[$plugin])) {
unset($this->_pluginInstances[$plugin]);
}
}
return $this;
}
/**
* Trigger external events for plugins
*
* This methods adds 'namespacing' to the event name to prevent conflicts with Solariums internal event keys.
*
* Based on the event name you can always tell if an event was internal (Solarium base classes)
* or external (plugins, even if it's a plugin included with Solarium).
*
* External events always have the 'event' prefix in the event name.
*
* @param string $event
* @param array $params
* @param bool $resultOverride
* @return void|mixed
*/
public function triggerEvent($event, $params, $resultOverride = false)
{
// Add namespacing
$event = 'event'.$event;
return $this->_callPlugins($event, $params, $resultOverride);
}
/**
* Forward events to plugins
*
......@@ -416,11 +468,13 @@ class Solarium_Client extends Solarium_Configurable
*/
protected function _callPlugins($event, $params, $resultOverride = false)
{
foreach ($this->_plugins AS $plugin) {
$result = call_user_func_array(array($plugin, $event), $params);
foreach ($this->_pluginInstances AS $plugin) {
if (method_exists($plugin, $event)) {
$result = call_user_func_array(array($plugin, $event), $params);
if ($result !== null && $resultOverride) {
return $result;
if ($result !== null && $resultOverride) {
return $result;
}
}
}
}
......@@ -501,9 +555,11 @@ class Solarium_Client extends Solarium_Configurable
public function executeRequest($request)
{
$pluginResult = $this->_callPlugins('preExecuteRequest', array($request), true);
if($pluginResult !== null) return $pluginResult;
$response = $this->getAdapter()->execute($request);
if ($pluginResult !== null) {
$response = $pluginResult; //a plugin result overrules the standard execution result
} else {
$response = $this->getAdapter()->execute($request);
}
$this->_callPlugins('postExecuteRequest', array($request, $response));
......@@ -620,6 +676,20 @@ class Solarium_Client extends Solarium_Configurable
return $this->execute($query);
}
/**
* Execute a terms query
*
* @internal This is a convenience method that forwards the query to the
* execute method, thus allowing for an easy to use and clean API.
*
* @param Solarium_Query_Terms $query
* @return Solarium_Result_Terms
*/
public function terms($query)
{
return $this->execute($query);
}
/**
* Create a query instance
*
......@@ -711,4 +781,15 @@ class Solarium_Client extends Solarium_Configurable
{
return $this->createQuery(self::QUERYTYPE_ANALYSIS_DOCUMENT, $options);
}
/**
* Create a terms query instance
*
* @param mixed $options
* @return Solarium_Query_Terms
*/
public function createTerms($options = null)
{
return $this->createQuery(self::QUERYTYPE_TERMS, $options);
}
}
......@@ -143,14 +143,14 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable
public function setPath($path)
{
if (substr($path, -1) == '/') $path = substr($path, 0, -1);
return $this->_setOption('path', $path);
}
/**
* Get path option
*
* @return void
* @return string
*/
public function getPath()
{
......@@ -215,7 +215,7 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable
*
* Based on host, path, port and core options.
*
* @return void
* @return string
*/
public function getBaseUri()
{
......
<?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/
*
* @package Solarium
* @subpackage Client
*/
/**
* cURL HTTP adapter
*
* @author Intervals <info@myintervals.com>
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter
{
/**
* Initialization hook
*
* Checks the availability of Curl_http
*/
protected function _init()
{
// @codeCoverageIgnoreStart
if (!function_exists('curl_init')) {
throw new Solarium_Exception('cURL is not available, install it to use the CurlHttp adapter');
}
parent::_init();
// @codeCoverageIgnoreEnd
}
/**
* Execute a Solr request using the cURL Http
*
* @param Solarium_Client_Request $request
* @return Solarium_Client_Response
*/
public function execute($request)
{
list($data, $headers) = $this->_getData($request);
$this->check($data, $headers);
return new Solarium_Client_Response($data, $headers);
}
/**
* Execute request
*
* @param Solarium_Client_Request $request
* @return array
*/
protected function _getData($request)
{
// @codeCoverageIgnoreStart
$uri = $this->getBaseUri() . $request->getUri();
$method = $request->getMethod();
$options = $this->_createOptions($request);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $options['timeout']);
if (!isset($options['headers']['Content-Type'])) {
$options['headers']['Content-Type'] = 'text/xml; charset=utf-8';
}
if (!isset($options['headers']['Content-Type'])) {
$options['headers']['Content-Type'] = 'text/xml; charset=utf-8';
}
if (count($options['headers'])) {
$arr = array();
foreach ($options['headers'] as $k => $v) {
$arr[] = $k . ": " . $v;
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $arr);
}
if ($method == Solarium_Client_Request::METHOD_POST) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request->getRawData());
$httpResponse = curl_exec($ch);
} else if ($method == Solarium_Client_Request::METHOD_GET) {
curl_setopt($ch, CURLOPT_HTTPGET, true);
$httpResponse = curl_exec($ch);
} else if ($method == Solarium_Client_Request::METHOD_HEAD) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
$httpResponse = curl_exec($ch);
} else {
throw new Solarium_Exception("unsupported method: $method");
}
$headers = array(); $data = '';
if ($httpResponse !== false) {
$data = $httpResponse;
$info = curl_getinfo($ch);
$headers = array();
$headers[] = 'HTTP/1.1 ' . $info['http_code']. ' OK';
}
return array($data, $headers);
// @codeCoverageIgnoreEnd
}
/**
* Create http request options from request.
*
* @param Solarium_Client_Request $request
* @return array
*/
protected function _createOptions($request)
{
// @codeCoverageIgnoreStart
$options = array(
'timeout' => $this->getTimeout()
);
foreach ($request->getHeaders() as $headerLine) {
list($header, $value) = explode(':', $headerLine);
if ($header = trim($header)) {
$options['headers'][$header] = trim($value);
}
}
return $options;
// @codeCoverageIgnoreEnd
}
/**
* Check result of a request
*
* @throws Solarium_Client_HttpException
* @param string $data
* @param array $headers
* @return void
*/
public function check($data, $headers)
{
// if there is no data and there are no headers it's a total failure,
// a connection to the host was impossible.
if (empty($data) && count($headers) == 0) {
throw new Solarium_Client_HttpException("HTTP request failed");
}
}
}
......@@ -58,15 +58,15 @@ class Solarium_Client_Adapter_Http extends Solarium_Client_Adapter
$uri = $this->getBaseUri() . $request->getUri();
list($data, $headers) = $this->_getData($uri, $context);
$this->check($data, $headers);
return new Solarium_Client_Response($data, $headers);
}
/**
* Check result of a request
*
*
* @throws Solarium_Client_HttpException
* @param string $data
* @param array $headers
......
......@@ -55,7 +55,7 @@ class Solarium_Client_Adapter_PeclHttp extends Solarium_Client_Adapter
protected function _init()
{
// @codeCoverageIgnoreStart
if (!function_exists('http_get')) {
if (!class_exists('HttpRequest', false)) {
throw new Solarium_Exception('Pecl_http is not available, install it to use the PeclHttp adapter');
}
......@@ -71,93 +71,96 @@ class Solarium_Client_Adapter_PeclHttp extends Solarium_Client_Adapter
*/
public function execute($request)
{
list($data, $headers) = $this->_getData($request);
$this->check($data, $headers);
return new Solarium_Client_Response($data, $headers);
$httpRequest = $this->toHttpRequest($request);
try {
$httpMessage = $httpRequest->send();
} catch (Exception $e) {
throw new Solarium_Client_HttpException($e->getMessage());
}
return new Solarium_Client_Response(
$httpMessage->getBody(),
$this->_toRawHeaders($httpMessage)
);
}
/**
* Execute request
* Convert key/value pair header to raw header.
*
* @param Solarium_Client_Request $request
* <code>
* //before
* $headers['Content-Type'] = 'text/plain';
*
* ...
*
* //after
* $headers[0] = 'Content-Type: text/plain';
* </code>
*
* @param $message HttpMessage
* @return array
*/
protected function _getData($request)
protected function _toRawHeaders($message)
{
// @codeCoverageIgnoreStart
$uri = $this->getBaseUri() . $request->getUri();
$method = $request->getMethod();
$options = $this->_createOptions($request);
if ($method == Solarium_Client_Request::METHOD_POST) {
if (!isset($options['headers']['Content-Type'])) {
$options['headers']['Content-Type'] = 'text/xml; charset=utf-8';
}
$httpResponse = http_post_data(
$uri, $request->getRawData(), $options
);
} else if ($method == Solarium_Client_Request::METHOD_GET) {
$httpResponse = http_get($uri, $options);
} else if ($method == Solarium_Client_Request::METHOD_HEAD) {
$httpResponse = http_head($uri, $options);
} else {
throw new Solarium_Exception("unsupported method: $method");
}
$headers[] = 'HTTP/' . $message->getHttpVersion()
. ' ' . $message->getResponseCode()
. ' ' . $message->getResponseStatus();
$headers = array();
$data = '';
if ($message = http_parse_message($httpResponse)) {
$data = $message->body;
if ($firstPositionOfCRLF = strpos($httpResponse, "\r\n\r\n")) {
$headersAsString = substr(
$httpResponse, 0, $firstPositionOfCRLF
);
$headers = explode("\n", $headersAsString);
}
foreach ($message->getHeaders() as $header => $value) {
$headers[] = "$header: $value";
}
return array($data, $headers);
// @codeCoverageIgnoreEnd
return $headers;
}
/**
* Create http request options from request.
*
* @link http://php.net/manual/en/http.request.options.php
* adapt Solarium_Client_Request to HttpRequest
*
* {@link http://us.php.net/manual/en/http.constants.php
* HTTP Predefined Constant}
*
* @param Solarium_Client_Request $request
* @return array
* @param HttpRequest
*/
protected function _createOptions($request)
public function toHttpRequest($request)
{
// @codeCoverageIgnoreStart
$options = array(
'timeout' => $this->getTimeout()
);
$url = $this->getBaseUri() . $request->getUri();
$httpRequest = new HttpRequest($url);
$headers = array();
foreach ($request->getHeaders() as $headerLine) {
list($header, $value) = explode(':', $headerLine);
if ($header = trim($header)) {
$options['headers'][$header] = trim($value);
$headers[$header] = trim($value);
}
}
return $options;
// @codeCoverageIgnoreEnd
}
/**
* Check result of a request
*
* @throws Solarium_Client_HttpException
* @param string $data
* @param array $headers
* @return void
*/
public function check($data, $headers)
{
// if there is no data and there are no headers it's a total failure,
// a connection to the host was impossible.
if (empty($data) && count($headers) == 0) {
throw new Solarium_Client_HttpException("HTTP request failed");
switch($request->getMethod()) {
case Solarium_Client_Request::METHOD_GET:
$method = HTTP_METH_GET;
break;
case Solarium_Client_Request::METHOD_POST:
$method = HTTP_METH_POST;
$httpRequest->setBody($request->getRawData());
if (!isset($headers['Content-Type'])) {
$headers['Content-Type'] = 'text/xml; charset=utf-8';
}
break;
case Solarium_Client_Request::METHOD_HEAD:
$method = HTTP_METH_HEAD;
break;
default:
throw new Solarium_Exception(
'Unsupported method: ' . $request->getMethod()
);
}
$httpRequest->setMethod($method);
$httpRequest->setOptions(array('timeout' => $this->getTimeout()));
$httpRequest->setHeaders($headers);
return $httpRequest;
}
}
......@@ -211,7 +211,7 @@ class Solarium_Client_Request extends Solarium_Configurable
*/
public function addParam($key, $value, $overwrite = false)
{
if ($value !== '' && $value !== null) {
if ($value !== null) {
if (!$overwrite && isset($this->_params[$key])) {
if (!is_array($this->_params[$key])) {
$this->_params[$key] = array($this->_params[$key]);
......@@ -362,6 +362,16 @@ class Solarium_Client_Request extends Solarium_Configurable
* @return string
*/
public function getUri()
{
return $this->getHandler() . '?' . $this->getQueryString();
}
/**
* Get the query string for this request
*
* @return string
*/
public function getQueryString()
{
$queryString = '';
if (count($this->_params) > 0) {
......@@ -373,6 +383,6 @@ class Solarium_Client_Request extends Solarium_Configurable
);
}
return $this->getHandler() . '?' . $queryString;
return $queryString;
}
}
\ No newline at end of file
......@@ -62,6 +62,8 @@ class Solarium_Client_RequestBuilder_Select extends Solarium_Client_RequestBuild
$request->addParam('rows', $query->getRows());
$request->addParam('fl', implode(',', $query->getFields()));
$request->addParam('wt', 'json');
$request->addParam('q.op', $query->getQueryDefaultOperator());
$request->addParam('df', $query->getQueryDefaultField());
// add sort fields to request
$sort = array();
......
<?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/
*
* @package Solarium
* @subpackage Client
*/
/**
* Add select component debug to the request
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_RequestBuilder_Select_Component_Debug
{
/**
* Add request settings for the debug component
*
* @param Solarium_Query_Select_Component_Debug $component
* @param Solarium_Client_Request $request
* @return Solarium_Client_Request
*/
public function build($component, $request)
{
$request->addParam('debugQuery', 'true');
$request->addParam('debug.explain.structured', 'true');
$request->addParam('explainOther', $component->getExplainOther());
return $request;
}
}
\ No newline at end of file
......@@ -44,7 +44,7 @@
*/
class Solarium_Client_RequestBuilder_Select_Component_Grouping
{
/**
* Add request settings for Grouping
*
......@@ -65,6 +65,7 @@ class Solarium_Client_RequestBuilder_Select_Component_Grouping
$request->addParam('group.main', $component->getMainResult());
$request->addParam('group.ngroups', $component->getNumberOfGroups());
$request->addParam('group.cache.percent', $component->getCachePercentage());
$request->addParam('group.truncate', $component->getTruncate());
return $request;
}
......
<?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/
*
* @package Solarium
* @subpackage Client
*/
/**
* Add select component stats to the request
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_RequestBuilder_Select_Component_Stats
{
/**
* Add request settings for the stats component
*
* @param Solarium_Query_Select_Component_Stats $component
* @param Solarium_Client_Request $request
* @return Solarium_Client_Request
*/
public function build($component, $request)
{
// enable stats
$request->addParam('stats', 'true');
// add fields
foreach ($component->getFields() as $field) {
$request->addParam('stats.field', $field->getKey());
// add field specific facet stats
foreach ($field->getFacets() as $facet) {
$request->addParam('f.'.$field->getKey().'.stats.facet', $facet);
}
}
// add facet stats for all fields
foreach ($component->getFacets() as $facet) {
$request->addParam('stats.facet', $facet);
}
return $request;
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer.
* Copyright 2011 Gasol Wu. PIXNET Digital Media Corporation.
* 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>
* @copyright Copyright 2011 Gasol Wu <gasol.wu@gmail.com>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Build a Terms query request
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_RequestBuilder_Terms extends Solarium_Client_RequestBuilder
{
/**
* Build request for a Terms query
*
* @param Solarium_Query_Terms $query
* @return Solarium_Client_Request
*/
public function build($query)
{
$request = new Solarium_Client_Request;
$request->setHandler($query->getHandler());
$request->addParam('terms', true);
$request->addParam('wt', 'json');
$request->addParam('terms.lower', $query->getLowerbound());
$request->addParam('terms.lower.incl', $query->getLowerboundInclude());
$request->addParam('terms.mincount', $query->getMinCount());
$request->addParam('terms.maxcount', $query->getMaxCount());
$request->addParam('terms.prefix', $query->getPrefix());
$request->addParam('terms.regex', $query->getRegex());
$request->addParam('terms.limit', $query->getLimit());
$request->addParam('terms.upper', $query->getUpperbound());
$request->addParam('terms.upper.incl', $query->getUpperboundInclude());
$request->addParam('terms.raw', $query->getRaw());
$request->addParam('terms.sort', $query->getSort());
$fields = explode(',', $query->getFields());
foreach ($fields as $field) {
$request->addParam('terms.fl', trim($field));
}
if ($query->getRegexFlags() !== null) {
$flags = explode(',', $query->getRegexFlags());
foreach ($flags as $flag) {
$request->addParam('terms.regex.flag', trim($flag));
}
}
return $request;
}
}
......@@ -129,7 +129,7 @@ class Solarium_Client_Response
/**
* Set headers
*
*
* @param array $headers
* @return void
*/
......
......@@ -72,7 +72,7 @@ class Solarium_Client_ResponseParser_MoreLikeThis extends Solarium_Client_Respon
if (isset($data['match']['docs'][0]) && true == $query->getMatchInclude()) {
$matchData = $data['match']['docs'][0];
$documentClass = $query->getOption('documentclass');
$fields = (array)$matchData;
$parseResult['match'] = new $documentClass($fields);
......
......@@ -82,10 +82,17 @@ class Solarium_Client_ResponseParser_Select extends Solarium_Client_ResponsePars
} else {
$numFound = null;
}
$status = null;
$queryTime = null;
if (isset($data['responseHeader'])) {
$status = $data['responseHeader']['status'];
$queryTime = $data['responseHeader']['QTime'];
}
return array(
'status' => $data['responseHeader']['status'],
'queryTime' => $data['responseHeader']['QTime'],
'status' => $status,
'queryTime' => $queryTime,
'numfound' => $numFound,
'documents' => $documents,
'components' => $components,
......
<?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/
*
* @package Solarium
* @subpackage Client
*/
/**
* Parse select component Debug result from the data
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_ResponseParser_Select_Component_Debug
{
/**
* Parse result data into result objects
*
* @param Solarium_Query_Select $query
* @param Solarium_Query_Select_Component_Debug $component
* @param array $data
* @return Solarium_Result_Select_Debug|null
*/
public function parse($query, $component, $data)
{
$result = null;
if (isset($data['debug'])) {
$debug = $data['debug'];
// get basic values from data
$queryString = (isset($debug['querystring'])) ? $debug['querystring'] : '';
$parsedQuery = (isset($debug['parsedquery'])) ? $debug['parsedquery'] : '';
$queryParser = (isset($debug['QParser'])) ? $debug['QParser'] : '';
$otherQuery = (isset($debug['otherQuery'])) ? $debug['otherQuery'] : '';
// parse explain data
if (isset($debug['explain']) && is_array($debug['explain'])) {
$explain = $this->_parseDocumentSet($debug['explain']);
} else {
$explain = new Solarium_Result_Select_Debug_DocumentSet(array());
}
// parse explainOther data
if (isset($debug['explainOther']) && is_array($debug['explainOther'])) {
$explainOther = $this->_parseDocumentSet($debug['explainOther']);
} else {
$explainOther = new Solarium_Result_Select_Debug_DocumentSet(array());
}
// parse timing data
$timing = null;
if (isset($debug['timing']) && is_array($debug['timing'])) {
$time = null;
$timingPhases = array();
foreach ($debug['timing'] as $key => $timingData) {
switch($key) {
case 'time':
$time = $timingData;
break;
default:
$timingPhases[$key] = $this->_parseTimingPhase($key, $timingData);
}
}
$timing = new Solarium_Result_Select_Debug_Timing($time, $timingPhases);
}
// create result object
$result = new Solarium_Result_Select_Debug(
$queryString,
$parsedQuery,
$queryParser,
$otherQuery,
$explain,
$explainOther,
$timing
);
}
return $result;
}
/**
* Parse data into a documentset
*
* Used for explain and explainOther
*
* @param array $data
* @return Solarium_Result_Select_Debug_DocumentSet
*/
protected function _parseDocumentSet($data)
{
$docs = array();
foreach ($data as $key => $documentData) {
$details = array();
if (isset($documentData['details']) && is_array($documentData['details'])) {
foreach ($documentData['details'] as $detailData) {
$details[] = new Solarium_Result_Select_Debug_Detail(
$detailData['match'],
$detailData['value'],
$detailData['description']
);
}
}
$docs[$key] = new Solarium_Result_Select_Debug_Document(
$key,
$documentData['match'],
$documentData['value'],
$documentData['description'],
$details
);
}
return new Solarium_Result_Select_Debug_DocumentSet($docs);
}
/**
* Parse raw timing phase data into a result class
*
* @param string $name
* @param array $data
* @return Solarium_Result_Select_Debug_TimingPhase
*/
protected function _parseTimingPhase($name, $data)
{
$time = 0.0;
$classes = array();
foreach ($data as $key => $timingData) {
switch($key) {
case 'time':
$time = $timingData;
break;
default:
$classes[$key] = $timingData['time'];
}
}
return new Solarium_Result_Select_Debug_TimingPhase($name, $time, $classes);
}
}
\ No newline at end of file
......@@ -177,7 +177,7 @@ class Solarium_Client_ResponseParser_Select_Component_FacetSet
$offset = 0;
$counts = array();
while(isset($data['counts'][$offset]) && isset($data['counts'][$offset+1])) {
while (isset($data['counts'][$offset]) && isset($data['counts'][$offset+1])) {
$counts[$data['counts'][$offset]] = $data['counts'][$offset+1];
$offset += 2;
}
......
......@@ -69,23 +69,34 @@ class Solarium_Client_ResponseParser_Select_Component_Grouping
$valueGroups = array();
foreach ($result['groups'] as $valueGroupResult) {
$value = (isset($valueGroupResult['groupValue'])) ? $valueGroupResult['groupValue'] : null;
$numFound = (isset($valueGroupResult['doclist']['numFound'])) ? $valueGroupResult['doclist']['numFound'] : null;
$start = (isset($valueGroupResult['doclist']['start'])) ? $valueGroupResult['doclist']['start'] : null;
$value = (isset($valueGroupResult['groupValue'])) ?
$valueGroupResult['groupValue'] : null;
$numFound = (isset($valueGroupResult['doclist']['numFound'])) ?
$valueGroupResult['doclist']['numFound'] : null;
$start = (isset($valueGroupResult['doclist']['start'])) ?
$valueGroupResult['doclist']['start'] : null;
// create document instances
$documentClass = $query->getOption('documentclass');
$documents = array();
if (isset($valueGroupResult['doclist']['docs']) && is_array($valueGroupResult['doclist']['docs'])) {
if (isset($valueGroupResult['doclist']['docs']) &&
is_array($valueGroupResult['doclist']['docs'])) {
foreach ($valueGroupResult['doclist']['docs'] as $doc) {
$documents[] = new $documentClass($doc);
}
}
$valueGroups[] = new Solarium_Result_Select_Grouping_ValueGroup($value, $numFound, $start, $documents);
$valueGroups[] = new Solarium_Result_Select_Grouping_ValueGroup(
$value, $numFound, $start, $documents
);
}
$groups[$field] = new Solarium_Result_Select_Grouping_FieldGroup($matches, $groupCount, $valueGroups);
$groups[$field] = new Solarium_Result_Select_Grouping_FieldGroup(
$matches, $groupCount, $valueGroups
);
}
}
......@@ -110,7 +121,9 @@ class Solarium_Client_ResponseParser_Select_Component_Grouping
}
// create a group result object
$group = new Solarium_Result_Select_Grouping_QueryGroup($matches, $numFound, $start, $maxScore, $documents);
$group = new Solarium_Result_Select_Grouping_QueryGroup(
$matches, $numFound, $start, $maxScore, $documents
);
$groups[$groupQuery] = $group;
}
}
......
<?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/
*
* @package Solarium
* @subpackage Client
*/
/**
* Parse select component Stats result from the data
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_ResponseParser_Select_Component_Stats
{
/**
* Parse result data into result objects
*
* @param Solarium_Query_Select $query
* @param Solarium_Query_Select_Component_Stats $stats
* @param array $data
* @return Solarium_Result_Select_Stats
*/
public function parse($query, $stats, $data)
{
$results = array();
if (isset($data['stats']['stats_fields'])) {
$statResults = $data['stats']['stats_fields'];
foreach ($statResults AS $field => $stats) {
if (isset($stats['facets'])) {
foreach ($stats['facets'] as $facetField => $values) {
foreach ($values as $value => $valueStats) {
$stats['facets'][$facetField][$value] = new Solarium_Result_Select_Stats_FacetValue(
$value, $valueStats
);
}
}
}
$results[$field] = new Solarium_Result_Select_Stats_Result($field, $stats);
}
}
return new Solarium_Result_Select_Stats($results);
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Gasol Wu. PIXNET Digital Media Corporation.
* 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 Gasol Wu <gasol.wu@gmail.com>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Parse MoreLikeThis response data
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_ResponseParser_Terms extends Solarium_Client_ResponseParser
{
/**
* Get result data for the response
*
* @param Solarium_Result_Terms $result
* @return array
*/
public function parse($result)
{
$termResults = array();
$data = $result->getData();
$field = $result->getQuery()->getFields();
$fields = explode(',', $field);
foreach ($fields as $field) {
$field = trim($field);
if (isset($data['terms'][$field])) {
$terms = $data['terms'][$field];
for ($i = 0; $i < count($terms); $i += 2) {
$termResults[$field][$terms[$i]] = $terms[$i + 1];
}
}
}
$status = null;
$queryTime = null;
if (isset($data['responseHeader'])) {
$status = $data['responseHeader']['status'];
$queryTime = $data['responseHeader']['QTime'];
}
return array(
'status' => $status,
'queryTime' => $queryTime,
'results' => $termResults,
);
}
}
......@@ -55,9 +55,16 @@ class Solarium_Client_ResponseParser_Update extends Solarium_Client_ResponsePars
{
$data = $result->getData();
$status = null;
$queryTime = null;
if (isset($data['responseHeader'])) {
$status = $data['responseHeader']['status'];
$queryTime = $data['responseHeader']['QTime'];
}
return array(
'status' => $data['responseHeader']['status'],
'queryTime' => $data['responseHeader']['QTime'],
'status' => $status,
'queryTime' => $queryTime,
);
}
......
......@@ -87,7 +87,7 @@ class Solarium_Configurable
* @param array|Zend_Config $options
* @param boolean $overwrite True for overwriting existing options, false
* for merging (new values overwrite old ones if needed)
*
*
* @return void
*/
public function setOptions($options, $overwrite = false)
......@@ -98,8 +98,7 @@ class Solarium_Configurable
if (is_object($options)) {
$options = $options->toArray();
} else {
throw new Solarium_Exception('Options must be an '
. 'array or a Zend_Config object');
throw new Solarium_Exception('Options must be an array or a Zend_Config object');
}
}
......
<?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/
*
* @package Solarium
*/
/**
* CustomizeRequest plugin
*
* You can use this plugin to customize the requests generated for Solarium queries by adding or overwriting
* params and/or headers.
*
* @package Solarium
* @subpackage Plugin
*/
class Solarium_Plugin_CustomizeRequest extends Solarium_Plugin_Abstract
{
/**
* Holds customizations added to this plugin
*
* @var array
*/
protected $_customizations = array();
/**
* Initialize options
*
* @return void
*/
protected function _init()
{
foreach ($this->_options AS $name => $value) {
switch ($name) {
case 'customization':
$this->addCustomizations($value);
break;
}
}
}
/**
* Create a Customization instance
*
* If you supply a string as the first arguments ($options) it will be used as the key for the Customization
* and it will be added to this plugin.
* If you supply an options array/object that contains a key the Customization will also be added to the plugin.
*
* When no key is supplied the Customization cannot be added, in that case you will need to add it manually
* after setting the key, by using the addCustomization method.
*
* @param mixed $options
* @return Solarium_Plugin_CustomizeRequest_Customization
*/
public function createCustomization($options = null)
{
if (is_string($options)) {
$fq = new Solarium_Plugin_CustomizeRequest_Customization;
$fq->setKey($options);
} else {
$fq = new Solarium_Plugin_CustomizeRequest_Customization($options);
}
if ($fq->getKey() !== null) {
$this->addCustomization($fq);
}
return $fq;
}
/**
* Add a customization
*
* Supports a Customization instance or a config array, in that case a new
* Customization instance wil be created based on the options.
*
* @param Solarium_Plugin_CustomizeRequest_Customization|array $customization
* @return Solarium_Plugin_CustomizeRequest Provides fluent interface
*/
public function addCustomization($customization)
{
if (is_array($customization)) {
$customization = new Solarium_Plugin_CustomizeRequest_Customization($customization);
}
$key = $customization->getKey();
// check for non-empty key
if (0 === strlen($key)) {
throw new Solarium_Exception('A Customization must have a key value');
}
// check for a unique key
if (array_key_exists($key, $this->_customizations)) {
//double add calls for the same customization are ignored, others cause an exception
if ($this->_customizations[$key] !== $customization) {
throw new Solarium_Exception('A Customization must have a unique key value');
}
}
$this->_customizations[$key] = $customization;
return $this;
}
/**
* Add multiple Customizations
*
* @param array $customizations
* @return Solarium_Plugin_CustomizeRequest Provides fluent interface
*/
public function addCustomizations(array $customizations)
{
foreach ($customizations AS $key => $customization) {
// in case of a config array: add key to config
if (is_array($customization) && !isset($customization['key'])) {
$customization['key'] = $key;
}
$this->addCustomization($customization);
}
return $this;
}
/**
* Get a Customization
*
* @param string $key
* @return string
*/
public function getCustomization($key)
{
if (isset($this->_customizations[$key])) {
return $this->_customizations[$key];
} else {
return null;
}
}
/**
* Get all Customizations
*
* @return array
*/
public function getCustomizations()
{
return $this->_customizations;
}
/**
* Remove a single Customization
*
* You can remove a Customization by passing it's key, or by passing the Customization instance
*
* @param string|Solarium_Plugin_CustomizeRequest_Customization $customization
* @return Solarium_Plugin_CustomizeRequest Provides fluent interface
*/
public function removeCustomization($customization)
{
if (is_object($customization)) {
$customization = $customization->getKey();
}
if (isset($this->_customizations[$customization])) {
unset($this->_customizations[$customization]);
}
return $this;
}
/**
* Remove all Customizations
*
* @return Solarium_Plugin_CustomizeRequest Provides fluent interface
*/
public function clearCustomizations()
{
$this->_customizations = array();
return $this;
}
/**
* Set multiple Customizations
*
* This overwrites any existing Customizations
*
* @param array $customizations
*/
public function setCustomizations($customizations)
{
$this->clearCustomizations();
$this->addCustomizations($customizations);
}
/**
* Event hook to customize the request object
*
* @param Solarium_Query $query
* @param Solarium_Client_Request $request
* @return void
*/
public function postCreateRequest($query, $request)
{
foreach ($this->getCustomizations() as $key => $customization) {
// first validate
if (!$customization->isValid()) {
throw new Solarium_Exception('Request customization with key "' . $key . '" is invalid');
}
// apply to request, depending on type
switch ($customization->getType()) {
case Solarium_Plugin_CustomizeRequest_Customization::TYPE_PARAM:
$request->addParam(
$customization->getName(),
$customization->getValue(),
$customization->getOverwrite()
);
break;
case Solarium_Plugin_CustomizeRequest_Customization::TYPE_HEADER:
$request->addHeader($customization->getName() . ': ' . $customization->getValue());
break;
}
// remove single-use customizations after use
if (!$customization->getPersistent()) {
$this->removeCustomization($key);
}
}
}
}
\ No newline at end of file
<?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/
*
* @package Solarium
*/
/**
* Customization value object
*
* @package Solarium
* @subpackage Plugin
*/
class Solarium_Plugin_CustomizeRequest_Customization extends Solarium_Configurable
{
/**
* Type definitions
*/
const TYPE_PARAM = 'param';
const TYPE_HEADER = 'header';
/**
* Default options
*
* @var array
*/
protected $_options = array(
'key' => null,
'type' => null,
'name' => null,
'value' => null,
'persistent' => false,
'overwrite' => true,
);
/**
* Set key value
*
* @param string $value
* @return Solarium_Plugin_CustomizeRequest_Customization
*/
public function setKey($value)
{
$this->_setOption('key', $value);
return $this;
}
/**
* Get key value
*
* @return string
*/
public function getKey()
{
return $this->getOption('key');
}
/**
* Set type value
*
* @param string $value
* @return Solarium_Plugin_CustomizeRequest_Customization
*/
public function setType($value)
{
$this->_setOption('type', $value);
return $this;
}
/**
* Get type value
*
* @return string
*/
public function getType()
{
return $this->getOption('type');
}
/**
* Set name value
*
* @param string $value
* @return Solarium_Plugin_CustomizeRequest_Customization
*/
public function setName($value)
{
$this->_setOption('name', $value);
return $this;
}
/**
* Get name value
*
* @return string
*/
public function getName()
{
return $this->getOption('name');
}
/**
* Set value
*
* @param string $value
* @return Solarium_Plugin_CustomizeRequest_Customization
*/
public function setValue($value)
{
$this->_setOption('value', $value);
return $this;
}
/**
* Get value
*
* @return string
*/
public function getValue()
{
return $this->getOption('value');
}
/**
* Set persistent on/off
*
* @param boolean $value
* @return Solarium_Plugin_CustomizeRequest_Customization
*/
public function setPersistent($value)
{
$this->_setOption('persistent', $value);
return $this;
}
/**
* Get persistent setting
*
* @return boolean
*/
public function getPersistent()
{
return $this->getOption('persistent');
}
/**
* Set overwrite option on/off
*
* @param boolean $value
* @return Solarium_Plugin_CustomizeRequest_Customization
*/
public function setOverwrite($value)
{
$this->_setOption('overwrite', $value);
return $this;
}
/**
* Get overwrite option value
*
* @return boolean
*/
public function getOverwrite()
{
return $this->getOption('overwrite');
}
/**
* Check for all mandatory settings
*
* @return bool
*/
public function isValid()
{
$type = $this->getType();
if ($type !== self::TYPE_PARAM && $type !== self::TYPE_HEADER) return false;
if (null == $this->getKey() || null == $this->getName() || null == $this->getValue()) return false;
return true;
}
}
\ No newline at end of file
<?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/
*
* @package Solarium
*/
/**
* Loadbalancer plugin
*
* Using this plugin you can use software loadbalancing over multiple Solr instances.
* You can add any number of servers, each with their own weight. The weight influences
* the probability of a server being used for a query.
*
* By default all queries except updates are loadbalanced. This can be customized by setting blocked querytypes.
* Any querytype that may not be loadbalanced will be executed by Solarium with the default adapter settings.
* In a master-slave setup the default adapter should be connecting to the master server.
*
* You can also enable the failover mode. In this case a query will be retried on another server in case of error.
*
* @package Solarium
* @subpackage Plugin
*/
class Solarium_Plugin_Loadbalancer extends Solarium_Plugin_Abstract
{
/**
* Default options
*
* @var array
*/
protected $_options = array(
'failoverenabled' => false,
'failovermaxretries' => 1,
);
/**
* Registered servers
*
* @var array
*/
protected $_servers = array();
/**
* Query types that are blocked from loadbalancing
*
* @var array
*/
protected $_blockedQueryTypes = array(
Solarium_Client::QUERYTYPE_UPDATE => true
);
/**
* Key of the last used server
*
* The value can be null if no queries have been executed, or if the last executed query didn't use loadbalancing.
*
* @var null|string
*/
protected $_lastServerKey;
/**
* Server to use for next query (overrules randomizer)
*
* @var string
*/
protected $_nextServer;
/**
* Presets of the client adapter
*
* These settings are used to restore the adapter to it's original status for queries
* that cannot be loadbalanced (for instance update queries that need to go to the master)
*
* @var array
*/
protected $_adapterPresets;
/**
* Pool of servers to use for requests
*
* @var Solarium_Plugin_Loadbalancer_WeightedRandomChoice
*/
protected $_randomizer;
/**
* Query type
*
* @var string
*/
protected $_queryType;
/**
* Used for failover mechanism
*
* @var array
*/
protected $_serverExcludes;
/**
* Initialize options
*
* Several options need some extra checks or setup work, for these options
* the setters are called.
*
* @return void
*/
protected function _init()
{
foreach ($this->_options AS $name => $value) {
switch ($name) {
case 'server':
$this->setServers($value);
break;
case 'blockedquerytype':
$this->setBlockedQueryTypes($value);
break;
}
}
}
/**
* Set failover enabled option
*
* @param bool $value
* @return self Provides fluent interface
*/
public function setFailoverEnabled($value)
{
return $this->_setOption('failoverenabled', $value);
}
/**
* Get failoverenabled option
*
* @return boolean
*/
public function getFailoverEnabled()
{
return $this->getOption('failoverenabled');
}
/**
* Set failover max retries
*
* @param int $value
* @return self Provides fluent interface
*/
public function setFailoverMaxRetries($value)
{
return $this->_setOption('failovermaxretries', $value);
}
/**
* Get failovermaxretries option
*
* @return int
*/
public function getFailoverMaxRetries()
{
return $this->getOption('failovermaxretries');
}
/**
* Add a server to the loadbalacing 'pool'
*
* @param string $key
* @param array $options
* @param int $weight Must be a positive number
* @return self Provides fluent interface
*/
public function addServer($key, $options, $weight = 1)
{
if (array_key_exists($key, $this->_servers)) {
throw new Solarium_Exception('A server for the loadbalancer plugin must have a unique key');
} else {
$this->_servers[$key] = array(
'options' => $options,
'weight' => $weight,
);
}
// reset the randomizer as soon as a new server is added
$this->_randomizer = null;
return $this;
}
/**
* Get servers in the loadbalancing pool
*
* @return array
*/
public function getServers()
{
return $this->_servers;
}
/**
* Get a server entry by key
*
* @param string $key
* @return array
*/
public function getServer($key)
{
if (!isset($this->_servers[$key])) {
throw new Solarium_Exception('Unknown server key');
}
return $this->_servers[$key];
}
/**
* Set servers, overwriting any existing servers
*
* @param array $servers Use server key as array key and 'options' and 'weight' as array entries
* @return self Provides fluent interface
*/
public function setServers($servers)
{
$this->clearServers();
$this->addServers($servers);
return $this;
}
/**
* Add multiple servers
*
* @param array $servers
* @return self Provides fluent interface
*/
public function addServers($servers)
{
foreach ($servers AS $key => $data) {
$this->addServer($key, $data['options'], $data['weight']);
}
return $this;
}
/**
* Clear all server entries
*
* @return self Provides fluent interface
*/
public function clearServers()
{
$this->_servers = array();
}
/**
* Remove a server by key
*
* @param string $key
* @return self Provides fluent interface
*/
public function removeServer($key)
{
if (isset($this->_servers[$key])) {
unset($this->_servers[$key]);
}
return $this;
}
/**
* Set a forced server (by key) for the next request
*
* As soon as one query has used the forced server this setting is reset. If you want to remove this setting
* pass NULL as the key value.
*
* If the next query cannot be loadbalanced (for instance based on the querytype) this setting is ignored
* but will still be reset.
*
* @param string|null $key
* @return self Provides fluent interface
*/
public function setForcedServerForNextQuery($key)
{
if ($key !== null && !array_key_exists($key, $this->_servers)) {
throw new Solarium_Exception('Unknown server forced for next query');
}
$this->_nextServer = $key;
return $this;
}
/**
* Get the ForcedServerForNextQuery value
*
* @return string|null
*/
public function getForcedServerForNextQuery()
{
return $this->_nextServer;
}
/**
* Get an array of blocked querytypes
*
* @return array
*/
public function getBlockedQueryTypes()
{
return array_keys($this->_blockedQueryTypes);
}
/**
* Set querytypes to block from loadbalancing
*
* Overwrites any existing types
*
* @param array $types Use an array with the constants defined in Solarium_Client as values
* @return self Provides fluent interface
*/
public function setBlockedQueryTypes($types)
{
$this->clearBlockedQueryTypes();
$this->addBlockedQueryTypes($types);
return $this;
}
/**
* Add a querytype to block from loadbalancing
*
* @param string $type Use one of the constants defined in Solarium_Client
* @return self Provides fluent interface
*/
public function addBlockedQueryType($type)
{
if (!array_key_exists($type, $this->_blockedQueryTypes)) {
$this->_blockedQueryTypes[$type] = true;
}
return $this;
}
/**
* Add querytypes to block from loadbalancing
*
* Appended to any existing types
*
* @param array $types Use an array with the constants defined in Solarium_Client as values
* @return self Provides fluent interface
*/
public function addBlockedQueryTypes($types)
{
foreach ($types AS $type) {
$this->addBlockedQueryType($type);
}
}
/**
* Remove a single querytype from the block list
*
* @param string $type
* @return void
*/
public function removeBlockedQueryType($type)
{
if (array_key_exists($type, $this->_blockedQueryTypes)) {
unset($this->_blockedQueryTypes[$type]);
}
}
/**
* Clear all blocked querytypes
*
* @return self Provides fluent interface
*/
public function clearBlockedQueryTypes()
{
$this->_blockedQueryTypes = array();
}
/**
* Get the key of the server that was used for the last query
*
* May return a null value if no query has been executed yet, or the last query could not be loadbalanced.
*
* @return null|string
*/
public function getLastServerKey()
{
return $this->_lastServerKey;
}
/**
* Event hook to capture querytype
*
* @param Solarium_Query $query
* @return void
*/
public function preCreateRequest($query)
{
$this->_queryType = $query->getType();
}
/**
* Event hook to adjust client settings just before query execution
*
* @param Solarium_Client_Request $request
* @return Solarium_Client_Response
*/
public function preExecuteRequest($request)
{
$adapter = $this->_client->getAdapter();
// save adapter presets (once) to allow the settings to be restored later
if ($this->_adapterPresets == null) {
$this->_adapterPresets = array(
'host' => $adapter->getHost(),
'port' => $adapter->getPort(),
'path' => $adapter->getPath(),
'core' => $adapter->getCore(),
'timeout' => $adapter->getTimeout(),
);
}
// check querytype: is loadbalancing allowed?
if (!array_key_exists($this->_queryType, $this->_blockedQueryTypes)) {
return $this->_getLoadbalancedResponse($request);
} else {
$options = $this->_adapterPresets;
$this->_lastServerKey = null;
// apply new settings to adapter
$adapter->setOptions($options);
// execute request and return result
return $adapter->execute($request);
}
}
/**
* Execute a request using the adapter
*
* @param Solarium_Client_Request $request
* @return Solarium_Client_Response $response
*/
protected function _getLoadbalancedResponse($request)
{
$this->_serverExcludes = array(); // reset for each query
$adapter = $this->_client->getAdapter();
if ($this->getFailoverEnabled() == true) {
for ($i=0; $i<=$this->getFailoverMaxRetries(); $i++) {
$options = $this->_getRandomServerOptions();
$adapter->setOptions($options);
try {
return $adapter->execute($request);
} catch(Solarium_Client_HttpException $e) {
// ignore HTTP errors and try again
// but do issue an event for things like logging
$e = new Solarium_Exception('Maximum number of loadbalancer retries reached');
$this->_client->triggerEvent('LoadbalancerServerFail', array($options, $e));
}
}
// if we get here no more retries available, throw exception
$e = new Solarium_Exception('Maximum number of loadbalancer retries reached');
throw $e;
} else {
// no failover retries, just execute and let an exception bubble upwards
$options = $this->_getRandomServerOptions();
$adapter->setOptions($options);
return $adapter->execute($request);
}
}
/**
* Get options array for a randomized server
*
* @return array
*/
protected function _getRandomServerOptions()
{
// determine the server to use
if ($this->_nextServer !== null) {
$serverKey = $this->_nextServer;
// reset forced server directly after use
$this->_nextServer = null;
} else {
$serverKey = $this->_getRandomizer()->getRandom($this->_serverExcludes);
}
$this->_serverExcludes[] = $serverKey;
$this->_lastServerKey = $serverKey;
return $this->_servers[$serverKey]['options'];
}
/**
* Get randomizer instance
*
* @return Solarium_Plugin_Loadbalancer_WeightedRandomChoice
*/
protected function _getRandomizer()
{
if ($this->_randomizer === null) {
$choices = array();
foreach ($this->_servers AS $key => $settings) {
$choices[$key] = $settings['weight'];
}
$this->_randomizer = new Solarium_Plugin_Loadbalancer_WeightedRandomChoice($choices);
}
return $this->_randomizer;
}
}
\ No newline at end of file
<?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/
*
* @package Solarium
*/
/**
* Weighted random choice class
*
* For use in the loadbalancer plugin
*
* @package Solarium
* @subpackage Plugin
*/
class Solarium_Plugin_Loadbalancer_WeightedRandomChoice
{
/**
* Total weight of all choices
*
* @var int
*/
protected $_totalWeight = 0;
/**
* Choices total lookup array
*
* @var array
*/
protected $_lookup = array();
/**
* Values lookup array
*
* @var array
*/
protected $_values = array();
/**
* Constructor
*
* @param array $choices
*/
public function __construct($choices)
{
$i = 0;
foreach ($choices AS $key => $weight) {
if ($weight <=0) throw new Solarium_Exception('Weight must be greater than zero');
$this->_totalWeight += $weight;
$this->_lookup[$i] = $this->_totalWeight;
$this->_values[$i] = $key;
$i++;
}
}
/**
* Get a (weighted) random entry
*
* @param array $excludes Keys to exclude
* @return string
*/
public function getRandom($excludes = array())
{
if (count($excludes) == count($this->_values)) {
throw new Solarium_Exception('No more server entries available');
}
// continue until a non-excluded value is found
// @todo optimize?
$result = null;
while (1) {
$result = $this->_values[$this->_getKey()];
if(!in_array($result, $excludes)) break;
}
return $result;
}
/**
* Get a (weighted) random entry key
*
* @return int
*/
protected function _getKey()
{
$random = mt_rand(1, $this->_totalWeight);
$high = count($this->_lookup)-1;
$low = 0;
while ( $low < $high ) {
$probe = (int)(($high + $low) / 2);
if ($this->_lookup[$probe] < $random) {
$low = $probe + 1;
} else if ($this->_lookup[$probe] > $random) {
$high = $probe - 1;
} else {
return $probe;
}
}
if ($this->_lookup[$low] >= $random) {
return $low;
} else {
return $low+1;
}
}
}
\ No newline at end of file
<?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/
*
* @package Solarium
*/
/**
* PostBigRequest plugin
*
* If you reach the url/header length limit of your servlet container your queries will fail.
* You can increase the limit in the servlet container, but if that's not possible this plugin can automatically
* convert big GET requests into POST requests. A POST request (usually) has a much higher limit.
*
* The default maximum querystring length is 1024. This doesn't include the base url or headers.
* For most servlet setups this limit leaves enough room for that extra data. Adjust the limit if needed.
*
* @package Solarium
* @subpackage Plugin
*/
class Solarium_Plugin_PostBigRequest extends Solarium_Plugin_Abstract
{
/**
* Default options
*
* @var array
*/
protected $_options = array(
'maxquerystringlength' => 1024,
);
/**
* Set maxquerystringlength enabled option
*
* @param integer $value
* @return self Provides fluent interface
*/
public function setMaxQueryStringLength($value)
{
return $this->_setOption('maxquerystringlength', $value);
}
/**
* Get maxquerystringlength option
*
* @return integer
*/
public function getMaxQueryStringLength()
{
return $this->getOption('maxquerystringlength');
}
/**
* Event hook to adjust client settings just before query execution
*
* @param Solarium_Query $query
* @param Solarium_Client_Request $request
* @return void
*/
public function postCreateRequest($query, $request)
{
$queryString = $request->getQueryString();
if ($request->getMethod() == Solarium_Client_Request::METHOD_GET &&
strlen($queryString) > $this->getMaxQueryStringLength()) {
$request->setMethod(Solarium_Client_Request::METHOD_POST);
$request->setRawData($queryString);
$request->clearParams();
$request->addHeader('Content-Type: application/x-www-form-urlencoded');
}
}
}
\ No newline at end of file
......@@ -59,6 +59,16 @@ class Solarium_Query_Select extends Solarium_Query
*/
const SORT_ASC = 'asc';
/**
* Solr query operator AND
*/
const QUERY_OPERATOR_AND = 'AND';
/**
* Solr query operator OR
*/
const QUERY_OPERATOR_OR = 'OR';
/**
* Query component facetset
*/
......@@ -94,6 +104,16 @@ class Solarium_Query_Select extends Solarium_Query
*/
const COMPONENT_DISTRIBUTEDSEARCH = 'distributedsearch';
/**
* Query component stats
*/
const COMPONENT_STATS = 'stats';
/**
* Query component debug
*/
const COMPONENT_DEBUG = 'debug';
/**
* Get type for this query
*
......@@ -160,6 +180,16 @@ class Solarium_Query_Select extends Solarium_Query
'requestbuilder' => 'Solarium_Client_RequestBuilder_Select_Component_DistributedSearch',
'responseparser' => null,
),
self::COMPONENT_STATS => array(
'component' => 'Solarium_Query_Select_Component_Stats',
'requestbuilder' => 'Solarium_Client_RequestBuilder_Select_Component_Stats',
'responseparser' => 'Solarium_Client_ResponseParser_Select_Component_Stats',
),
self::COMPONENT_DEBUG => array(
'component' => 'Solarium_Query_Select_Component_Debug',
'requestbuilder' => 'Solarium_Client_RequestBuilder_Select_Component_Debug',
'responseparser' => 'Solarium_Client_ResponseParser_Select_Component_Debug',
),
);
/**
......@@ -256,6 +286,50 @@ class Solarium_Query_Select extends Solarium_Query
return $this->getOption('query');
}
/**
* Set default query operator
*
* Use one of the constants as value
*
* @param string $operator
* @return Solarium_Query_Select Provides fluent interface
*/
public function setQueryDefaultOperator($operator)
{
return $this->_setOption('querydefaultoperator', $operator);
}
/**
* Get the default query operator
*
* @return null|string
*/
public function getQueryDefaultOperator()
{
return $this->getOption('querydefaultoperator');
}
/**
* Set default query field
*
* @param string $field
* @return Solarium_Query_Select Provides fluent interface
*/
public function setQueryDefaultField($field)
{
return $this->_setOption('querydefaultfield', $field);
}
/**
* Get the default query field
*
* @return null|string
*/
public function getQueryDefaultField()
{
return $this->getOption('querydefaultfield');
}
/**
* Set the start offset
*
......@@ -563,13 +637,10 @@ class Solarium_Query_Select extends Solarium_Query
throw new Solarium_Exception('A filterquery must have a key value');
}
if (array_key_exists($key, $this->_filterQueries)) {
if ($this->_filterQueries[$key] === $filterQuery) {
//double add calls for the same FQ are ignored
//@todo add trigger_error with a notice?
} else {
throw new Solarium_Exception('A filterquery must have a unique key value within a query');
}
//double add calls for the same FQ are ignored, but non-unique keys cause an exception
//@todo add trigger_error with a notice for double add calls?
if (array_key_exists($key, $this->_filterQueries) && $this->_filterQueries[$key] !== $filterQuery) {
throw new Solarium_Exception('A filterquery must have a unique key value within a query');
} else {
$this->_filterQueries[$key] = $filterQuery;
}
......@@ -877,4 +948,28 @@ class Solarium_Query_Select extends Solarium_Query
return $this->getComponent(Solarium_Query_Select::COMPONENT_DISTRIBUTEDSEARCH, true);
}
/**
* Get a Stats component instance
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Query_Select_Component_Stats
*/
public function getStats()
{
return $this->getComponent(Solarium_Query_Select::COMPONENT_STATS, true);
}
/**
* Get a Debug component instance
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Query_Select_Component_Debug
*/
public function getDebug()
{
return $this->getComponent(Solarium_Query_Select::COMPONENT_DEBUG, true);
}
}
<?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/
*
* @package Solarium
* @subpackage Query
*/
/**
* Debug component
*
* @link http://wiki.apache.org/solr/CommonQueryParameters#Debugging
*
* @package Solarium
* @subpackage Query
*/
class Solarium_Query_Select_Component_Debug extends Solarium_Query_Select_Component
{
/**
* Component type
*
* @var string
*/
protected $_type = Solarium_Query_Select::COMPONENT_DEBUG;
/**
* Get the explainOther option
*
* @return string|null
*/
public function getExplainOther()
{
return $this->getOption('explainother');
}
/**
* Set the explainOther query
*
* @param string $query
* @return self Provides fluent interface
*/
public function setExplainOther($query)
{
return $this->_setOption('explainother', $query);
}
}
\ No newline at end of file
......@@ -66,7 +66,7 @@ class Solarium_Query_Select_Component_Facet_MultiQuery extends Solarium_Query_Se
protected function _init()
{
parent::_init();
foreach ($this->_options AS $name => $value) {
switch ($name) {
case 'query':
......@@ -79,7 +79,7 @@ class Solarium_Query_Select_Component_Facet_MultiQuery extends Solarium_Query_Se
/**
* Get the facet type
*
*
* @return string
*/
public function getType()
......@@ -133,8 +133,7 @@ class Solarium_Query_Select_Component_Facet_MultiQuery extends Solarium_Query_Se
}
if (array_key_exists($key, $this->_facetQueries)) {
throw new Solarium_Exception('A query must have a unique key'
. ' value within a multiquery facet');
throw new Solarium_Exception('A query must have a unique key value within a multiquery facet');
}
// forward shared excludes
......
......@@ -266,13 +266,10 @@ class Solarium_Query_Select_Component_FacetSet extends Solarium_Query_Select_Com
throw new Solarium_Exception('A facet must have a key value');
}
if (array_key_exists($key, $this->_facets)) {
if ($this->_facets[$key] === $facet) {
//double add calls for the same facet are ignored
//@todo add trigger_error with a notice?
} else {
throw new Solarium_Exception('A facet must have a unique key value within a query');
}
//double add calls for the same facet are ignored, but non-unique keys cause an exception
//@todo add trigger_error with a notice for double add calls?
if (array_key_exists($key, $this->_facets) && $this->_facets[$key] !== $facet) {
throw new Solarium_Exception('A facet must have a unique key value within a query');
} else {
$this->_facets[$key] = $facet;
}
......
......@@ -45,7 +45,7 @@
* @link http://wiki.apache.org/solr/FieldCollapsing
*
* @since 2.1.0
*
*
* @package Solarium
* @subpackage Query
*/
......@@ -64,7 +64,7 @@ class Solarium_Query_Select_Component_Grouping extends Solarium_Query_Select_Com
/**
* Component type
*
*
* @var string
*/
protected $_type = Solarium_Query_Select::COMPONENT_GROUPING;
......@@ -78,7 +78,7 @@ class Solarium_Query_Select_Component_Grouping extends Solarium_Query_Select_Com
/**
* Queries for grouping
*
*
* @var array
*/
protected $_queries = array();
......@@ -381,5 +381,29 @@ class Solarium_Query_Select_Component_Grouping extends Solarium_Query_Select_Com
{
return $this->getOption('cachepercentage');
}
/**
* Set truncate option
*
* If true, facet counts are based on the most relevant document of each group matching the query.
* Same applies for StatsComponent. Default is false. Only available from Solr 3.4
*
* @param boolean $value
* @return Solarium_Query_Select_Component_Grouping Provides fluent interface
*/
public function setTruncate($value)
{
return $this->_setOption('truncate', $value);
}
/**
* Get truncate option
*
* @return boolean|null
*/
public function getTruncate()
{
return $this->getOption('truncate');
}
}
\ No newline at end of file
<?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/
*
* @package Solarium
* @subpackage Query
*/
/**
* Stats component
*
* @link http://wiki.apache.org/solr/StatsComponent
*
* @package Solarium
* @subpackage Query
*/
class Solarium_Query_Select_Component_Stats extends Solarium_Query_Select_Component
{
/**
* Component type
*
* @var string
*/
protected $_type = Solarium_Query_Select::COMPONENT_STATS;
/**
* Stats facets for all fields
*
* @var array
*/
protected $_facets = array();
/**
* Fields
*
* @var array
*/
protected $_fields = array();
/**
* Initialize options
*
* Several options need some extra checks or setup work, for these options
* the setters are called.
*
* @return void
*/
protected function _init()
{
foreach ($this->_options AS $name => $value) {
switch ($name) {
case 'field':
$this->setFields($value);
break;
case 'facet':
$this->setFacets($value);
break;
}
}
}
/**
* Create a field instance
*
* If you supply a string as the first arguments ($options) it will be used as the key for the field
* and it will be added to this query component.
* If you supply an options array/object that contains a key the field will also be added to the component.
*
* When no key is supplied the field cannot be added, in that case you will need to add it manually
* after setting the key, by using the addField method.
*
* @param mixed $options
* @return Solarium_Query_Select_Component_Stats_Field
*/
public function createField($options = null)
{
if (is_string($options)) {
$fq = new Solarium_Query_Select_Component_Stats_Field;
$fq->setKey($options);
} else {
$fq = new Solarium_Query_Select_Component_Stats_Field($options);
}
if ($fq->getKey() !== null) {
$this->addField($fq);
}
return $fq;
}
/**
* Add a field
*
* Supports a field instance or a config array, in that case a new
* field instance wil be created based on the options.
*
* @param Solarium_Query_Select_Component_Stats_Field|array $field
* @return Solarium_Query_Select_Component_Stats Provides fluent interface
*/
public function addField($field)
{
if (is_array($field)) {
$field = new Solarium_Query_Select_Component_Stats_Field($field);
}
$key = $field->getKey();
if (0 === strlen($key)) {
throw new Solarium_Exception('A field must have a key value');
}
//double add calls for the same field are ignored, but non-unique keys cause an exception
//@todo add trigger_error with a notice for double add calls?
if (array_key_exists($key, $this->_fields) && $this->_fields[$key] !== $field) {
throw new Solarium_Exception('A field must have a unique key value');
} else {
$this->_fields[$key] = $field;
}
return $this;
}
/**
* Add multiple fields
*
* @param array $fields
* @return Solarium_Query_Select_Component_Stats Provides fluent interface
*/
public function addFields(array $fields)
{
foreach ($fields AS $key => $field) {
// in case of a config array: add key to config
if (is_array($field) && !isset($field['key'])) {
$field['key'] = $key;
}
$this->addField($field);
}
return $this;
}
/**
* Get a field
*
* @param string $key
* @return string
*/
public function getField($key)
{
if (isset($this->_fields[$key])) {
return $this->_fields[$key];
} else {
return null;
}
}
/**
* Get all fields
*
* @return array
*/
public function getFields()
{
return $this->_fields;
}
/**
* Remove a single field
*
* You can remove a field by passing it's key, or by passing the field instance
*
* @param string|Solarium_Query_Select_Component_Stats_Field $field
* @return Solarium_Query_Select_Component_Stats Provides fluent interface
*/
public function removeField($field)
{
if (is_object($field)) {
$field = $field->getKey();
}
if (isset($this->_fields[$field])) {
unset($this->_fields[$field]);
}
return $this;
}
/**
* Remove all fields
*
* @return Solarium_Query_Select_Component_Stats Provides fluent interface
*/
public function clearFields()
{
$this->_fields = array();
return $this;
}
/**
* Set multiple fields
*
* This overwrites any existing fields
*
* @param array $fields
*/
public function setFields($fields)
{
$this->clearFields();
$this->addFields($fields);
}
/**
* Specify a facet to return in the resultset
*
* @param string $facet
* @return Solarium_Query_Select_Component_Stats Provides fluent interface
*/
public function addFacet($facet)
{
$this->_facets[$facet] = true;
return $this;
}
/**
* Specify multiple facets to return in the resultset
*
* @param string|array $facets can be an array or string with comma
* separated facetnames
*
* @return Solarium_Query_Select_Component_Stats Provides fluent interface
*/
public function addFacets($facets)
{
if (is_string($facets)) {
$facets = explode(',', $facets);
$facets = array_map('trim', $facets);
}
foreach ($facets AS $facet) {
$this->addFacet($facet);
}
return $this;
}
/**
* Remove a facet from the facet list
*
* @param string $facet
* @return Solarium_Query_Select_Component_Stats Provides fluent interface
*/
public function removeFacet($facet)
{
if (isset($this->_facets[$facet])) {
unset($this->_facets[$facet]);
}
return $this;
}
/**
* Remove all facets from the facet list.
*
* @return Solarium_Query_Select_Component_Stats Provides fluent interface
*/
public function clearFacets()
{
$this->_facets = array();
return $this;
}
/**
* Get the list of facets
*
* @return array
*/
public function getFacets()
{
return array_keys($this->_facets);
}
/**
* Set multiple facets
*
* This overwrites any existing facets
*
* @param array $facets
* @return Solarium_Query_Select_Component_Stats Provides fluent interface
*/
public function setFacets($facets)
{
$this->clearFacets();
$this->addFacets($facets);
return $this;
}
}
\ No newline at end of file
<?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/
*
* @package Solarium
* @subpackage Query
*
* TODO
* Voorbeeld request:
* http://localhost:8983/solr/select?q=*:*&stats=true&stats.field=price&stats.field=popularity
* &stats.twopass=true&rows=0&indent=true&stats.facet=inStock&f.price.stats.facet=price
* &f.price.stats.facet=popularity
*/
/**
* Stats component field class
*
* @package Solarium
* @subpackage Query
*/
class Solarium_Query_Select_Component_Stats_Field extends Solarium_Configurable
{
/**
* Field facets (for stats)
*
* @var array
*/
protected $_facets = array();
/**
* Initialize options
*
* Several options need some extra checks or setup work, for these options
* the setters are called.
*
* @return void
*/
protected function _init()
{
foreach ($this->_options AS $name => $value) {
switch ($name) {
case 'facet':
$this->setFacets($value);
break;
}
}
}
/**
* Get key value
*
* @return string
*/
public function getKey()
{
return $this->getOption('key');
}
/**
* Set key value
*
* @param string $value
* @return Solarium_Query_Select_Component_Stats Provides fluent interface
*/
public function setKey($value)
{
return $this->_setOption('key', $value);
}
/**
* Specify a facet to return in the resultset
*
* @param string $facet
* @return Solarium_Query_Select_Component_Stats Provides fluent interface
*/
public function addFacet($facet)
{
$this->_facets[$facet] = true;
return $this;
}
/**
* Specify multiple facets to return in the resultset
*
* @param string|array $facets can be an array or string with comma
* separated facetnames
*
* @return Solarium_Query_Select_Component_Stats Provides fluent interface
*/
public function addFacets($facets)
{
if (is_string($facets)) {
$facets = explode(',', $facets);
$facets = array_map('trim', $facets);
}
foreach ($facets AS $facet) {
$this->addFacet($facet);
}
return $this;
}
/**
* Remove a facet from the facet list
*
* @param string $facet
* @return Solarium_Query_Select_Component_Stats Provides fluent interface
*/
public function removeFacet($facet)
{
if (isset($this->_facets[$facet])) {
unset($this->_facets[$facet]);
}
return $this;
}
/**
* Remove all facets from the facet list.
*
* @return Solarium_Query_Select_Component_Stats Provides fluent interface
*/
public function clearFacets()
{
$this->_facets = array();
return $this;
}
/**
* Get the list of facets
*
* @return array
*/
public function getFacets()
{
return array_keys($this->_facets);
}
/**
* Set multiple facets
*
* This overwrites any existing facets
*
* @param array $facets
* @return Solarium_Query_Select_Component_Stats Provides fluent interface
*/
public function setFacets($facets)
{
$this->clearFacets();
$this->addFacets($facets);
return $this;
}
}
\ No newline at end of file
<?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/
*
* @package Solarium
* @subpackage Query
*/
/**
* Terns query
*
* A terms query provides access to the indexed terms in a field and the number of documents that match each term.
* This can be useful for doing auto-suggest or other things that operate at the term level instead of the search
* or document level. Retrieving terms in index order is very fast since the implementation directly uses Lucene's
* TermEnum to iterate over the term dictionary.
*
* @package Solarium
* @subpackage Query
*/
class Solarium_Query_Terms extends Solarium_Query
{
/**
* Get type for this query
*
* @return string
*/
public function getType()
{
return Solarium_Client::QUERYTYPE_TERMS;
}
/**
* Default options
*
* @var array
*/
protected $_options = array(
'resultclass' => 'Solarium_Result_Terms',
'handler' => 'terms',
);
/**
* Set the field name(s) to get the terms from
*
* For multiple fields use a comma-separated string
*
* @param string $value
* @return self Provides fluent interface
*/
public function setFields($value)
{
return $this->_setOption('fields', $value);
}
/**
* Get the field name(s) to get the terms from
*
* @return string
*/
public function getFields()
{
return $this->getOption('fields');
}
/**
* Set the lowerbound term to start at
*
* @param string $value
* @return self Provides fluent interface
*/
public function setLowerbound($value)
{
return $this->_setOption('lowerbound', $value);
}
/**
* Get the lowerbound term to start at
*
* @return string
*/
public function getLowerbound()
{
return $this->getOption('lowerbound');
}
/**
* Set lowerboundinclude
*
* @param boolean $value
* @return self Provides fluent interface
*/
public function setLowerboundInclude($value)
{
return $this->_setOption('lowerboundinclude', $value);
}
/**
* Get lowerboundinclude
*
* @return boolean
*/
public function getLowerboundInclude()
{
return $this->getOption('lowerboundinclude');
}
/**
* Set mincount (the minimum doc frequency for terms in order to be included)
*
* @param integer $value
* @return self Provides fluent interface
*/
public function setMinCount($value)
{
return $this->_setOption('mincount', $value);
}
/**
* Get mincount
*
* @return integer
*/
public function getMinCount()
{
return $this->getOption('mincount');
}
/**
* Set maxcount (the maximum doc frequency for terms in order to be included)
*
* @param integer $value
* @return self Provides fluent interface
*/
public function setMaxCount($value)
{
return $this->_setOption('maxcount', $value);
}
/**
* Get maxcount
*
* @return integer
*/
public function getMaxCount()
{
return $this->getOption('maxcount');
}
/**
* Set prefix for terms
*
* @param string $value
* @return self Provides fluent interface
*/
public function setPrefix($value)
{
return $this->_setOption('prefix', $value);
}
/**
* Get maxcount
*
* @return string
*/
public function getPrefix()
{
return $this->getOption('prefix');
}
/**
* Set regex to restrict terms
*
* @param string $value
* @return self Provides fluent interface
*/
public function setRegex($value)
{
return $this->_setOption('regex', $value);
}
/**
* Get regex
*
* @return string
*/
public function getRegex()
{
return $this->getOption('regex');
}
/**
* Set regex flags
*
* Use a comma-separated string for multiple entries
*
* @param string $value
* @return self Provides fluent interface
*/
public function setRegexFlags($value)
{
return $this->_setOption('regexflags', $value);
}
/**
* Get regex flags
*
* @return string
*/
public function getRegexFlags()
{
return $this->getOption('regexflags');
}
/**
* Set limit
*
* If < 0 all terms are included
*
* @param integer $value
* @return self Provides fluent interface
*/
public function setLimit($value)
{
return $this->_setOption('limit', $value);
}
/**
* Get limit
*
* @return integer
*/
public function getLimit()
{
return $this->getOption('limit');
}
/**
* Set the upperbound term to start at
*
* @param string $value
* @return self Provides fluent interface
*/
public function setUpperbound($value)
{
return $this->_setOption('upperbound', $value);
}
/**
* Get the upperbound term to start at
*
* @return string
*/
public function getUpperbound()
{
return $this->getOption('upperbound');
}
/**
* Set upperboundinclude
*
* @param boolean $value
* @return self Provides fluent interface
*/
public function setUpperboundInclude($value)
{
return $this->_setOption('upperboundinclude', $value);
}
/**
* Get upperboundinclude
*
* @return boolean
*/
public function getUpperboundInclude()
{
return $this->getOption('upperboundinclude');
}
/**
* Set raw option
*
* @param boolean $value
* @return self Provides fluent interface
*/
public function setRaw($value)
{
return $this->_setOption('raw', $value);
}
/**
* Get raw option
*
* @return boolean
*/
public function getRaw()
{
return $this->getOption('raw');
}
/**
* Set sort option
*
* @param string $value
* @return self Provides fluent interface
*/
public function setSort($value)
{
return $this->_setOption('sort', $value);
}
/**
* Get sort option
*
* @return string
*/
public function getSort()
{
return $this->getOption('sort');
}
}
\ No newline at end of file
......@@ -125,8 +125,8 @@ class Solarium_Result
/**
* Get Solr response data
*
* Included a lazy loading mechanism: JSON body data is decoded on first use and then saved for reuse.
*
* Includes a lazy loading mechanism: JSON body data is decoded on first use and then saved for reuse.
*
* @return array
*/
public function getData()
......
......@@ -269,4 +269,28 @@ class Solarium_Result_Select extends Solarium_Result_QueryType
{
return $this->getComponent(Solarium_Query_Select::COMPONENT_SPELLCHECK);
}
/**
* Get stats component result
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Result_Select_Stats
*/
public function getStats()
{
return $this->getComponent(Solarium_Query_Select::COMPONENT_STATS);
}
/**
* Get debug component result
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Result_Select_Debug
*/
public function getDebug()
{
return $this->getComponent(Solarium_Query_Select::COMPONENT_DEBUG);
}
}
\ No newline at end of file
<?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/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component debug result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_Debug implements IteratorAggregate, Countable
{
/**
* @var string
*/
protected $_queryString;
/**
* @var string
*/
protected $_parsedQuery;
/**
* @var string
*/
protected $_queryParser;
/**
* @var string
*/
protected $_otherQuery;
/**
* @var Solarium_Result_Select_Debug_DocumentSet
*/
protected $_explain;
/**
* @var Solarium_Result_Select_Debug_DocumentSet
*/
protected $_explainOther;
/**
* @var Solarium_Result_Select_Debug_Timing
*/
protected $_timing;
/**
* Constructor
*
* @param string $queryString
* @param string $parsedQuery
* @param string $queryParser
* @param string $otherQuery
* @param Solarium_Result_Select_Debug_DocumentSet $explain
* @param Solarium_Result_Select_Debug_DocumentSet $explainOther
* @param Solarium_Result_Select_Debug_Timing $timing
*/
public function __construct($queryString, $parsedQuery, $queryParser, $otherQuery, $explain, $explainOther, $timing)
{
$this->_queryString = $queryString;
$this->_parsedQuery = $parsedQuery;
$this->_queryParser = $queryParser;
$this->_otherQuery = $otherQuery;
$this->_explain = $explain;
$this->_explainOther = $explainOther;
$this->_timing = $timing;
}
/**
* Get input querystring
*
* @return string
*/
public function getQueryString()
{
return $this->_queryString;
}
/**
* Get the result of the queryparser
*
* @return string
*/
public function getParsedQuery()
{
return $this->_parsedQuery;
}
/**
* Get the used queryparser
*
* @return string
*/
public function getQueryParser()
{
return $this->_queryParser;
}
/**
* Get other query (only available if set in query)
*
* @return string
*/
public function getOtherQuery()
{
return $this->_otherQuery;
}
/**
* Get explain document set
*
* @return Solarium_Result_Select_Debug_DocumentSet
*/
public function getExplain()
{
return $this->_explain;
}
/**
* Get explain other document set (only available if otherquery was set in query)
*
* @return Solarium_Result_Select_Debug_DocumentSet
*/
public function getExplainOther()
{
return $this->_explainOther;
}
/**
* Get timing object
*
* @return Solarium_Result_Select_Debug_Timing
*/
public function getTiming()
{
return $this->_timing;
}
/**
* IteratorAggregate implementation
*
* Iterates the explain results
*
* @return Solarium_Result_Select_Debug_DocumentSet
*/
public function getIterator()
{
return $this->_explain;
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
return count($this->_explain);
}
}
\ No newline at end of file
<?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/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component debug detail result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_Debug_Detail
{
/**
* @var float
*/
protected $_value;
/**
* @var boolean
*/
protected $_match;
/**
* @var string
*/
protected $_description;
/**
* Constructor
*
* @param boolean $match
* @param float $value
* @param string $description
*/
public function __construct($match, $value, $description)
{
$this->_match = $match;
$this->_value = $value;
$this->_description = $description;
}
/**
* Get match status
*
* @return bool
*/
public function getMatch()
{
return $this->_match;
}
/**
* Get match value (score)
*
* @return float
*/
public function getValue()
{
return $this->_value;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->_description;
}
}
<?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/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component debug document result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_Debug_Document extends Solarium_Result_Select_Debug_Detail
implements IteratorAggregate, Countable
{
/**
* @var string
*/
protected $_key;
/**
* @var array
*/
protected $_details;
/**
* Constructor
*
* @param string $key
* @param boolean $match
* @param float $value
* @param string $description
*/
public function __construct($key, $match, $value, $description, $details)
{
parent::__construct($match, $value, $description);
$this->_key = $key;
$this->_details = $details;
}
/**
* Get key value for this document
*
* @return string
*/
public function getKey()
{
return $this->_key;
}
/**
* Get details
*
* @return array
*/
public function getDetails()
{
return $this->_details;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->_details);
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
return count($this->_details);
}
}
<?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/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component debug documentset result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_Debug_DocumentSet
implements IteratorAggregate, Countable
{
/**
* Docs array
*
* @var array
*/
protected $_docs;
/**
* Constructor
*
* @param array $docs
* @return void
*/
public function __construct($docs)
{
$this->_docs = $docs;
}
/**
* Get a document by key
*
* @param mixed $key
* @return Solarium_Result_Select_Debug_Document|null
*/
public function getDocument($key)
{
if (isset($this->_docs[$key])) {
return $this->_docs[$key];
} else {
return null;
}
}
/**
* Get all docs
*
* @return array
*/
public function getDocuments()
{
return $this->_docs;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->_docs);
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
return count($this->_docs);
}
}
<?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/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component debug timing result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_Debug_Timing implements IteratorAggregate, Countable
{
/**
* @var float
*/
protected $_time;
/**
* Timing phase array
*
* @var array
*/
protected $_phases;
/**
* Constructor
*
* @param float $time
* @param array $phases
* @return void
*/
public function __construct($time, $phases)
{
$this->_time = $time;
$this->_phases = $phases;
}
/**
* Get total time
*
* @return float
*/
public function getTime()
{
return $this->_time;
}
/**
* Get a timing phase by key
*
* @param mixed $key
* @return Solarium_Result_Select_Debug_TimingPhase|null
*/
public function getPhase($key)
{
if (isset($this->_phases[$key])) {
return $this->_phases[$key];
} else {
return null;
}
}
/**
* Get timings
*
* @return array
*/
public function getPhases()
{
return $this->_phases;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->_phases);
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
return count($this->_phases);
}
}
<?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/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component debug timing phase result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_Debug_TimingPhase
implements IteratorAggregate, Countable
{
/**
* @var string
*/
protected $_name;
/**
* @var float
*/
protected $_time;
/**
* Timing array
*
* @var array
*/
protected $_timings;
/**
* Constructor
*
* @param string $name
* @param float $time
* @param array $timings
* @return void
*/
public function __construct($name, $time, $timings)
{
$this->_name = $name;
$this->_time = $time;
$this->_timings = $timings;
}
/**
* Get total time
*
* @return float
*/
public function getTime()
{
return $this->_time;
}
/**
* Get a timing by key
*
* @param mixed $key
* @return float|null
*/
public function getTiming($key)
{
if (isset($this->_timings[$key])) {
return $this->_timings[$key];
} else {
return null;
}
}
/**
* Get timings
*
* @return array
*/
public function getTimings()
{
return $this->_timings;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->_timings);
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
return count($this->_timings);
}
}
<?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/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component stats result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_Stats
implements IteratorAggregate, Countable
{
/**
* Result array
*
* @var array
*/
protected $_results;
/**
* Constructor
*
* @param array $results
* @return void
*/
public function __construct($results)
{
$this->_results = $results;
}
/**
* Get a result by key
*
* @param mixed $key
* @return Solarium_Result_Select_Stats_Result|null
*/
public function getResult($key)
{
if (isset($this->_results[$key])) {
return $this->_results[$key];
} else {
return null;
}
}
/**
* Get all results
*
* @return array
*/
public function getResults()
{
return $this->_results;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->_results);
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
return count($this->_results);
}
}
<?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/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component stats facet value
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_Stats_FacetValue
{
/**
* Facet value
*
* @var string
*/
protected $_value;
/**
* Stats data
*
* @var array
*/
protected $_stats;
/**
* Constructor
*
* @param string $value
* @param array $stats
* @return void
*/
public function __construct($value, $stats)
{
$this->_value = $value;
$this->_stats = $stats;
}
/**
* Get facet value
*
* @return string
*/
public function getValue()
{
return $this->_value;
}
/**
* Get min value
*
* @return string
*/
public function getMin()
{
return $this->_stats['min'];
}
/**
* Get max value
*
* @return string
*/
public function getMax()
{
return $this->_stats['max'];
}
/**
* Get sum value
*
* @return string
*/
public function getSum()
{
return $this->_stats['sum'];
}
/**
* Get count value
*
* @return string
*/
public function getCount()
{
return $this->_stats['count'];
}
/**
* Get missing value
*
* @return string
*/
public function getMissing()
{
return $this->_stats['missing'];
}
/**
* Get sumOfSquares value
*
* @return string
*/
public function getSumOfSquares()
{
return $this->_stats['sumOfSquares'];
}
/**
* Get mean value
*
* @return string
*/
public function getMean()
{
return $this->_stats['mean'];
}
/**
* Get stddev value
*
* @return string
*/
public function getStddev()
{
return $this->_stats['stddev'];
}
/**
* Get facet stats
*
* @return array
*/
public function getFacets()
{
return $this->_stats['facets'];
}
}
<?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/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component stats field result item
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_Stats_Result
{
/**
* Field name
*
* @var string
*/
protected $_field;
/**
* Stats data
*
* @var array
*/
protected $_stats;
/**
* Constructor
*
* @param string $field
* @param array $stats
* @return void
*/
public function __construct($field, $stats)
{
$this->_field = $field;
$this->_stats = $stats;
}
/**
* Get field name
*
* @return string
*/
public function getName()
{
return $this->_field;
}
/**
* Get min value
*
* @return string
*/
public function getMin()
{
return $this->_stats['min'];
}
/**
* Get max value
*
* @return string
*/
public function getMax()
{
return $this->_stats['max'];
}
/**
* Get sum value
*
* @return string
*/
public function getSum()
{
return $this->_stats['sum'];
}
/**
* Get count value
*
* @return string
*/
public function getCount()
{
return $this->_stats['count'];
}
/**
* Get missing value
*
* @return string
*/
public function getMissing()
{
return $this->_stats['missing'];
}
/**
* Get sumOfSquares value
*
* @return string
*/
public function getSumOfSquares()
{
return $this->_stats['sumOfSquares'];
}
/**
* Get mean value
*
* @return string
*/
public function getMean()
{
return $this->_stats['mean'];
}
/**
* Get stddev value
*
* @return string
*/
public function getStddev()
{
return $this->_stats['stddev'];
}
/**
* Get facet stats
*
* @return array
*/
public function getFacets()
{
return $this->_stats['facets'];
}
}
<?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/
*
* @package Solarium
* @subpackage Result
*/
/**
* Terms query result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Terms extends Solarium_Result_QueryType implements IteratorAggregate, Countable
{
/**
* Status code returned by Solr
*
* @var int
*/
protected $_status;
/**
* Solr index queryTime
*
* This doesn't include things like the HTTP responsetime. Purely the Solr
* query execution time.
*
* @var int
*/
protected $_queryTime;
/**
* Term results
*
* @var array
*/
protected $_results;
/**
* Get Solr status code
*
* This is not the HTTP status code! The normal value for success is 0.
*
* @return int
*/
public function getStatus()
{
$this->_parseResponse();
return $this->_status;
}
/**
* Get Solr query time
*
* This doesn't include things like the HTTP responsetime. Purely the Solr
* query execution time.
*
* @return int
*/
public function getQueryTime()
{
$this->_parseResponse();
return $this->_queryTime;
}
/**
* Get all term results
*
* @return array
*/
public function getResults()
{
$this->_parseResponse();
return $this->_results;
}
/**
* Get term results for a specific field
*
* @param string $field
* @return array
*/
public function getTerms($field)
{
$this->_parseResponse();
if (isset($this->_results[$field])) {
return $this->_results[$field];
} else {
return array();
}
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public function getIterator()
{
$this->_parseResponse();
return new ArrayIterator($this->_results);
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
$this->_parseResponse();
return count($this->_results);
}
}
\ No newline at end of file
......@@ -67,10 +67,10 @@ class Solarium_Version
*
* @see checkExact()
* @see checkMinimal()
*
*
* @var string
*/
const VERSION = '2.0.0';
const VERSION = '2.3.0';
/**
......
<?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.
*/
class Solarium_Client_Adapter_CurlTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Client_Adapter_Curl
*/
protected $_adapter;
public function setUp()
{
if (!function_exists('curl_init')) {
$this->markTestSkipped('Curl not available, skipping Curl adapter tests');
}
$this->_adapter = new Solarium_Client_Adapter_Curl();
}
public function testCheck()
{
$data = 'data';
$headers = array('X-dummy: data');
// this should be ok, no exception
$this->_adapter->check($data, $headers);
$data = '';
$headers = array();
$this->setExpectedException('Solarium_Exception');
$this->_adapter->check($data, $headers);
}
public function testExecute()
{
$headers = array('HTTP/1.0 200 OK');
$body = 'data';
$data = array($body, $headers);
$request = new Solarium_Client_Request();
$mock = $this->getMock('Solarium_Client_Adapter_Curl', array('_getData'));
$mock->expects($this->once())
->method('_getData')
->with($request)
->will($this->returnValue($data));
$response = $mock->execute($request);
$this->assertEquals($body,$response->getBody());
$this->assertEquals($headers,$response->getHeaders());
}
}
\ No newline at end of file
......@@ -42,42 +42,128 @@ class Solarium_Client_Adapter_PeclHttpTest extends PHPUnit_Framework_TestCase
$this->markTestSkipped('Pecl_http not available, skipping PeclHttp adapter tests');
}
$this->_adapter = new Solarium_Client_Adapter_PeclHttp();
$this->_adapter = new Solarium_Client_Adapter_PeclHttp(array('timeout' => 10));
}
public function testCheck()
/**
* @dataProvider requestProvider
*/
public function testToHttpRequestWithMethod($request, $method, $support)
{
try {
$httpRequest = $this->_adapter->toHttpRequest($request);
$this->assertEquals($httpRequest->getMethod(), $method);
} catch (Solarium_Exception $e) {
if ($support) {
$this->fail("Unsupport method: {$request->getMethod()}");
}
}
}
public function requestProvider()
{
$data = 'data';
$headers = array('X-dummy: data');
$methods = array(
Solarium_Client_Request::METHOD_GET => array(
'method' => HTTP_METH_GET,
'support' => true
),
Solarium_Client_Request::METHOD_POST => array(
'method' => HTTP_METH_POST,
'support' => true
),
Solarium_Client_Request::METHOD_HEAD => array(
'method' => HTTP_METH_HEAD,
'support' => true
),
'PUT' => array(
'method' => HTTP_METH_PUT,
'support' => false
),
'DELETE' => array(
'method' => HTTP_METH_DELETE,
'support' => false
),
);
// this should be ok, no exception
$this->_adapter->check($data, $headers);
foreach ($methods as $method => $options) {
$request = new Solarium_Client_Request;
$request->setMethod($method);
$data[] = array_merge(array($request), $options);
}
$data = '';
$headers = array();
return $data;
}
public function testToHttpRequestWithHeaders()
{
$request = new Solarium_Client_Request(array(
'header' => array(
'Content-Type: application/json',
'User-Agent: Foo'
)
));
$this->setExpectedException('Solarium_Exception');
$this->_adapter->check($data, $headers);
$httpRequest = $this->_adapter->toHttpRequest($request);
$this->assertEquals(array(
'timeout' => 10,
'headers' => array(
'Content-Type' => 'application/json',
'User-Agent' => 'Foo'
)
), $httpRequest->getOptions());
}
public function testToHttpRequestWithDefaultContentType()
{
$request = new Solarium_Client_Request;
$request->setMethod(Solarium_Client_Request::METHOD_POST);
$httpRequest = $this->_adapter->toHttpRequest($request);
$this->assertEquals(array(
'timeout' => 10,
'headers' => array(
'Content-Type' => 'text/xml; charset=utf-8',
)
), $httpRequest->getOptions());
}
public function testExecute()
{
$headers = array('HTTP/1.0 200 OK');
$statusCode = 200;
$statusMessage = 'OK';
$body = 'data';
$data = array($body, $headers);
$data = <<<EOF
HTTP/1.1 $statusCode $statusMessage
X-Foo: test
$body
EOF;
$request = new Solarium_Client_Request();
$mock = $this->getMock('Solarium_Client_Adapter_PeclHttp', array('_getData'));
$mockHttpRequest = $this->getMock('HttpRequest');
$mockHttpRequest->expects($this->once())
->method('send')
->will($this->returnValue(HttpMessage::factory($data)));
$mock = $this->getMock('Solarium_Client_Adapter_PeclHttp', array('toHttpRequest'));
$mock->expects($this->once())
->method('_getData')
->with($request)
->will($this->returnValue($data));
->method('toHttpRequest')
->with($request)
->will($this->returnValue($mockHttpRequest));
$response = $mock->execute($request);
$this->assertEquals($body, $response->getBody());
$this->assertEquals($statusCode, $response->getStatusCode());
$this->assertEquals($statusMessage, $response->getStatusMessage());
}
$this->assertEquals($body,$response->getBody());
$this->assertEquals($headers,$response->getHeaders());
/**
* @expectedException Solarium_Client_HttpException
*/
public function testExecuteWithException()
{
$this->_adapter->setPort(-1); // this forces an error
$request = new Solarium_Client_Request();
$this->_adapter->execute($request);
}
}
\ No newline at end of file
}
......@@ -63,7 +63,7 @@ class Solarium_Client_RequestBuilder_AnalysisTest extends PHPUnit_Framework_Test
array(
'wt' => 'json',
'analysis.query' => $query,
'analysis.showmatch' => $showMatch,
'analysis.showmatch' => 'true',
),
$request->getParams()
);
......@@ -72,4 +72,4 @@ class Solarium_Client_RequestBuilder_AnalysisTest extends PHPUnit_Framework_Test
}
}
\ No newline at end of file
}
......@@ -38,14 +38,14 @@ class Solarium_Client_RequestBuilder_PingTest extends PHPUnit_Framework_TestCase
$request = $builder->build(new Solarium_Query_Ping);
$this->assertEquals(
'admin/ping?',
'admin/ping?wt=json',
$request->getUri()
);
$this->assertEquals(
Solarium_Client_Request::METHOD_HEAD,
Solarium_Client_Request::METHOD_GET,
$request->getMethod()
);
}
}
\ No newline at end of file
}
<?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.
*/
class Solarium_Client_RequestBuilder_Select_Component_DebugTest extends PHPUnit_Framework_TestCase
{
public function testBuild()
{
$builder = new Solarium_Client_RequestBuilder_Select_Component_Debug();
$request = new Solarium_Client_Request();
$component = new Solarium_Query_Select_Component_Debug();
$component->setExplainOther('id:45');
$request = $builder->build($component, $request);
$this->assertEquals(
array(
'debugQuery' => true,
'debug.explain.structured' => true,
'explainOther' => 'id:45',
),
$request->getParams()
);
}
}
\ No newline at end of file
......@@ -46,6 +46,7 @@ class Solarium_Client_RequestBuilder_Select_Component_GroupingTest extends PHPUn
$component->setMainResult(true);
$component->setNumberOfGroups(false);
$component->setCachePercentage(50);
$component->setTruncate(true);
$request = $builder->build($component, $request);
......@@ -60,6 +61,7 @@ class Solarium_Client_RequestBuilder_Select_Component_GroupingTest extends PHPUn
'group.main' => 'true',
'group.ngroups' => 'false',
'group.cache.percent' => 50,
'group.truncate' => 'true',
),
$request->getParams()
);
......
......@@ -53,7 +53,7 @@ class Solarium_Client_RequestBuilder_Select_Component_MoreLikeThisTest extends P
$this->assertEquals(
array(
'mlt' => true,
'mlt' => 'true',
'mlt.fl' => 'description,name',
'mlt.mintf' => 1,
'mlt.mindf' => 3,
......@@ -61,7 +61,7 @@ class Solarium_Client_RequestBuilder_Select_Component_MoreLikeThisTest extends P
'mlt.maxwl' => 15,
'mlt.maxqt' => 4,
'mlt.maxntp' => 5,
'mlt.boost' => true,
'mlt.boost' => 'true',
'mlt.qf' => 'description',
'mlt.count' => 6,
),
......@@ -70,4 +70,4 @@ class Solarium_Client_RequestBuilder_Select_Component_MoreLikeThisTest extends P
}
}
\ No newline at end of file
}
<?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.
*/
class Solarium_Client_RequestBuilder_Select_Component_StatsTest extends PHPUnit_Framework_TestCase
{
public function testBuild()
{
$builder = new Solarium_Client_RequestBuilder_Select_Component_Stats();
$request = new Solarium_Client_Request();
$component = new Solarium_Query_Select_Component_Stats();
$component->createField('fieldA')->addFacet('fieldFacetA');
$component->createField('fieldB');
$component->addFacets(array('facetA', 'facetB'));
$request = $builder->build($component, $request);
$this->assertEquals(
array(
'stats' => 'true',
'stats.facet' => array(
'facetA',
'facetB',
),
'stats.field' => array(
'fieldA',
'fieldB',
),
'f.fieldA.stats.facet' => 'fieldFacetA',
),
$request->getParams()
);
}
}
......@@ -89,6 +89,23 @@ class Solarium_Client_RequestBuilder_SelectTest extends PHPUnit_Framework_TestCa
);
}
public function testSelectUrlWithQueryDefaultFieldAndOperator()
{
$this->_query->setQueryDefaultField('mydefault');
$this->_query->setQueryDefaultOperator(Solarium_Query_Select::QUERY_OPERATOR_AND);
$request = $this->_builder->build($this->_query);
$this->assertEquals(
null,
$request->getRawData()
);
$this->assertEquals(
'select?q=*:*&start=0&rows=10&fl=*,score&wt=json&q.op=AND&df=mydefault',
urldecode($request->getUri())
);
}
public function testSelectUrlWithSortAndFilters()
{
$this->_query->addSort('id', Solarium_Query_Select::SORT_ASC);
......
<?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.
*/
class Solarium_Client_RequestBuilder_TermsTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Terms
*/
protected $_query;
/**
* @var Solarium_Client_RequestBuilder_Terms
*/
protected $_builder;
public function setUp()
{
$this->_query = new Solarium_Query_Terms;
$this->_builder = new Solarium_Client_RequestBuilder_Terms;
}
public function testBuildParams()
{
$this->_query->setFields('fieldA, fieldB');
$this->_query->setLowerbound('d');
$this->_query->setLowerboundInclude(true);
$this->_query->setMinCount(3);
$this->_query->setMaxCount(100);
$this->_query->setPrefix('de');
$this->_query->setRegex('det.*');
$this->_query->setRegexFlags('case_insensitive,comments');
$this->_query->setLimit(50);
$this->_query->setUpperbound('x');
$this->_query->setUpperboundInclude(false);
$this->_query->setRaw(false);
$this->_query->setSort('index');
$request = $this->_builder->build($this->_query);
$this->assertEquals(
array(
'terms' => 'true',
'terms.fl' => array(
'fieldA',
'fieldB',
),
'terms.limit' => 50,
'terms.lower' => 'd',
'terms.lower.incl' => 'true',
'terms.maxcount' => 100,
'terms.mincount' => 3,
'terms.prefix' => 'de',
'terms.raw' => 'false',
'terms.regex' => 'det.*',
'terms.regex.flag' => array(
'case_insensitive',
'comments',
),
'terms.sort' => 'index',
'terms.upper' => 'x',
'terms.upper.incl' => 'false',
'wt' => 'json',
),
$request->getParams()
);
$this->assertEquals(
Solarium_Client_Request::METHOD_GET,
$request->getMethod()
);
}
}
\ No newline at end of file
......@@ -212,17 +212,23 @@ class Solarium_Client_RequestTest extends PHPUnit_Framework_TestCase
{
$params = array(
'param1' => 1,
'param2' => 2,
'param3' => 3,
);
$this->_request->setParams($params);
$this->_request->addParam('param2', 2);
$this->_request->addParam('param2', '');
$this->_request->addParam('param3', '');
$params['param2'] = 2;
$this->_request->addParam('param2', ''); // this should add an empty value to param2
$this->_request->addParam('param3', '' , true); // this should overwrite param2 with an empty value
$this->_request->addParam('param4', ''); // this should add an empty param (for instance "q=" in dismax)
$this->_request->addParam('param5', null); // this param should be ignored
$this->assertEquals(
$params,
array(
'param1' => 1,
'param2' => array(2,''),
'param3' => '',
'param4' => '',
),
$this->_request->getParams()
);
}
......
<?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.
*/
class Solarium_Client_ResponseParser_Select_Component_DebugTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Client_ResponseParser_Select_Component_Debug
*/
protected $_parser;
public function setUp()
{
$this->_parser = new Solarium_Client_ResponseParser_Select_Component_Debug();
}
public function testParse()
{
$data = array(
'debug' => array(
'querystring' => 'dummy-qs',
'parsedquery' => 'dummy-pq',
'QParser' => 'dummy-qp',
'otherQuery' => 'dummy-oq',
'explain' => array(
'MA147LL/A' => array(
'match' => true,
'value' => 0.5,
'description' => 'fieldWeight(text:ipod in 5), product of:',
'details' => array(
array(
'match' => true,
'value' => 0.5,
'description' => 'tf(termFreq(text:ipod)=1)',
)
),
),
),
'explainOther' => array(
'IW-02' => array(
'match' => true,
'value' => 0.6,
'description' => 'fieldWeight(text:ipod in 6), product of:',
'details' => array(
array(
'match' => true,
'value' => 0.7,
'description' => 'tf(termFreq(text:ipod)=1)',
)
),
),
),
'timing' => array(
'time' => 36,
'prepare' => array(
'time' => 12,
'org.apache.solr.handler.component.QueryComponent' => array(
'time' => 1,
),
'org.apache.solr.handler.component.FacetComponent' => array(
'time' => 11,
),
),
'process' => array(
'time' => 8,
'org.apache.solr.handler.component.QueryComponent' => array(
'time' => 5,
),
'org.apache.solr.handler.component.MoreLikeThisComponent' => array(
'time' => 3,
),
)
)
)
);
$result = $this->_parser->parse(null, null, $data);
$this->assertEquals('dummy-qs', $result->getQueryString());
$this->assertEquals('dummy-pq', $result->getParsedQuery());
$this->assertEquals('dummy-qp', $result->getQueryParser());
$this->assertEquals('dummy-oq', $result->getOtherQuery());
$this->assertEquals(1, count($result->getExplain()));
$doc = $result->getExplain()->getDocument('MA147LL/A');
$this->assertEquals(0.5, $doc->getValue());
$this->assertEquals(true, $doc->getMatch());
$this->assertEquals('fieldWeight(text:ipod in 5), product of:', $doc->getDescription());
$this->assertEquals(
array(new Solarium_Result_Select_Debug_Detail(true, 0.5, 'tf(termFreq(text:ipod)=1)')),
$doc->getDetails()
);
$this->assertEquals(1, count($result->getExplainOther()));
$doc = $result->getExplainOther()->getDocument('IW-02');
$this->assertEquals(0.6, $doc->getValue());
$this->assertEquals(true, $doc->getMatch());
$this->assertEquals('fieldWeight(text:ipod in 6), product of:', $doc->getDescription());
$this->assertEquals(
array(new Solarium_Result_Select_Debug_Detail(true, 0.7, 'tf(termFreq(text:ipod)=1)')),
$doc->getDetails()
);
$timing = $result->getTiming();
$this->assertEquals(36, $timing->getTime());
$this->assertEquals(2, count($timing->getPhases()));
$phase = $timing->getPhase('process');
$this->assertEquals(8, $phase->getTime());
$this->assertEquals(2, count($phase->getTimings()));
$this->assertEquals(5, $phase->getTiming('org.apache.solr.handler.component.QueryComponent'));
$this->assertEquals(3, $phase->getTiming('org.apache.solr.handler.component.MoreLikeThisComponent'));
}
public function testParseNoExplainData()
{
$data = array(
'debug' => array(
'querystring' => 'dummy-qs',
'parsedquery' => 'dummy-pq',
'QParser' => 'dummy-qp',
'otherQuery' => 'dummy-oq',
)
);
$result = $this->_parser->parse(null, null, $data);
$this->assertEquals('dummy-qs', $result->getQueryString());
$this->assertEquals('dummy-pq', $result->getParsedQuery());
$this->assertEquals('dummy-qp', $result->getQueryParser());
$this->assertEquals('dummy-oq', $result->getOtherQuery());
$this->assertEquals(0, count($result->getExplain()));
$this->assertEquals(0, count($result->getExplainOther()));
}
public function testParseNoData()
{
$result = $this->_parser->parse(null, null, array());
$this->assertEquals(null, $result);
}
}
......@@ -68,9 +68,12 @@ class Solarium_Client_ResponseParser_Select_Component_FacetSetTest extends PHPUn
'after' => 5,
'between' => 4,
'counts' => array(
'1.0' => 1,
'101.0' => 2,
'201.0' => 1,
'1.0',
1,
'101.0',
2,
'201.0',
1,
)
)
)
......@@ -136,7 +139,7 @@ class Solarium_Client_ResponseParser_Select_Component_FacetSetTest extends PHPUn
$this->_facetSet->addFacet($facetStub);
$this->setExpectedException('Solarium_Exception');
$this->setExpectedException('Solarium_Exception');
$this->_parser->parse(null, $this->_facetSet, array());
}
......
<?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.
*/
class Solarium_Client_ResponseParser_Select_Component_StatsTest extends PHPUnit_Framework_TestCase
{
protected $_parser;
public function setUp()
{
$this->_parser = new Solarium_Client_ResponseParser_Select_Component_Stats();
}
public function testParse()
{
$data = array(
'stats' => array(
'stats_fields' => array(
'fieldA' => array(
'min' => 3,
),
'fieldB' => array(
'min' => 4,
'facets' => array(
'fieldC' => array(
'value1' => array(
'min' => 5,
)
)
)
)
)
)
);
$result = $this->_parser->parse(null, null, $data);
$this->assertEquals(3, $result->getResult('fieldA')->getMin());
$this->assertEquals(4, $result->getResult('fieldB')->getMin());
$facets = $result->getResult('fieldB')->getFacets();
$this->assertEquals(5, $facets['fieldC']['value1']->getMin());
}
public function testParseNoData()
{
$result = $this->_parser->parse(null, null, array());
$this->assertEquals(0, count($result));
}
}
<?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.
*/
class Solarium_Client_ResponseParser_TermsTest extends PHPUnit_Framework_TestCase
{
public function testParse()
{
$data = array(
'responseHeader' => array(
'status' => 1,
'QTime' => 13,
),
'terms' => array(
'fieldA' => array(
'term1',
5,
'term2',
3
),
'fieldB' => array(
'term3',
6,
'term4',
2
)
),
);
$query = new Solarium_Query_Terms();
$query->setFields('fieldA, fieldB');
$resultStub = $this->getMock('Solarium_Result_Terms', array(), array(), '', false);
$resultStub->expects($this->any())
->method('getData')
->will($this->returnValue($data));
$resultStub->expects($this->any())
->method('getQuery')
->will($this->returnValue($query));
$parser = new Solarium_Client_ResponseParser_Terms;
$result = $parser->parse($resultStub);
$expected = array(
'fieldA' => array(
'term1' => 5,
'term2' => 3,
),
'fieldB' => array(
'term3' => 6,
'term4' => 2,
)
);
$this->assertEquals($expected, $result['results']);
$this->assertEquals(2, count($result['results']));
}
}
......@@ -85,7 +85,7 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
$plugin = $this->_client->getPlugin('myplugin');
$this->assertThat($plugin, $this->isInstanceOf('MyClientPlugin'));
$this->assertEquals($options['plugin']['myplugin']['options'], $plugin->getOptions());
}
public function testConfigModeWithoutKeys()
......@@ -151,7 +151,7 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
$this->_client->setAdapter($adapterClass);
$this->assertThat($this->_client->getAdapter(), $this->isInstanceOf($adapterClass));
}
public function testSetAndGetAdapterWithObject()
{
$adapterClass = 'MyAdapter';
......@@ -205,10 +205,25 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
{
$this->assertEquals(
null,
$this->_client->getPlugin('invalidplugin')
$this->_client->getPlugin('invalidplugin', false)
);
}
public function testAutoloadPlugin()
{
$loadbalancer = $this->_client->getPlugin('loadbalancer');
$this->assertThat(
$loadbalancer,
$this->isInstanceOf('Solarium_Plugin_Loadbalancer')
);
}
public function testAutoloadInvalidPlugin()
{
$this->setExpectedException('Solarium_Exception');
$this->_client->getPlugin('invalidpluginname');
}
public function testRemoveAndGetPlugins()
{
$options = array('option1' => 1);
......@@ -469,7 +484,7 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
public function testExecuteWithOverridingPlugin()
{
$query = new Solarium_Query_Ping();
$observer = $this->getMock('Solarium_Plugin_Abstract', array(), array($this->_client,array()));
$observer->expects($this->once())
->method('preExecute')
......@@ -629,6 +644,18 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
$observer->analyze($query);
}
public function testTerms()
{
$query = new Solarium_Query_Terms();
$observer = $this->getMock('Solarium_Client', array('execute'));
$observer->expects($this->once())
->method('execute')
->with($this->equalTo($query));
$observer->terms($query);
}
public function testCreateQuery()
{
$options = array('optionA' => 1, 'optionB' => 2);
......@@ -747,8 +774,8 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
->with($this->equalTo(Solarium_Client::QUERYTYPE_MORELIKETHIS), $this->equalTo($options));
$observer->createMoreLikeThis($options);
}
}
public function testCreateAnalysisField()
{
$options = array('optionA' => 1, 'optionB' => 2);
......@@ -773,6 +800,32 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
$observer->createAnalysisDocument($options);
}
public function testCreateTerms()
{
$options = array('optionA' => 1, 'optionB' => 2);
$observer = $this->getMock('Solarium_Client', array('createQuery'));
$observer->expects($this->once())
->method('createQuery')
->with($this->equalTo(Solarium_Client::QUERYTYPE_TERMS), $this->equalTo($options));
$observer->createTerms($options);
}
public function testTriggerEvent()
{
$eventName = 'Test';
$params = array('a', 'b');
$override = true;
$clientMock = $this->getMock('Solarium_Client', array('_callPlugins'));
$clientMock->expects($this->once())
->method('_callPlugins')
->with($this->equalTo('event'.$eventName), $this->equalTo($params), $override);
$clientMock->triggerEvent($eventName, $params, $override);
}
}
class MyAdapter extends Solarium_Client_Adapter_Http{
......
<?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.
*/
class Solarium_Plugin_CustomizeRequest_CustomizationTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Plugin_CustomizeRequest_Customization
*/
protected $_instance;
public function setUp()
{
$this->_instance = new Solarium_Plugin_CustomizeRequest_Customization();
}
public function testSetAndGetKey()
{
$value = 'mykey';
$this->_instance->setKey($value);
$this->assertEquals($value, $this->_instance->getKey());
}
public function testSetAndGetName()
{
$value = 'myname';
$this->_instance->setName($value);
$this->assertEquals($value, $this->_instance->getName());
}
public function testSetAndGetType()
{
$value = 'mytype';
$this->_instance->setType($value);
$this->assertEquals($value, $this->_instance->getType());
}
public function testSetAndGetValue()
{
$value = 'myvalue';
$this->_instance->setValue($value);
$this->assertEquals($value, $this->_instance->getValue());
}
public function testSetAndGetPersistence()
{
$value = true;
$this->_instance->setPersistent($value);
$this->assertEquals($value, $this->_instance->getPersistent());
}
public function testSetAndGetOverwrite()
{
$value = false;
$this->_instance->setOverwrite($value);
$this->assertEquals($value, $this->_instance->getOverwrite());
}
public function testIsValid()
{
$this->_instance->setKey('mykey');
$this->_instance->setType('param');
$this->_instance->setName('myname');
$this->_instance->setValue('myvalue');
$this->assertTrue($this->_instance->isValid());
}
public function testIsValidWithInvalidType()
{
$this->_instance->setKey('mykey');
$this->_instance->setType('mytype');
$this->_instance->setName('myname');
$this->_instance->setValue('myvalue');
$this->assertFalse($this->_instance->isValid());
}
public function testIsValidWithMissingValue()
{
$this->_instance->setKey('mykey');
$this->_instance->setType('param');
$this->_instance->setName('myname');
$this->assertFalse($this->_instance->isValid());
}
}
\ No newline at end of file
<?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.
*/
class Solarium_Plugin_CustomizeRequestTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Plugin_CustomizeRequest
*/
protected $_plugin;
public function setUp()
{
$this->_plugin = new Solarium_Plugin_CustomizeRequest();
}
public function testConfigMode()
{
$options = array(
'customization' => array(
array(
'key' => 'auth',
'type' => 'header',
'name' => 'X-my-auth',
'value' => 'mypassword',
'persistent' => true
),
'id' => array(
'type' => 'param',
'name' => 'id',
'value' => '1234',
'persistent' => false,
'overwrite' => false,
),
)
);
$this->_plugin->setOptions($options);
$auth = $this->_plugin->getCustomization('auth');
$id = $this->_plugin->getCustomization('id');
$this->assertThat($auth, $this->isInstanceOf('Solarium_Plugin_CustomizeRequest_Customization'));
$this->assertEquals('auth', $auth->getKey());
$this->assertEquals('header', $auth->getType());
$this->assertEquals('X-my-auth', $auth->getName());
$this->assertEquals('mypassword', $auth->getValue());
$this->assertEquals(true, $auth->getPersistent());
$this->assertThat($id, $this->isInstanceOf('Solarium_Plugin_CustomizeRequest_Customization'));
$this->assertEquals('id', $id->getKey());
$this->assertEquals('param', $id->getType());
$this->assertEquals('id', $id->getName());
$this->assertEquals('1234', $id->getValue());
$this->assertEquals(false, $id->getPersistent());
$this->assertEquals(false, $id->getOverwrite());
}
public function testCreateCustomization()
{
$customization = $this->_plugin->createCustomization('id1');
$this->assertEquals(
$customization,
$this->_plugin->getCustomization('id1')
);
}
public function testCreateCustomizationWithArray()
{
$input = array(
'key' => 'auth',
'type' => 'header',
'name' => 'X-my-auth',
'value' => 'mypassword',
'persistent' => true
);
$customization = $this->_plugin->createCustomization($input);
$this->assertEquals($customization, $this->_plugin->getCustomization('auth'));
$this->assertEquals($input['key'], $customization->getKey());
$this->assertEquals($input['type'], $customization->getType());
$this->assertEquals($input['name'], $customization->getName());
$this->assertEquals($input['value'], $customization->getValue());
$this->assertEquals($input['persistent'], $customization->getPersistent());
}
public function testAddAndGetCustomization()
{
$customization = new Solarium_Plugin_CustomizeRequest_Customization;
$customization->setKey('id1');
$this->_plugin->addCustomization($customization);
$this->assertEquals(
$customization,
$this->_plugin->getCustomization('id1')
);
}
public function testAddAndGetCustomizationWithKey()
{
$key = 'id1';
$customization = $this->_plugin->createCustomization($key);
$this->assertEquals(
$key,
$customization->getKey()
);
$this->assertEquals(
$customization,
$this->_plugin->getCustomization($key)
);
}
public function testAddCustomizationWithoutKey()
{
$customization = new Solarium_Plugin_CustomizeRequest_Customization;;
$this->setExpectedException('Solarium_Exception');
$this->_plugin->addCustomization($customization);
}
public function testAddCustomizationWithUsedKey()
{
$customization1 = new Solarium_Plugin_CustomizeRequest_Customization;
$customization1->setKey('id1')->setName('test1');
$customization2 = new Solarium_Plugin_CustomizeRequest_Customization;
$customization2->setKey('id1')->setName('test2');
$this->_plugin->addCustomization($customization1);
$this->setExpectedException('Solarium_Exception');
$this->_plugin->addCustomization($customization2);
}
public function testAddDuplicateCustomizationWith()
{
$customization = new Solarium_Plugin_CustomizeRequest_Customization;
$customization->setKey('id1')->setName('test1');
$this->_plugin->addCustomization($customization);
$this->_plugin->addCustomization($customization);
$this->assertEquals(
$customization,
$this->_plugin->getCustomization('id1')
);
}
public function testGetInvalidCustomization()
{
$this->assertEquals(
null,
$this->_plugin->getCustomization('invalidkey')
);
}
public function testAddCustomizations()
{
$customization1 = new Solarium_Plugin_CustomizeRequest_Customization;
$customization1->setKey('id1')->setName('test1');
$customization2 = new Solarium_Plugin_CustomizeRequest_Customization;
$customization2->setKey('id2')->setName('test2');
$customizations = array('id1' => $customization1, 'id2' => $customization2);
$this->_plugin->addCustomizations($customizations);
$this->assertEquals(
$customizations,
$this->_plugin->getCustomizations()
);
}
public function testRemoveCustomization()
{
$customization1 = new Solarium_Plugin_CustomizeRequest_Customization;
$customization1->setKey('id1')->setName('test1');
$customization2 = new Solarium_Plugin_CustomizeRequest_Customization;
$customization2->setKey('id2')->setName('test2');
$customizations = array($customization1, $customization2);
$this->_plugin->addCustomizations($customizations);
$this->_plugin->removeCustomization('id1');
$this->assertEquals(
array('id2' => $customization2),
$this->_plugin->getCustomizations()
);
}
public function testRemoveCustomizationWithObjectInput()
{
$customization1 = new Solarium_Plugin_CustomizeRequest_Customization;
$customization1->setKey('id1')->setName('test1');
$customization2 = new Solarium_Plugin_CustomizeRequest_Customization;
$customization2->setKey('id2')->setName('test2');
$customizations = array($customization1, $customization2);
$this->_plugin->addCustomizations($customizations);
$this->_plugin->removeCustomization($customization1);
$this->assertEquals(
array('id2' => $customization2),
$this->_plugin->getCustomizations()
);
}
public function testRemoveInvalidCustomization()
{
$customization1 = new Solarium_Plugin_CustomizeRequest_Customization;
$customization1->setKey('id1')->setName('test1');
$customization2 = new Solarium_Plugin_CustomizeRequest_Customization;
$customization2->setKey('id2')->setName('test2');
$customizations = array('id1' => $customization1, 'id2' => $customization2);
$this->_plugin->addCustomizations($customizations);
$this->_plugin->removeCustomization('id3'); //continue silently
$this->assertEquals(
$customizations,
$this->_plugin->getCustomizations()
);
}
public function testClearCustomizations()
{
$customization1 = new Solarium_Plugin_CustomizeRequest_Customization;
$customization1->setKey('id1')->setName('test1');
$customization2 = new Solarium_Plugin_CustomizeRequest_Customization;
$customization2->setKey('id2')->setName('test2');
$customizations = array($customization1, $customization2);
$this->_plugin->addCustomizations($customizations);
$this->_plugin->clearCustomizations();
$this->assertEquals(
array(),
$this->_plugin->getCustomizations()
);
}
public function testSetCustomizations()
{
$customization1 = new Solarium_Plugin_CustomizeRequest_Customization;
$customization1->setKey('id1')->setName('test1');
$customization2 = new Solarium_Plugin_CustomizeRequest_Customization;
$customization2->setKey('id2')->setName('test2');
$customizations1 = array('id1' => $customization1, 'id2' => $customization2);
$this->_plugin->addCustomizations($customizations1);
$customization3 = new Solarium_Plugin_CustomizeRequest_Customization;
$customization3->setKey('id3')->setName('test3');
$customization4 = new Solarium_Plugin_CustomizeRequest_Customization;
$customization4->setKey('id4')->setName('test4');
$customizations2 = array('id3' => $customization3, 'id4' => $customization4);
$this->_plugin->setCustomizations($customizations2);
$this->assertEquals(
$customizations2,
$this->_plugin->getCustomizations()
);
}
public function testPostCreateRequestWithHeaderAndParam()
{
$input = array(
'key' => 'xid',
'type' => 'param',
'name' => 'xid',
'value' => 123,
);
$this->_plugin->addCustomization($input);
$input = array(
'key' => 'auth',
'type' => 'header',
'name' => 'X-my-auth',
'value' => 'mypassword',
'persistent' => true
);
$this->_plugin->addCustomization($input);
$request = new Solarium_Client_Request();
$this->_plugin->postCreateRequest(null, $request);
$this->assertEquals(
123,
$request->getParam('xid')
);
$this->assertEquals(
array('X-my-auth: mypassword'),
$request->getHeaders()
);
}
public function testPostCreateRequestWithInvalidCustomization()
{
$input = array(
'key' => 'xid',
'type' => 'invalid',
'name' => 'xid',
'value' => 123,
);
$this->_plugin->addCustomization($input);
$request = new Solarium_Client_Request();
$this->setExpectedException('Solarium_Exception');
$this->_plugin->postCreateRequest(null, $request);
}
public function testPostCreateRequestWithoutCustomizations()
{
$request = new Solarium_Client_Request();
$originalRequest = clone $request;
$this->_plugin->postCreateRequest(null, $request);
$this->assertEquals(
$originalRequest,
$request
);
}
public function testPostCreateRequestWithPersistentAndNonPersistentCustomizations()
{
$input = array(
'key' => 'xid',
'type' => 'param',
'name' => 'xid',
'value' => 123,
);
$this->_plugin->addCustomization($input);
$input = array(
'key' => 'auth',
'type' => 'header',
'name' => 'X-my-auth',
'value' => 'mypassword',
'persistent' => true
);
$this->_plugin->addCustomization($input);
$request = new Solarium_Client_Request();
$this->_plugin->postCreateRequest(null, $request);
$this->assertEquals(
123,
$request->getParam('xid')
);
$this->assertEquals(
array('X-my-auth: mypassword'),
$request->getHeaders()
);
// second use, only the header should be persistent
$request = new Solarium_Client_Request();
$this->_plugin->postCreateRequest(null, $request);
$this->assertEquals(
null,
$request->getParam('xid')
);
$this->assertEquals(
array('X-my-auth: mypassword'),
$request->getHeaders()
);
}
}
\ No newline at end of file
<?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.
*/
class Solarium_Plugin_Loadbalancer_WeightedRandomChoiceTest extends PHPUnit_Framework_TestCase
{
public function testGetRandom()
{
$choices = array('key1' => 1, 'key2' => 2, 'key3' => 3);
$randomizer = new Solarium_Plugin_Loadbalancer_WeightedRandomChoice($choices);
$choice = $randomizer->getRandom();
$this->assertTrue(
array_key_exists($choice, $choices)
);
$counts = array('key1' => 0, 'key2' => 0, 'key3' => 0);
for ($i = 0; $i<1000; $i++) {
$choice = $randomizer->getRandom();
$counts[$choice]++;
}
$this->assertTrue($counts['key1'] < $counts['key2']);
$this->assertTrue($counts['key2'] < $counts['key3']);
}
public function testGetRandomWithExclude()
{
$choices = array('key1' => 1, 'key2' => 1, 'key3' => 300);
$excludes = array('key3');
$randomizer = new Solarium_Plugin_Loadbalancer_WeightedRandomChoice($choices);
$key = $randomizer->getRandom($excludes);
$this->assertTrue($key !== 'key3');
}
public function testAllEntriesExcluded()
{
$choices = array('key1' => 1, 'key2' => 2, 'key3' => 3);
$excludes = array_keys($choices);
$randomizer = new Solarium_Plugin_Loadbalancer_WeightedRandomChoice($choices);
$this->setExpectedException('Solarium_Exception');
$randomizer->getRandom($excludes);
}
}
\ No newline at end of file
<?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.
*/
class Solarium_Plugin_LoadbalancerTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Plugin_Loadbalancer
*/
protected $_plugin;
/**
* @var Solarium_Client
*/
protected $_client;
protected $_serverOptions = array('host' => 'nonexistinghostname');
public function setUp()
{
$this->_plugin = new Solarium_Plugin_Loadbalancer();
$this->_client = new Solarium_Client();
$adapter = $this->getMock('Solarium_Client_Adapter_Http');
$adapter->expects($this->any())
->method('execute')
->will($this->returnValue('dummyresult'));
$this->_client->setAdapter($adapter);
$this->_plugin->init($this->_client, array());
}
public function testConfigMode()
{
$options = array(
'server' => array(
'server1' => array(
'options' => array(
'host' => 'host1'
),
'weight' => 10,
),
'server2' => array(
'options' => array(
'host' => 'host2'
),
'weight' => 5,
),
),
'blockedquerytype' => array(Solarium_Client::QUERYTYPE_UPDATE, Solarium_Client::QUERYTYPE_MORELIKETHIS)
);
$this->_plugin->setOptions($options);
$this->assertEquals(
array(
'server1' => array(
'options' => array('host' => 'host1'),
'weight' => 10,
),
'server2' => array(
'options' => array('host' => 'host2'),
'weight' => 5,
)
),
$this->_plugin->getServers()
);
$this->assertEquals(
array(Solarium_Client::QUERYTYPE_UPDATE, Solarium_Client::QUERYTYPE_MORELIKETHIS),
$this->_plugin->getBlockedQueryTypes()
);
}
public function testSetAndGetFailoverEnabled()
{
$this->_plugin->setFailoverEnabled(true);
$this->assertEquals(true, $this->_plugin->getFailoverEnabled());
}
public function testSetAndGetFailoverMaxRetries()
{
$this->_plugin->setFailoverMaxRetries(16);
$this->assertEquals(16, $this->_plugin->getFailoverMaxRetries());
}
public function testAddServer()
{
$this->_plugin->addServer('s1', $this->_serverOptions, 10);
$this->assertEquals(
array('s1' =>
array(
'options' => $this->_serverOptions,
'weight' => 10,
)
),
$this->_plugin->getServers()
);
}
public function testAddServerWithDuplicateKey()
{
$this->_plugin->addServer('s1', $this->_serverOptions, 10);
$this->setExpectedException('Solarium_Exception');
$this->_plugin->addServer('s1', $this->_serverOptions, 20);
}
public function testGetServer()
{
$this->_plugin->addServer('s1', $this->_serverOptions, 10);
$this->assertEquals(
array('options' => $this->_serverOptions, 'weight' => 10),
$this->_plugin->getServer('s1')
);
}
public function testGetInvalidServer()
{
$this->_plugin->addServer('s1', $this->_serverOptions, 10);
$this->setExpectedException('Solarium_Exception');
$this->_plugin->getServer('s2');
}
public function testClearServers()
{
$this->_plugin->addServer('s1', $this->_serverOptions, 10);
$this->_plugin->clearServers();
$this->assertEquals(array(), $this->_plugin->getServers());
}
public function testAddServers()
{
$servers = array(
's1' => array('options' => $this->_serverOptions, 'weight' => 10),
's2' => array('options' => $this->_serverOptions, 'weight' => 20),
);
$this->_plugin->addServers($servers);
$this->assertEquals($servers, $this->_plugin->getServers());
}
public function testRemoveServer()
{
$servers = array(
's1' => array('options' => $this->_serverOptions, 'weight' => 10),
's2' => array('options' => $this->_serverOptions, 'weight' => 20),
);
$this->_plugin->addServers($servers);
$this->_plugin->removeServer('s1');
$this->assertEquals(
array('s2' => array('options' => $this->_serverOptions, 'weight' => 20)),
$this->_plugin->getServers()
);
}
public function testSetServers()
{
$servers1 = array(
's1' => array('options' => $this->_serverOptions, 'weight' => 10),
's2' => array('options' => $this->_serverOptions, 'weight' => 20),
);
$servers2 = array(
's3' => array('options' => $this->_serverOptions, 'weight' => 50),
's4' => array('options' => $this->_serverOptions, 'weight' => 30),
);
$this->_plugin->addServers($servers1);
$this->_plugin->setServers($servers2);
$this->assertEquals(
$servers2,
$this->_plugin->getServers()
);
}
public function testSetAndGetForcedServerForNextQuery()
{
$servers1 = array(
's1' => array('options' => $this->_serverOptions, 'weight' => 10),
's2' => array('options' => $this->_serverOptions, 'weight' => 20),
);
$this->_plugin->addServers($servers1);
$this->_plugin->setForcedServerForNextQuery('s2');
$this->assertEquals('s2', $this->_plugin->getForcedServerForNextQuery());
}
public function testSetForcedServerForNextQueryWithInvalidKey()
{
$servers1 = array(
's1' => array('options' => $this->_serverOptions, 'weight' => 10),
's2' => array('options' => $this->_serverOptions, 'weight' => 20),
);
$this->_plugin->addServers($servers1);
$this->setExpectedException('Solarium_Exception');
$this->_plugin->setForcedServerForNextQuery('s3');
}
public function testAddBlockedQueryType()
{
$this->_plugin->addBlockedQueryType('type1');
$this->_plugin->addBlockedQueryType('type2');
$this->assertEquals(
array(Solarium_Client::QUERYTYPE_UPDATE, 'type1', 'type2'),
$this->_plugin->getBlockedQueryTypes()
);
}
public function testClearBlockedQueryTypes()
{
$this->_plugin->addBlockedQueryType('type1');
$this->_plugin->addBlockedQueryType('type2');
$this->_plugin->clearBlockedQueryTypes();
$this->assertEquals(array(), $this->_plugin->getBlockedQueryTypes());
}
public function testAddBlockedQueryTypes()
{
$blockedQueryTypes = array('type1', 'type2', 'type3');
$this->_plugin->clearBlockedQueryTypes();
$this->_plugin->addBlockedQueryTypes($blockedQueryTypes);
$this->assertEquals($blockedQueryTypes, $this->_plugin->getBlockedQueryTypes());
}
public function testRemoveBlockedQueryType()
{
$blockedQueryTypes = array('type1', 'type2', 'type3');
$this->_plugin->clearBlockedQueryTypes();
$this->_plugin->addBlockedQueryTypes($blockedQueryTypes);
$this->_plugin->removeBlockedQueryType('type2');
$this->assertEquals(
array('type1', 'type3'),
$this->_plugin->getBlockedQueryTypes()
);
}
public function testSetBlockedQueryTypes()
{
$blockedQueryTypes = array('type1', 'type2', 'type3');
$this->_plugin->setBlockedQueryTypes($blockedQueryTypes);
$this->assertEquals(
$blockedQueryTypes,
$this->_plugin->getBlockedQueryTypes()
);
}
public function testPreExecuteRequestWithForcedServer()
{
$servers = array(
's1' => array('options' => $this->_serverOptions, 'weight' => 100),
's2' => array('options' => $this->_serverOptions, 'weight' => 1),
);
$query = new Solarium_Query_Select();
$request = new Solarium_Client_Request();
$this->_plugin->setServers($servers);
$this->_plugin->setForcedServerForNextQuery('s2');
$this->_plugin->preCreateRequest($query);
$this->_plugin->preExecuteRequest($request);
$this->assertEquals(
's2',
$this->_plugin->getLastServerKey()
);
}
public function testAdapterPresetRestore()
{
$originalHost = $this->_client->getAdapter()->getHost();
$servers = array(
's1' => array('options' => $this->_serverOptions, 'weight' => 100),
's2' => array('options' => $this->_serverOptions, 'weight' => 1),
);
$request = new Solarium_Client_Request();
$this->_plugin->setServers($servers);
$this->_plugin->setForcedServerForNextQuery('s2');
$query = new Solarium_Query_Select();
$this->_plugin->preCreateRequest($query);
$this->_plugin->preExecuteRequest($request);
$this->assertEquals(
's2',
$this->_plugin->getLastServerKey()
);
$query = new Solarium_Query_Update(); // this is a blocked querytype that should trigger a restore
$this->_plugin->preCreateRequest($query);
$this->_plugin->preExecuteRequest($request);
$this->assertEquals(
$originalHost,
$this->_client->getAdapter()->getHost()
);
}
public function testBlockedQueryTypeNotLoadbalanced()
{
$originalHost = $this->_client->getAdapter()->getHost();
$servers = array(
's1' => array('options' => $this->_serverOptions, 'weight' => 100),
's2' => array('options' => $this->_serverOptions, 'weight' => 1),
);
$this->_plugin->setServers($servers);
$request = new Solarium_Client_Request();
$query = new Solarium_Query_Update(); // this is a blocked querytype that should not be loadbalanced
$this->_plugin->preCreateRequest($query);
$this->_plugin->preExecuteRequest($request);
$this->assertEquals(
$originalHost,
$this->_client->getAdapter()->getHost()
);
$this->assertEquals(
null,
$this->_plugin->getLastServerKey()
);
}
public function testLoadbalancerRandomizing()
{
$servers = array(
's1' => array('options' => $this->_serverOptions, 'weight' => 1),
's2' => array('options' => $this->_serverOptions, 'weight' => 1),
);
$this->_plugin->setServers($servers);
$request = new Solarium_Client_Request();
$query = new Solarium_Query_Select(); //
$this->_plugin->preCreateRequest($query);
$this->_plugin->preExecuteRequest($request);
$this->assertTrue(
in_array($this->_plugin->getLastServerKey(), array('s1','s2'))
);
}
public function testFailover()
{
$this->_plugin = new TestLoadbalancer(); // special loadbalancer that returns servers in fixed order
$this->_client = new Solarium_Client();
$this->_client->setAdapter(new TestAdapterForFailover()); // set special mock that fails once
$this->_plugin->init($this->_client, array());
$request = new Solarium_Client_Request();
$servers = array(
's1' => array('options' => $this->_serverOptions, 'weight' => 1),
's2' => array('options' => $this->_serverOptions, 'weight' => 1),
);
$this->_plugin->setServers($servers);
$this->_plugin->setFailoverEnabled(true);
$query = new Solarium_Query_Select();
$this->_plugin->preCreateRequest($query);
$this->_plugin->preExecuteRequest($request);
$this->assertEquals(
's2',
$this->_plugin->getLastServerKey()
);
}
public function testFailoverMaxRetries()
{
$this->_plugin = new TestLoadbalancer(); // special loadbalancer that returns servers in fixed order
$this->_client = new Solarium_Client();
$adapter = new TestAdapterForFailover();
$adapter->setFailCount(10);
$this->_client->setAdapter($adapter); // set special mock that fails for all servers
$this->_plugin->init($this->_client, array());
$request = new Solarium_Client_Request();
$servers = array(
's1' => array('options' => $this->_serverOptions, 'weight' => 1),
's2' => array('options' => $this->_serverOptions, 'weight' => 1),
);
$this->_plugin->setServers($servers);
$this->_plugin->setFailoverEnabled(true);
$query = new Solarium_Query_Select();
$this->_plugin->preCreateRequest($query);
$this->setExpectedException('Solarium_Exception', 'Maximum number of loadbalancer retries reached');
$this->_plugin->preExecuteRequest($request);
}
}
class TestLoadbalancer extends Solarium_Plugin_Loadbalancer{
protected $_counter = 0;
/**
* Get options array for a randomized server
*
* @return array
*/
protected function _getRandomServerOptions()
{
$this->_counter++;
$serverKey = 's'.$this->_counter;
$this->_serverExcludes[] = $serverKey;
$this->_lastServerKey = $serverKey;
return $this->_servers[$serverKey]['options'];
}
}
class TestAdapterForFailover extends Solarium_Client_Adapter_Http{
protected $_counter = 0;
protected $_failCount = 1;
public function setFailCount($count)
{
$this->_failCount = $count;
}
public function execute($request)
{
$this->_counter++;
if($this->_counter <= $this->_failCount) {
throw new Solarium_Client_HttpException('failover exception');
}
return 'dummyvalue';
}
}
\ No newline at end of file
<?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.
*/
class Solarium_Plugin_PostBigRequestTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Plugin_PostBigRequest
*/
protected $_plugin;
/**
* @var Solarium_Client
*/
protected $_client;
/**
* @var Solarium_Query_Select
*/
protected $query;
public function setUp()
{
$this->_plugin = new Solarium_Plugin_PostBigRequest();
$this->_client = new Solarium_Client();
$this->_query = $this->_client->createSelect();
}
public function testSetAndGetMaxQueryStringLength()
{
$this->_plugin->setMaxQueryStringLength(512);
$this->assertEquals(512, $this->_plugin->getMaxQueryStringLength());
}
public function testPostCreateRequest()
{
// create a very long query
$fq = '';
for($i=1; $i<=1000; $i++) {
$fq .= ' OR price:'.$i;
}
$fq = substr($fq, 4);
$this->_query->createFilterQuery('fq')->setQuery($fq);
$requestOutput = $this->_client->createRequest($this->_query);
$requestInput = clone $requestOutput;
$this->_plugin->postCreateRequest($this->_query, $requestOutput);
$this->assertEquals(Solarium_Client_Request::METHOD_GET, $requestInput->getMethod());
$this->assertEquals(Solarium_Client_Request::METHOD_POST, $requestOutput->getMethod());
$this->assertEquals($requestInput->getQueryString(), $requestOutput->getRawData());
$this->assertEquals('', $requestOutput->getQueryString());
}
public function testPostCreateRequestUnalteredSmallRequest()
{
$requestOutput = $this->_client->createRequest($this->_query);
$requestInput = clone $requestOutput;
$this->_plugin->postCreateRequest($this->_query, $requestOutput);
$this->assertEquals($requestInput, $requestOutput);
}
public function testPostCreateRequestUnalteredPostRequest()
{
$query = $this->_client->createUpdate();
$query->addDeleteById(1);
$requestOutput = $this->_client->createRequest($query);
$requestInput = clone $requestOutput;
$this->_plugin->postCreateRequest($query, $requestOutput);
$this->assertEquals($requestInput, $requestOutput);
}
}
\ No newline at end of file
<?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.
*/
class Solarium_Query_Select_Component_DebugTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Select_Component_Debug
*/
protected $_debug;
public function setUp()
{
$this->_debug = new Solarium_Query_Select_Component_Debug;
}
public function testConfigMode()
{
$options = array(
'explainother' => 'id:12',
);
$this->_debug->setOptions($options);
$this->assertEquals($options['explainother'], $this->_debug->getExplainOther());
}
public function testGetType()
{
$this->assertEquals(
Solarium_Query_Select::COMPONENT_DEBUG,
$this->_debug->getType()
);
}
public function testSetAndGetExplainOther()
{
$value = 'id:24';
$this->_debug->setExplainOther($value);
$this->assertEquals(
$value,
$this->_debug->getExplainOther()
);
}
}
......@@ -53,6 +53,7 @@ class Solarium_Query_Select_Component_GroupingTest extends PHPUnit_Framework_Tes
'mainresult' => false,
'numberofgroups' => true,
'cachepercentage' => 45,
'truncate' => true,
);
$this->_grouping->setOptions($options);
......@@ -65,6 +66,7 @@ class Solarium_Query_Select_Component_GroupingTest extends PHPUnit_Framework_Tes
$this->assertEquals($options['mainresult'], $this->_grouping->getMainResult());
$this->assertEquals($options['numberofgroups'], $this->_grouping->getNumberOfGroups());
$this->assertEquals($options['cachepercentage'], $this->_grouping->getCachePercentage());
$this->assertEquals($options['truncate'], $this->_grouping->getTruncate());
}
public function testGetType()
......@@ -195,5 +197,16 @@ class Solarium_Query_Select_Component_GroupingTest extends PHPUnit_Framework_Tes
$this->_grouping->getCachePercentage()
);
}
public function testSetAndGetTruncate()
{
$value = true;
$this->_grouping->setTruncate($value);
$this->assertEquals(
$value,
$this->_grouping->getTruncate()
);
}
}
<?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.
*/
class Solarium_Query_Select_Component_Stats_FieldTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Select_Component_Stats_Field
*/
protected $_field;
public function setUp()
{
$this->_field = new Solarium_Query_Select_Component_Stats_Field;
}
public function testConfigMode()
{
$options = array(
'facet' => 'field1, field2',
);
$this->_field->setOptions($options);
$this->assertEquals(array('field1','field2'), $this->_field->getFacets());
}
public function testSetAndGetKey()
{
$this->_field->setKey('testkey');
$this->assertEquals('testkey', $this->_field->getKey());
}
public function testAddFacet()
{
$expectedFacets = $this->_field->getFacets();
$expectedFacets[] = 'newfacet';
$this->_field->addFacet('newfacet');
$this->assertEquals($expectedFacets, $this->_field->getFacets());
}
public function testClearFacets()
{
$this->_field->addFacet('newfacet');
$this->_field->clearFacets();
$this->assertEquals(array(), $this->_field->getFacets());
}
public function testAddFacets()
{
$facets = array('facet1','facet2');
$this->_field->clearFacets();
$this->_field->addFacets($facets);
$this->assertEquals($facets, $this->_field->getFacets());
}
public function testAddFacetsAsStringWithTrim()
{
$this->_field->clearFacets();
$this->_field->addFacets('facet1, facet2');
$this->assertEquals(array('facet1','facet2'), $this->_field->getFacets());
}
public function testRemoveFacet()
{
$this->_field->clearFacets();
$this->_field->addFacets(array('facet1','facet2'));
$this->_field->removeFacet('facet1');
$this->assertEquals(array('facet2'), $this->_field->getFacets());
}
public function testSetFacets()
{
$this->_field->clearFacets();
$this->_field->addFacets(array('facet1','facet2'));
$this->_field->setFacets(array('facet3','facet4'));
$this->assertEquals(array('facet3','facet4'), $this->_field->getFacets());
}
}
<?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.
*/
class Solarium_Query_Select_Component_StatsTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Select_Component_Stats
*/
protected $_stats;
public function setUp()
{
$this->_stats = new Solarium_Query_Select_Component_Stats;
}
public function testGetType()
{
$this->assertEquals(Solarium_Query_Select::COMPONENT_STATS, $this->_stats->getType());
}
public function testConfigMode()
{
$options = array(
'facet' => 'field1, field2',
'field' => array(
'f1' => array(),
'f2' => array(),
)
);
$this->_stats->setOptions($options);
$this->assertEquals(array('field1','field2'), $this->_stats->getFacets());
$this->assertEquals(array('f1','f2'), array_keys($this->_stats->getFields()));
}
public function testCreateFieldWithKey()
{
$field = $this->_stats->createField('mykey');
// check class
$this->assertThat($field, $this->isInstanceOf('Solarium_Query_Select_Component_Stats_Field'));
$this->assertEquals(
'mykey',
$field->getKey()
);
}
public function testCreateFieldWithOptions()
{
$options = array('key' => 'testkey');
$field = $this->_stats->createField($options);
// check class
$this->assertThat($field, $this->isInstanceOf('Solarium_Query_Select_Component_Stats_Field'));
// check option forwarding
$fieldOptions = $field->getOptions();
$this->assertEquals(
$options['key'],
$field->getKey()
);
}
public function testAddAndGetField()
{
$field = new Solarium_Query_Select_Component_Stats_Field;
$field->setKey('f1');
$this->_stats->addField($field);
$this->assertEquals(
$field,
$this->_stats->getField('f1')
);
}
public function testAddFieldWithOptions()
{
$this->_stats->addField(array('key' => 'f1'));
$this->assertEquals(
'f1',
$this->_stats->getField('f1')->getKey()
);
}
public function testAddAndGetFieldWithKey()
{
$key = 'f1';
$fld = $this->_stats->createField($key, true);
$this->assertEquals(
$key,
$fld->getKey()
);
$this->assertEquals(
$fld,
$this->_stats->getField('f1')
);
}
public function testAddFieldWithoutKey()
{
$fld = new Solarium_Query_Select_Component_Stats_Field;
$this->setExpectedException('Solarium_Exception');
$this->_stats->addField($fld);
}
public function testAddFieldWithUsedKey()
{
$f1 = new Solarium_Query_Select_Component_Stats_Field;
$f1->setKey('f1');
$f2 = new Solarium_Query_Select_Component_Stats_Field;
$f2->setKey('f1');
$this->_stats->addField($f1);
$this->setExpectedException('Solarium_Exception');
$this->_stats->addField($f2);
}
public function testGetInvalidField()
{
$this->assertEquals(
null,
$this->_stats->getField('invalidkey')
);
}
public function testAddFields()
{
$f1 = new Solarium_Query_Select_Component_Stats_Field;
$f1->setKey('f1');
$f2 = new Solarium_Query_Select_Component_Stats_Field;
$f2->setKey('f2');
$fields = array('f1' => $f1, 'f2' => $f2);
$this->_stats->addFields($fields);
$this->assertEquals(
$fields,
$this->_stats->getFields()
);
}
public function testAddFieldsWithOptions()
{
$fields = array(
'f1' => array(''),
array('key' => 'f2')
);
$this->_stats->addFields($fields);
$fields = $this->_stats->getFields();
$this->assertEquals( array('f1', 'f2'), array_keys($fields));
}
public function testRemoveField()
{
$f1 = new Solarium_Query_Select_Component_Stats_Field;
$f1->setKey('f1');
$f2 = new Solarium_Query_Select_Component_Stats_Field;
$f2->setKey('f2');
$fields = array('f1' => $f1, 'f2' => $f2);
$this->_stats->addFields($fields);
$this->_stats->removeField('f1');
$this->assertEquals(
array('f2' => $f2),
$this->_stats->getFields()
);
}
public function testRemoveFieldWithObjectInput()
{
$f1 = new Solarium_Query_Select_Component_Stats_Field;
$f1->setKey('f1');
$f2 = new Solarium_Query_Select_Component_Stats_Field;
$f2->setKey('f2');
$fields = array($f1, $f2);
$this->_stats->addFields($fields);
$this->_stats->removeField($f1);
$this->assertEquals(
array('f2' => $f2),
$this->_stats->getFields()
);
}
public function testRemoveInvalidField()
{
$f1 = new Solarium_Query_Select_Component_Stats_Field;
$f1->setKey('f1');
$f2 = new Solarium_Query_Select_Component_Stats_Field;
$f2->setKey('f2');
$fields = array('f1' => $f1, 'f2' => $f2);
$this->_stats->addFields($fields);
$this->_stats->removeField('f3'); //continue silently
$this->assertEquals(
$fields,
$this->_stats->getFields()
);
}
public function testClearFields()
{
$f1 = new Solarium_Query_Select_Component_Stats_Field;
$f1->setKey('f1');
$f2 = new Solarium_Query_Select_Component_Stats_Field;
$f2->setKey('f2');
$fields = array($f1, $f2);
$this->_stats->addFields($fields);
$this->_stats->clearFields();
$this->assertEquals(
array(),
$this->_stats->getFields()
);
}
public function testSetFields()
{
$f1 = new Solarium_Query_Select_Component_Stats_Field;
$f1->setKey('f1');
$f2 = new Solarium_Query_Select_Component_Stats_Field;
$f2->setKey('f2');
$fields = array($f1, $f2);
$this->_stats->addFields($fields);
$f3 = new Solarium_Query_Select_Component_Stats_Field;
$f3->setKey('f3');
$f4 = new Solarium_Query_Select_Component_Stats_Field;
$f4->setKey('f4');
$fields2 = array('f3' => $f3, 'f4' => $f4);
$this->_stats->setFields($fields2);
$this->assertEquals(
$fields2,
$this->_stats->getFields()
);
}
public function testAddFacet()
{
$expectedFacets = $this->_stats->getFacets();
$expectedFacets[] = 'newfacet';
$this->_stats->addFacet('newfacet');
$this->assertEquals($expectedFacets, $this->_stats->getFacets());
}
public function testClearFacets()
{
$this->_stats->addFacet('newfacet');
$this->_stats->clearFacets();
$this->assertEquals(array(), $this->_stats->getFacets());
}
public function testAddFacets()
{
$facets = array('facet1','facet2');
$this->_stats->clearFacets();
$this->_stats->addFacets($facets);
$this->assertEquals($facets, $this->_stats->getFacets());
}
public function testAddFacetsAsStringWithTrim()
{
$this->_stats->clearFacets();
$this->_stats->addFacets('facet1, facet2');
$this->assertEquals(array('facet1','facet2'), $this->_stats->getFacets());
}
public function testRemoveFacet()
{
$this->_stats->clearFacets();
$this->_stats->addFacets(array('facet1','facet2'));
$this->_stats->removeFacet('facet1');
$this->assertEquals(array('facet2'), $this->_stats->getFacets());
}
public function testSetFacets()
{
$this->_stats->clearFacets();
$this->_stats->addFacets(array('facet1','facet2'));
$this->_stats->setFacets(array('facet3','facet4'));
$this->assertEquals(array('facet3','facet4'), $this->_stats->getFacets());
}
}
......@@ -32,6 +32,9 @@
class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Select
*/
protected $_query;
public function setUp()
......@@ -62,6 +65,22 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
$this->assertEquals('id:678', $this->_query->getQuery());
}
public function testSetAndGetQueryDefaultOperator()
{
$value = Solarium_Query_Select::QUERY_OPERATOR_AND;
$this->_query->setQueryDefaultOperator($value);
$this->assertEquals($value, $this->_query->getQueryDefaultOperator());
}
public function testSetAndGetQueryDefaultField()
{
$value = 'mydefault';
$this->_query->setQueryDefaultField($value);
$this->assertEquals($value, $this->_query->getQueryDefaultField());
}
public function testSetAndGetResultClass()
{
$this->_query->setResultClass('MyResult');
......@@ -601,4 +620,24 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
get_class($spellcheck)
);
}
public function testGetStats()
{
$stats = $this->_query->getStats();
$this->assertEquals(
'Solarium_Query_Select_Component_Stats',
get_class($stats)
);
}
public function testGetDebug()
{
$stats = $this->_query->getDebug();
$this->assertEquals(
'Solarium_Query_Select_Component_Debug',
get_class($stats)
);
}
}
<?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.
*/
class Solarium_Query_TermsTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Terms
*/
protected $_query;
public function setUp()
{
$this->_query = new Solarium_Query_Terms;
}
public function testGetType()
{
$this->assertEquals(Solarium_Client::QUERYTYPE_TERMS, $this->_query->getType());
}
public function testSetAndGetFields()
{
$this->_query->setFields('fieldA,fieldB');
$this->assertEquals('fieldA,fieldB', $this->_query->getFields());
}
public function testSetAndGetLowerbound()
{
$this->_query->setLowerbound('f');
$this->assertEquals('f', $this->_query->getLowerbound());
}
public function testSetAndGetLowerboundInclude()
{
$this->_query->setLowerboundInclude(true);
$this->assertEquals(true, $this->_query->getLowerboundInclude());
}
public function testSetAndGetMinCount()
{
$this->_query->setMinCount(3);
$this->assertEquals(3, $this->_query->getMinCount());
}
public function testSetAndGetMaxCount()
{
$this->_query->setMaxCount(25);
$this->assertEquals(25, $this->_query->getMaxCount());
}
public function testSetAndGetPrefix()
{
$this->_query->setPrefix('wat');
$this->assertEquals('wat', $this->_query->getPrefix());
}
public function testSetAndGetRegex()
{
$this->_query->setRegex('at.*');
$this->assertEquals('at.*', $this->_query->getRegex());
}
public function testSetAndGetRegexFlags()
{
$this->_query->setRegexFlags('case_insensitive,comments');
$this->assertEquals('case_insensitive,comments', $this->_query->getRegexFlags());
}
public function testSetAndGetLimit()
{
$this->_query->setLimit(15);
$this->assertEquals(15, $this->_query->getLimit());
}
public function testSetAndGetUpperbound()
{
$this->_query->setUpperbound('x');
$this->assertEquals('x', $this->_query->getUpperbound());
}
public function testSetAndGetUpperboundInclude()
{
$this->_query->setUpperboundInclude(true);
$this->assertEquals(true, $this->_query->getUpperboundInclude());
}
public function testSetAndGetRaw()
{
$this->_query->setRaw(false);
$this->assertEquals(false, $this->_query->getRaw());
}
public function testSetAndGetSort()
{
$this->_query->setSort('index');
$this->assertEquals('index', $this->_query->getSort());
}
}
\ No newline at end of file
......@@ -48,7 +48,8 @@ class Solarium_Result_Analysis_ItemTest extends PHPUnit_Framework_TestCase
'position' => 2,
'positionHistory' => array(2,1),
'type' => '<dummytype>',
'raw_text' => 'dummy raw text'
'raw_text' => 'dummy raw text',
'match' => true
);
$this->_item = new Solarium_Result_Analysis_Item($this->_data);
}
......@@ -101,4 +102,9 @@ class Solarium_Result_Analysis_ItemTest extends PHPUnit_Framework_TestCase
$item = new Solarium_Result_Analysis_Item($data);
$this->assertEquals(null, $item->getRawText());
}
public function testGetMatch()
{
$this->assertEquals($this->_data['match'], $this->_item->getMatch());
}
}
\ No newline at end of file
......@@ -34,11 +34,15 @@ class Solarium_Result_PingTest extends PHPUnit_Framework_TestCase
public function testGetStatus()
{
$ping = new Solarium_Result_Ping();
$client = new Solarium_Client;
$query = new Solarium_Query_Ping;
$response = new Solarium_Client_Response('{"responseHeader":{"status":1,"QTime":12}}',array('HTTP 1.1 200 OK'));
$ping = new Solarium_Result_Ping($client, $query, $response);
$this->assertEquals(
0,
$ping->getStatus()
);
}
}
\ No newline at end of file
}
<?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.
*/
class Solarium_Result_Select_Debug_DetailTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Debug_Detail
*/
protected $_result;
protected $_value, $_match, $_description;
public function setUp()
{
$this->_value = 1.5;
$this->_match = true;
$this->_description = 'dummy-desc';
$this->_result = new Solarium_Result_Select_Debug_Detail(
$this->_match,
$this->_value,
$this->_description
);
}
public function testGetValue()
{
$this->assertEquals($this->_value, $this->_result->getValue());
}
public function testGetMatch()
{
$this->assertEquals($this->_match, $this->_result->getMatch());
}
public function testGetDescription()
{
$this->assertEquals($this->_description, $this->_result->getDescription());
}
}
<?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.
*/
class Solarium_Result_Select_Debug_DocumentSetTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Debug_DocumentSet
*/
protected $_result;
protected $_docs;
public function setUp()
{
$this->_docs = array('key1' => 'dummy1', 'key2' => 'dummy2');
$this->_result = new Solarium_Result_Select_Debug_DocumentSet($this->_docs);
}
public function testGetDocument()
{
$this->assertEquals(
$this->_docs['key1'],
$this->_result->getDocument('key1')
);
}
public function testGetDocumentWithInvalidKey()
{
$this->assertEquals(
null,
$this->_result->getDocument('invalidkey')
);
}
public function testGetDocuments()
{
$this->assertEquals(
$this->_docs,
$this->_result->getDocuments()
);
}
public function testIterator()
{
$items = array();
foreach($this->_result AS $key => $item)
{
$items[$key] = $item;
}
$this->assertEquals($this->_docs, $items);
}
public function testCount()
{
$this->assertEquals(count($this->_docs), count($this->_result));
}
}
<?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.
*/
class Solarium_Result_Select_Debug_DocumentTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Debug_Document
*/
protected $_result;
protected $_value, $_match, $_description, $_key, $_details;
public function setUp()
{
$this->_key = 'dummy-key';
$this->_value = 1.5;
$this->_match = true;
$this->_description = 'dummy-desc';
$this->_details = array(0 => 'dummy1', 1 => 'dummy2');
$this->_result = new Solarium_Result_Select_Debug_Document(
$this->_key,
$this->_match,
$this->_value,
$this->_description,
$this->_details
);
}
public function testGetKey()
{
$this->assertEquals($this->_key, $this->_result->getKey());
}
public function testGetDetails()
{
$this->assertEquals($this->_details, $this->_result->getDetails());
}
public function testIterator()
{
$items = array();
foreach($this->_result AS $key => $item)
{
$items[$key] = $item;
}
$this->assertEquals($this->_details, $items);
}
public function testCount()
{
$this->assertEquals(count($this->_details), count($this->_result));
}
}
<?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.
*/
class Solarium_Result_Select_Debug_TimingPhaseTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Debug_TimingPhase
*/
protected $_result;
protected $_name, $_time, $_timings;
public function setUp()
{
$this->_name = 'dummy-name';
$this->_time = 14;
$this->_timings = array('class1' => 1, 'class2' => 3);
$this->_result = new Solarium_Result_Select_Debug_TimingPhase($this->_name, $this->_time, $this->_timings);
}
public function testGetTime()
{
$this->assertEquals(
$this->_time,
$this->_result->getTime()
);
}
public function testGetTiming()
{
$this->assertEquals(
$this->_timings['class1'],
$this->_result->getTiming('class1')
);
}
public function testGetPhaseWithInvalidKey()
{
$this->assertEquals(
null,
$this->_result->getTiming('invalidkey')
);
}
public function testGetTimings()
{
$this->assertEquals(
$this->_timings,
$this->_result->getTimings()
);
}
public function testIterator()
{
$items = array();
foreach($this->_result AS $key => $item)
{
$items[$key] = $item;
}
$this->assertEquals($this->_timings, $items);
}
public function testCount()
{
$this->assertEquals(count($this->_timings), count($this->_result));
}
}
<?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.
*/
class Solarium_Result_Select_Debug_TimingTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Debug_Timing
*/
protected $_result;
protected $_time, $_phases;
public function setUp()
{
$this->_time = 14;
$this->_phases = array('key1' => 'dummy1', 'key2' => 'dummy2');
$this->_result = new Solarium_Result_Select_Debug_Timing($this->_time, $this->_phases);
}
public function testGetTime()
{
$this->assertEquals(
$this->_time,
$this->_result->getTime()
);
}
public function testGetPhase()
{
$this->assertEquals(
$this->_phases['key1'],
$this->_result->getPhase('key1')
);
}
public function testGetPhaseWithInvalidKey()
{
$this->assertEquals(
null,
$this->_result->getPhase('invalidkey')
);
}
public function testGetPhases()
{
$this->assertEquals(
$this->_phases,
$this->_result->getPhases()
);
}
public function testIterator()
{
$items = array();
foreach($this->_result AS $key => $item)
{
$items[$key] = $item;
}
$this->assertEquals($this->_phases, $items);
}
public function testCount()
{
$this->assertEquals(count($this->_phases), count($this->_result));
}
}
<?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.
*/
class Solarium_Result_Select_DebugTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Debug
*/
protected $_result;
protected $_queryString, $_queryParser, $_otherQuery, $_explain, $_explainOther, $timing;
public function setUp()
{
$this->_queryString = 'dummy-querystring';
$this->_parsedQuery = 'dummy-parsed-qs';
$this->_queryParser = 'dummy-parser';
$this->_otherQuery = 'id:67';
$this->_explainData = array('a'=>'dummy1', 'b'=>'dummy2');
$this->_explain = new ArrayIterator($this->_explainData);
$this->_explainOther = 'dummy-other';
$this->_timing = 'dummy-timing';
$this->_result = new Solarium_Result_Select_Debug(
$this->_queryString,
$this->_parsedQuery,
$this->_queryParser,
$this->_otherQuery,
$this->_explain,
$this->_explainOther,
$this->_timing
);
}
public function testGetQueryString()
{
$this->assertEquals($this->_queryString, $this->_result->getQueryString());
}
public function testGetParsedQuery()
{
$this->assertEquals($this->_parsedQuery, $this->_result->getParsedQuery());
}
public function testGetQueryParser()
{
$this->assertEquals($this->_queryParser, $this->_result->getQueryParser());
}
public function testGetOtherQuery()
{
$this->assertEquals($this->_otherQuery, $this->_result->getOtherQuery());
}
public function testGetExplain()
{
$this->assertEquals($this->_explain, $this->_result->getExplain());
}
public function testGetExplainOther()
{
$this->assertEquals($this->_explainOther, $this->_result->getExplainOther());
}
public function testGetTiming()
{
$this->assertEquals($this->_timing, $this->_result->getTiming());
}
public function testIterator()
{
$items = array();
foreach($this->_result AS $key => $item)
{
$items[$key] = $item;
}
$this->assertEquals($this->_explainData, $items);
}
public function testCount()
{
$this->assertEquals(count($this->_explain), count($this->_result));
}
}
<?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.
*/
class Solarium_Result_Select_Stats_FacetValueTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Stats_FacetValue
*/
protected $_result;
protected $_value, $_stats;
public function setUp()
{
$this->_value = 'myvalue';
$this->_stats = array(
'min' => 'dummyMin',
'max' => 'dummyMax',
'sum' => 'dummySum',
'count' => 'dummyCount',
'missing' => 'dummyMissing',
'sumOfSquares' => 'dummySos',
'mean' => 'dummyMean',
'stddev' => 'dummyStddev',
'facets' => 'dummyFacets',
);
$this->_result = new Solarium_Result_Select_Stats_FacetValue($this->_value, $this->_stats);
}
public function testGetValue()
{
$this->assertEquals($this->_value, $this->_result->getValue());
}
public function testGetMin()
{
$this->assertEquals($this->_stats['min'], $this->_result->getMin());
}
public function testGetMax()
{
$this->assertEquals($this->_stats['max'], $this->_result->getMax());
}
public function testGetSum()
{
$this->assertEquals($this->_stats['sum'], $this->_result->getSum());
}
public function testGetCount()
{
$this->assertEquals($this->_stats['count'], $this->_result->getCount());
}
public function testGetMissing()
{
$this->assertEquals($this->_stats['missing'], $this->_result->getMissing());
}
public function testGetSumOfSquares()
{
$this->assertEquals($this->_stats['sumOfSquares'], $this->_result->getSumOfSquares());
}
public function testGetMean()
{
$this->assertEquals($this->_stats['mean'], $this->_result->getMean());
}
public function testGetStddev()
{
$this->assertEquals($this->_stats['stddev'], $this->_result->getStddev());
}
public function testGetFacets()
{
$this->assertEquals($this->_stats['facets'], $this->_result->getFacets());
}
}
<?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.
*/
class Solarium_Result_Select_Stats_ResultTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Stats_Result
*/
protected $_result;
protected $_field, $_stats;
public function setUp()
{
$this->_field = 'myfield';
$this->_stats = array(
'min' => 'dummyMin',
'max' => 'dummyMax',
'sum' => 'dummySum',
'count' => 'dummyCount',
'missing' => 'dummyMissing',
'sumOfSquares' => 'dummySos',
'mean' => 'dummyMean',
'stddev' => 'dummyStddev',
'facets' => 'dummyFacets',
);
$this->_result = new Solarium_Result_Select_Stats_Result($this->_field, $this->_stats);
}
public function testGetName()
{
$this->assertEquals($this->_field, $this->_result->getName());
}
public function testGetMin()
{
$this->assertEquals($this->_stats['min'], $this->_result->getMin());
}
public function testGetMax()
{
$this->assertEquals($this->_stats['max'], $this->_result->getMax());
}
public function testGetSum()
{
$this->assertEquals($this->_stats['sum'], $this->_result->getSum());
}
public function testGetCount()
{
$this->assertEquals($this->_stats['count'], $this->_result->getCount());
}
public function testGetMissing()
{
$this->assertEquals($this->_stats['missing'], $this->_result->getMissing());
}
public function testGetSumOfSquares()
{
$this->assertEquals($this->_stats['sumOfSquares'], $this->_result->getSumOfSquares());
}
public function testGetMean()
{
$this->assertEquals($this->_stats['mean'], $this->_result->getMean());
}
public function testGetStddev()
{
$this->assertEquals($this->_stats['stddev'], $this->_result->getStddev());
}
public function testGetFacets()
{
$this->assertEquals($this->_stats['facets'], $this->_result->getFacets());
}
}
<?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.
*/
class Solarium_Result_Select_StatsTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Stats
*/
protected $_result;
public function setUp()
{
$this->_data = array(
'key1' => 'value1',
'key2' => 'value2',
);
$this->_result = new Solarium_Result_Select_Stats($this->_data);
}
public function testGetResult()
{
$this->assertEquals($this->_data['key1'], $this->_result->getResult('key1'));
}
public function testGetInvalidResult()
{
$this->assertEquals(null, $this->_result->getResult('key3'));
}
public function testGetResults()
{
$this->assertEquals($this->_data, $this->_result->getResults());
}
public function testIterator()
{
$items = array();
foreach($this->_result AS $key => $item)
{
$items[$key] = $item;
}
$this->assertEquals($this->_data, $items);
}
public function testCount()
{
$this->assertEquals(count($this->_data), count($this->_result));
}
}
......@@ -37,7 +37,8 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
*/
protected $_result;
protected $_numFound, $_docs, $_components, $_facetSet, $_moreLikeThis, $_highlighting, $_grouping;
protected $_numFound, $_docs, $_components, $_facetSet, $_moreLikeThis,
$_highlighting, $_grouping, $_stats, $_debug;
public function setUp()
{
......@@ -53,6 +54,8 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
$this->_highlighting = 'dummy-highlighting-value';
$this->_grouping = 'dummy-grouping-value';
$this->_spellcheck = 'dummy-grouping-value';
$this->_stats = 'dummy-stats-value';
$this->_debug = 'dummy-debug-value';
$this->_components = array(
Solarium_Query_Select::COMPONENT_FACETSET => $this->_facetSet,
......@@ -60,6 +63,8 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
Solarium_Query_Select::COMPONENT_HIGHLIGHTING => $this->_highlighting,
Solarium_Query_Select::COMPONENT_GROUPING => $this->_grouping,
Solarium_Query_Select::COMPONENT_SPELLCHECK => $this->_spellcheck,
Solarium_Query_Select::COMPONENT_STATS => $this->_stats,
Solarium_Query_Select::COMPONENT_DEBUG => $this->_debug,
);
$this->_result = new Solarium_Result_SelectDummy(1, 12, $this->_numFound, $this->_docs, $this->_components);
......@@ -138,6 +143,22 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
);
}
public function testGetStats()
{
$this->assertEquals(
$this->_components[Solarium_Query_Select::COMPONENT_STATS],
$this->_result->getStats()
);
}
public function testGetDebug()
{
$this->assertEquals(
$this->_components[Solarium_Query_Select::COMPONENT_DEBUG],
$this->_result->getDebug()
);
}
public function testIterator()
{
$docs = array();
......
<?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.
*/
class Solarium_Result_TermsTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Terms
*/
protected $_result;
/**
* @var array
*/
protected $_data;
public function setUp()
{
$this->_data = array(
'fieldA' => array(
'term1',
11,
'term2',
5,
'term3',
2,
),
'fieldB' => array(
'term4',
4,
'term5',
1,
)
);
$this->_result = new Solarium_Result_TermsDummy($this->_data);
}
public function testGetStatus()
{
$this->assertEquals(
1,
$this->_result->getStatus()
);
}
public function testGetQueryTime()
{
$this->assertEquals(
12,
$this->_result->getQueryTime()
);
}
public function testGetResults()
{
$this->assertEquals($this->_data, $this->_result->getResults());
}
public function testGetTerms()
{
$this->assertEquals($this->_data['fieldA'], $this->_result->getTerms('fieldA'));
}
public function testGetTermsWithInvalidFieldName()
{
$this->assertEquals(array(), $this->_result->getTerms('fieldX'));
}
public function testCount()
{
$this->assertEquals(count($this->_data), count($this->_result));
}
public function testIterator()
{
$results = array();
foreach($this->_result AS $key => $doc)
{
$results[$key] = $doc;
}
$this->assertEquals($this->_data, $results);
}
}
class Solarium_Result_TermsDummy extends Solarium_Result_Terms
{
protected $_parsed = true;
public function __construct($results)
{
$this->_results = $results;
$this->_status = 1;
$this->_queryTime = 12;
}
}
\ No newline at end of file
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