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,7 +468,8 @@ class Solarium_Client extends Solarium_Configurable
*/
protected function _callPlugins($event, $params, $resultOverride = false)
{
foreach ($this->_plugins AS $plugin) {
foreach ($this->_pluginInstances AS $plugin) {
if (method_exists($plugin, $event)) {
$result = call_user_func_array(array($plugin, $event), $params);
if ($result !== null && $resultOverride) {
......@@ -424,6 +477,7 @@ class Solarium_Client extends Solarium_Configurable
}
}
}
}
/**
* Creates a request based on a query instance
......@@ -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;
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);
}
}
......@@ -150,7 +150,7 @@ abstract class Solarium_Client_Adapter extends Solarium_Configurable
/**
* 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");
}
}
}
......@@ -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);
$headers[] = 'HTTP/' . $message->getHttpVersion()
. ' ' . $message->getResponseCode()
. ' ' . $message->getResponseStatus();
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 = 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
......@@ -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;
}
}
......@@ -83,9 +83,16 @@ class Solarium_Client_ResponseParser_Select extends Solarium_Client_ResponsePars
$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,
);
}
......
......@@ -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
This diff is collapsed.
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @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 {
//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
......@@ -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 {
//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;
}
......
......@@ -382,4 +382,28 @@ 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,7 +125,7 @@ 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
*/
......
......@@ -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);
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -70,7 +70,7 @@ class Solarium_Version
*
* @var string
*/
const VERSION = '2.0.0';
const VERSION = '2.3.0';
/**
......
This diff is collapsed.
......@@ -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()
);
......
......@@ -38,12 +38,12 @@ 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()
);
}
......
......@@ -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()
);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment