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

- added a select query stats component

- added an example for the stats component
parent 69604f3f
<?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
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
<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.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.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.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>
</ul> </ul>
<li><a href="2.1.6-helper-functions.php">2.1.6 Helper functions</a></li> <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> <li><a href="2.1.7-query-reuse.php">2.1.7 Query re-use</a></li>
......
<?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. 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) {
$facets = array();
if (isset($stats['facets'])) {
foreach($stats['facets'] as $field => $values) {
foreach ($values as $value => $valueStats) {
$stats['facets'][$field][$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
...@@ -94,6 +94,11 @@ class Solarium_Query_Select extends Solarium_Query ...@@ -94,6 +94,11 @@ class Solarium_Query_Select extends Solarium_Query
*/ */
const COMPONENT_DISTRIBUTEDSEARCH = 'distributedsearch'; const COMPONENT_DISTRIBUTEDSEARCH = 'distributedsearch';
/**
* Query component stats
*/
const COMPONENT_STATS = 'stats';
/** /**
* Get type for this query * Get type for this query
* *
...@@ -160,6 +165,11 @@ class Solarium_Query_Select extends Solarium_Query ...@@ -160,6 +165,11 @@ class Solarium_Query_Select extends Solarium_Query
'requestbuilder' => 'Solarium_Client_RequestBuilder_Select_Component_DistributedSearch', 'requestbuilder' => 'Solarium_Client_RequestBuilder_Select_Component_DistributedSearch',
'responseparser' => null, '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',
),
); );
/** /**
...@@ -877,4 +887,16 @@ class Solarium_Query_Select extends Solarium_Query ...@@ -877,4 +887,16 @@ class Solarium_Query_Select extends Solarium_Query
return $this->getComponent(Solarium_Query_Select::COMPONENT_DISTRIBUTEDSEARCH, true); 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);
}
} }
<?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');
}
if (array_key_exists($key, $this->_fields)) {
if ($this->_fields[$key] === $field) {
//double add calls for the same FQ are ignored
//@todo add trigger_error with a notice?
} else {
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
...@@ -269,4 +269,16 @@ class Solarium_Result_Select extends Solarium_Result_QueryType ...@@ -269,4 +269,16 @@ class Solarium_Result_Select extends Solarium_Result_QueryType
{ {
return $this->getComponent(Solarium_Query_Select::COMPONENT_SPELLCHECK); 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);
}
} }
\ 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 stats result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_Stats
implements IteratorAggregate, Countable
{
/**
* Result array
*
* @var array
*/
protected $_results;
/**
* Constructor
*
* @param array $results
* @return void
*/
public function __construct($results)
{
$this->_results = $results;
}
/**
* Get a result by key
*
* @param mixed $key
* @return Solarium_Result_Select_Stats_Result|null
*/
public function getResult($key)
{
if (isset($this->_results[$key])) {
return $this->_results[$key];
} else {
return null;
}
}
/**
* Get all results
*
* @return array
*/
public function getResults()
{
return $this->_results;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->_results);
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
return count($this->_results);
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component stats facet value
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_Stats_FacetValue
{
/**
* Facet value
*
* @var string
*/
protected $_value;
/**
* Stats data
*
* @var array
*/
protected $_stats;
/**
* Constructor
*
* @param string $value
* @param array $stats
* @return void
*/
public function __construct($value, $stats)
{
$this->_value = $value;
$this->_stats = $stats;
}
/**
* Get facet value
*
* @return string
*/
public function getValue()
{
return $this->_value;
}
/**
* Get min value
*
* @return string
*/
public function getMin()
{
return $this->_stats['min'];
}
/**
* Get max value
*
* @return string
*/
public function getMax()
{
return $this->_stats['max'];
}
/**
* Get sum value
*
* @return string
*/
public function getSum()
{
return $this->_stats['sum'];
}
/**
* Get count value
*
* @return string
*/
public function getCount()
{
return $this->_stats['count'];
}
/**
* Get missing value
*
* @return string
*/
public function getMissing()
{
return $this->_stats['missing'];
}
/**
* Get sumOfSquares value
*
* @return string
*/
public function getSumOfSquares()
{
return $this->_stats['sumOfSquares'];
}
/**
* Get mean value
*
* @return string
*/
public function getMean()
{
return $this->_stats['mean'];
}
/**
* Get stddev value
*
* @return string
*/
public function getStddev()
{
return $this->_stats['stddev'];
}
/**
* Get facet stats
*
* @return array
*/
public function getFacets()
{
return $this->_stats['facets'];
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component stats field result item
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_Stats_Result
{
/**
* Field name
*
* @var string
*/
protected $_field;
/**
* Stats data
*
* @var array
*/
protected $_stats;
/**
* Constructor
*
* @param string $field
* @param array $stats
* @return void
*/
public function __construct($field, $stats)
{
$this->_field = $field;
$this->_stats = $stats;
}
/**
* Get field name
*
* @return string
*/
public function getName()
{
return $this->_field;
}
/**
* Get min value
*
* @return string
*/
public function getMin()
{
return $this->_stats['min'];
}
/**
* Get max value
*
* @return string
*/
public function getMax()
{
return $this->_stats['max'];
}
/**
* Get sum value
*
* @return string
*/
public function getSum()
{
return $this->_stats['sum'];
}
/**
* Get count value
*
* @return string
*/
public function getCount()
{
return $this->_stats['count'];
}
/**
* Get missing value
*
* @return string
*/
public function getMissing()
{
return $this->_stats['missing'];
}
/**
* Get sumOfSquares value
*
* @return string
*/
public function getSumOfSquares()
{
return $this->_stats['sumOfSquares'];
}
/**
* Get mean value
*
* @return string
*/
public function getMean()
{
return $this->_stats['mean'];
}
/**
* Get stddev value
*
* @return string
*/
public function getStddev()
{
return $this->_stats['stddev'];
}
/**
* Get facet stats
*
* @return array
*/
public function getFacets()
{
return $this->_stats['facets'];
}
}
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