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

- added facet support

- refactored lots of code
parent 2e1ed301
...@@ -47,19 +47,8 @@ class Solarium_Client_Adapter_Stream extends Solarium_Client_Adapter ...@@ -47,19 +47,8 @@ class Solarium_Client_Adapter_Stream extends Solarium_Client_Adapter
new Solarium_Client_Request_Select($this->_options, $query) new Solarium_Client_Request_Select($this->_options, $query)
); );
$documentClass = $query->getOption('documentclass'); $response = new Solarium_Client_Response_Select($query, $data);
$documents = array(); return $response->getResult();
if (isset($data['response']['docs'])) {
foreach ($data['response']['docs'] AS $doc) {
$fields = (array)$doc;
$documents[] = new $documentClass($fields);
}
}
$numFound = $data['response']['numFound'];
$resultClass = $query->getOption('resultclass');
return new $resultClass($numFound, $documents);
} }
...@@ -75,9 +64,8 @@ class Solarium_Client_Adapter_Stream extends Solarium_Client_Adapter ...@@ -75,9 +64,8 @@ class Solarium_Client_Adapter_Stream extends Solarium_Client_Adapter
new Solarium_Client_Request($this->_options, $query) new Solarium_Client_Request($this->_options, $query)
); );
$resultClass = $query->getOption('resultclass'); $response = new Solarium_Client_Response_Ping($query);
return $response->getResult();
return new $resultClass;
} }
/** /**
...@@ -91,13 +79,9 @@ class Solarium_Client_Adapter_Stream extends Solarium_Client_Adapter ...@@ -91,13 +79,9 @@ class Solarium_Client_Adapter_Stream extends Solarium_Client_Adapter
$data = $this->_getSolrData( $data = $this->_getSolrData(
new Solarium_Client_Request_Update($this->_options, $query) new Solarium_Client_Request_Update($this->_options, $query)
); );
$resultClass = $query->getOption('resultclass');
return new $resultClass( $response = new Solarium_Client_Response_Update($query, $data);
$data['responseHeader']['status'], return $response->getResult();
$data['responseHeader']['QTime']
);
} }
/** /**
......
...@@ -120,5 +120,54 @@ class Solarium_Client_Request ...@@ -120,5 +120,54 @@ class Solarium_Client_Request
return ''; return '';
} }
} }
/**
* Render a param with localParams
*
* @param string $value
* @param array $localParams in key => value format
* @return string with Solr localparams syntax
*/
public function renderLocalParams($value, $localParams = array())
{
$prefix = '';
if (count($localParams) > 0) {
$prefix .= '{!';
foreach ($localParams AS $paramName => $paramValue) {
if (empty($paramValue)) continue;
if (is_array($paramValue)) {
$paramValue = implode($paramValue,',');
}
$prefix .= $paramName . '=' . $paramValue . ' ';
}
$prefix = rtrim($prefix) . '}';
}
return $prefix . $value;
}
public function getParams()
{
return $this->_params;
}
public function addParam($name, $value)
{
if (0 === strlen($value)) return;
if (!isset($this->_params[$name])) {
$this->_params[$name] = $value;
} else {
if (!is_array($this->_params[$name])) {
$this->_params[$name] = array($this->_params[$name]);
}
$this->_params[$name][] = $value;
}
}
} }
\ No newline at end of file
...@@ -51,15 +51,69 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request ...@@ -51,15 +51,69 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
'wt' => 'json', 'wt' => 'json',
); );
if (count($this->_query->getFilterQueries()) !== 0) { $filterQueries = $this->_query->getFilterQueries();
$fq = array(); if (count($filterQueries) !== 0) {
foreach ($this->_query->getFilterQueries() foreach ($filterQueries AS $filterQuery) {
AS $tag => $filterQuery) { $fq = $this->renderLocalParams(
$fq[] = '{!tag='. $tag . '}' . $filterQuery; $filterQuery->getQuery(),
array('tag' => $filterQuery->getTags())
);
$this->addParam('fq', $fq);
} }
}
$facets = $this->_query->getFacets();
if (count($facets) !== 0) {
$this->_params['fq'] = $fq; // enable faceting
$this->_params['facet'] = 'true';
foreach ($facets AS $facet) {
switch ($facet->getType())
{
case Solarium_Query_Select_Facet::FIELD:
$this->addFacetField($facet);
break;
case Solarium_Query_Select_Facet::QUERY:
$this->addFacetQuery($facet);
break;
default:
throw new Solarium_Exception('Unknown facet type');
}
}
} }
} }
public function addFacetField($facet)
{
$field = $facet->getField();
$this->addParam(
'facet.field',
$this->renderLocalParams(
$field,
array('key' => $facet->getKey(), 'ex' => $facet->getExcludes())
)
);
$this->addParam("f.$field.facet.limit", $facet->getLimit());
$this->addParam("f.$field.facet.sort", $facet->getSort());
$this->addParam("f.$field.facet.prefix", $facet->getPrefix());
$this->addParam("f.$field.facet.offset", $facet->getOffset());
$this->addParam("f.$field.facet.mincount", $facet->getMinCount());
$this->addParam("f.$field.facet.missing", $facet->getMissing());
$this->addParam("f.$field.facet.method", $facet->getMethod());
}
public function addFacetQuery($facet)
{
$this->addParam(
'facet.query',
$this->renderLocalParams(
$facet->getQuery(),
array('key' => $facet->getKey(), 'ex' => $facet->getExcludes())
)
);
}
} }
\ 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.
*/
/**
* Handles Solr response, for use in adapters.
*/
abstract class Solarium_Client_Response
{
protected $_query;
protected $_data;
public function __construct($query, $data = null)
{
$this->_query = $query;
$this->_data = $data;
}
abstract function getResult();
}
\ 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.
*/
/**
* Handles Solr ping response, for use in adapters.
*/
class Solarium_Client_Response_Ping extends Solarium_Client_Response
{
public function getResult()
{
$resultClass = $this->_query->getOption('resultclass');
return new $resultClass;
}
}
\ 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.
*/
/**
* Handles Solr select response, for use in adapters.
*/
class Solarium_Client_Response_Select extends Solarium_Client_Response
{
protected $_facets = array();
public function getResult()
{
$documentClass = $this->_query->getOption('documentclass');
$documents = array();
if (isset($this->_data['response']['docs'])) {
foreach ($this->_data['response']['docs'] AS $doc) {
$fields = (array)$doc;
$documents[] = new $documentClass($fields);
}
}
foreach($this->_query->getFacets() AS $facet)
{
switch ($facet->getType()) {
case Solarium_Query_Select_Facet::FIELD:
$this->_addFacetField($facet);
break;
case Solarium_Query_Select_Facet::QUERY:
$this->_addFacetQuery($facet);
break;
default:
throw new Solarium_Exception('Unknown facet type');
}
}
$numFound = $this->_data['response']['numFound'];
$resultClass = $this->_query->getOption('resultclass');
return new $resultClass($numFound, $documents, $this->_facets);
}
protected function _addFacetField($facet)
{
if (isset($this->_data['facet_counts']['facet_fields'][$facet->getKey()])) {
$values = array_chunk($this->_data['facet_counts']['facet_fields'][$facet->getKey()],2);
$facetValues = array();
foreach ($values AS $value) {
$facetValues[$value[0]] = $value[1];
}
$this->_facets[$facet->getKey()] = new Solarium_Result_Select_Facet_Field($facetValues);
}
}
protected function _addFacetQuery($facet)
{
if (isset($this->_data['facet_counts']['facet_queries'][$facet->getKey()])) {
$value = $this->_data['facet_counts']['facet_queries'][$facet->getKey()];
$this->_facets[$facet->getKey()] = new Solarium_Result_Select_Facet_Query($value);
}
}
}
\ 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.
*/
/**
* Handles Solr select response, for use in adapters.
*/
class Solarium_Client_Response_Update extends Solarium_Client_Response
{
public function getResult()
{
$resultClass = $this->_query->getOption('resultclass');
return new $resultClass(
$this->_data['responseHeader']['status'],
$this->_data['responseHeader']['QTime']
);
}
}
\ No newline at end of file
...@@ -56,7 +56,7 @@ class Solarium_Configurable ...@@ -56,7 +56,7 @@ class Solarium_Configurable
if (null !== $options) { if (null !== $options) {
// first convert to array if needed // first convert to array if needed
if (!is_array($options)) { if (!is_array($options)) {
if ($options instanceof Zend_Config) { if (is_object($options)) {
$options = $options->toArray(); $options = $options->toArray();
} else { } else {
throw new Solarium_Exception('Options must be an ' throw new Solarium_Exception('Options must be an '
......
...@@ -94,27 +94,4 @@ class Solarium_Query extends Solarium_Configurable ...@@ -94,27 +94,4 @@ class Solarium_Query extends Solarium_Configurable
return $string; return $string;
} }
/**
* Render a param with localParams
*
* @param string $value
* @param array $localParams in key => value format
* @return string with Solr localparams syntax
*/
public function renderLocalParams($value, $localParams = array())
{
$prefix = '';
if (count($localParams) > 0) {
$prefix .= '{!';
foreach ($localParams AS $paramName => $paramValue) {
$prefix .= $paramName . '=' . $paramValue . ' ';
}
$prefix = rtrim($prefix) . '}';
}
return $prefix . $value;
}
} }
\ No newline at end of file
...@@ -77,6 +77,13 @@ class Solarium_Query_Select extends Solarium_Query ...@@ -77,6 +77,13 @@ class Solarium_Query_Select extends Solarium_Query
*/ */
protected $_filterQueries = array(); protected $_filterQueries = array();
/**
* Facets
*
* @var array
*/
protected $_facets = array();
/** /**
* Initialize options * Initialize options
* *
...@@ -94,6 +101,9 @@ class Solarium_Query_Select extends Solarium_Query ...@@ -94,6 +101,9 @@ class Solarium_Query_Select extends Solarium_Query
case 'filterquery': case 'filterquery':
$this->addFilterQueries($value); $this->addFilterQueries($value);
break; break;
case 'facet':
$this->addFacets($value);
break;
case 'sort': case 'sort':
$this->addSortFields($value); $this->addSortFields($value);
break; break;
...@@ -380,30 +390,36 @@ class Solarium_Query_Select extends Solarium_Query ...@@ -380,30 +390,36 @@ class Solarium_Query_Select extends Solarium_Query
/** /**
* Add a filter query * Add a filter query
* *
* @param string $tag used as reference to the filterquery and possible for * @param Solarium_Query_Select_FilterQuery $filterQuery
* excluding in facets
*
* @param string $filterQuery
* @return Solarium_Query Provides fluent interface * @return Solarium_Query Provides fluent interface
*/ */
public function addFilterQuery($tag, $filterQuery) public function addFilterQuery($filterQuery)
{ {
$this->_filterQueries[$tag] = $filterQuery; $key = $filterQuery->getKey();
if (0 === strlen($key)) {
throw new Solarium_Exception('A filterquery must have a key value');
}
if (array_key_exists($key, $this->_facets)) {
throw new Solarium_Exception('A filterquery must have a unique key'
. ' value within a query');
}
$this->_filterQueries[$key] = $filterQuery;
return $this; return $this;
} }
/** /**
* Add multiple filterqueries * Add multiple filterqueries
* The input array must contain tags as keys and the filterqueries as
* values.
* *
* @param array $filterQueries * @param array $filterQueries
* @return Solarium_Query Provides fluent interface * @return Solarium_Query Provides fluent interface
*/ */
public function addFilterQueries(array $filterQueries) public function addFilterQueries(array $filterQueries)
{ {
foreach ($filterQueries AS $tag => $filterQuery) { foreach ($filterQueries AS $filterQuery) {
$this->addFilterQuery($tag, $filterQuery); $this->addFilterQuery($filterQuery);
} }
return $this; return $this;
...@@ -412,13 +428,13 @@ class Solarium_Query_Select extends Solarium_Query ...@@ -412,13 +428,13 @@ class Solarium_Query_Select extends Solarium_Query
/** /**
* Get a filterquery * Get a filterquery
* *
* @param string $tag * @param string $key
* @return string * @return string
*/ */
public function getFilterQuery($tag) public function getFilterQuery($key)
{ {
if (isset($this->_filterQueries[$tag])) { if (isset($this->_filterQueries[$key])) {
return $this->_filterQueries[$tag]; return $this->_filterQueries[$key];
} else { } else {
return null; return null;
} }
...@@ -435,15 +451,15 @@ class Solarium_Query_Select extends Solarium_Query ...@@ -435,15 +451,15 @@ class Solarium_Query_Select extends Solarium_Query
} }
/** /**
* Remove a single filterquery by tag * Remove a single filterquery by key
* *
* @param string $tag * @param string $key
* @return Solarium_Query Provides fluent interface * @return Solarium_Query Provides fluent interface
*/ */
public function removeFilterQuery($tag) public function removeFilterQuery($key)
{ {
if (isset($this->_filterQueries[$tag])) { if (isset($this->_filterQueries[$key])) {
unset($this->_filterQueries[$tag]); unset($this->_filterQueries[$key]);
} }
return $this; return $this;
...@@ -471,4 +487,104 @@ class Solarium_Query_Select extends Solarium_Query ...@@ -471,4 +487,104 @@ class Solarium_Query_Select extends Solarium_Query
$this->addFilterQueries($filterQueries); $this->addFilterQueries($filterQueries);
} }
/**
* Add a facet
*
* @param Solarium_Query_Select_Facet $facet
* @return Solarium_Query Provides fluent interface
*/
public function addFacet($facet)
{
$key = $facet->getKey();
if (0 === strlen($key)) {
throw new Solarium_Exception('A facet must have a key value');
}
if (array_key_exists($key, $this->_facets)) {
throw new Solarium_Exception('A facet must have a unique key value'
. ' within a query');
}
$this->_facets[$key] = $facet;
return $this;
}
/**
* Add multiple facets
*
* @param array $facets
* @return Solarium_Query Provides fluent interface
*/
public function addFacets(array $facets)
{
foreach ($facets AS $facet) {
$this->addFacet($facet);
}
return $this;
}
/**
* Get a facet
*
* @param string $key
* @return string
*/
public function getFacet($key)
{
if (isset($this->_facet[$key])) {
return $this->_facet[$key];
} else {
return null;
}
}
/**
* Get all facets
*
* @return array
*/
public function getFacets()
{
return $this->_facets;
}
/**
* Remove a single facet by key
*
* @param string $key
* @return Solarium_Query Provides fluent interface
*/
public function removeFacet($key)
{
if (isset($this->_facet[$key])) {
unset($this->_facet[$key]);
}
return $this;
}
/**
* Remove all facets
*
* @return Solarium_Query Provides fluent interface
*/
public function clearFacets()
{
$this->_facets = array();
return $this;
}
/**
* Set multiple facets at once, overwriting any existing facets
*
* @param array $facets
*/
public function setFacets($facets)
{
$this->clearFacets();
$this->addFacets($facets);
}
} }
\ 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.
*/
/**
* Facet query
*/
abstract class Solarium_Query_Select_Facet extends Solarium_Configurable
{
/**
* Constants for the facet types
*/
const QUERY = 'query';
const FIELD = 'field';
/**
* Exclude tags for this facet
*
* @var array
*/
protected $_excludes = array();
/**
* Must be implemented by the facet types and return one of the constants
*
* @abstract
* @return string
*/
abstract public function getType();
/**
* Initialize options
*
* @return void
*/
protected function _init()
{
foreach ($this->_options AS $name => $value) {
switch ($name) {
case 'exclude':
$this->setExcludes($value);
break;
}
}
}
/**
* Get key value
*
* @return string
*/
public function getKey()
{
return $this->getOption('key');
}
/**
* Set key value
*
* @param string $value
* @return Solarium_Query_Select_Facet Provides fluent interface
*/
public function setKey($value)
{
return $this->_setOption('key', $value);
}
/**
* Add an exclude tag
*
* @param string $tag
* @return Solarium_Query_Select_Facet Provides fluent interface
*/
public function addExclude($exclude)
{
$this->_excludes[$exclude] = true;
return $this;
}
/**
* Add multiple exclude tags
*
* @param array $excludes
* @return Solarium_Query_Select_Facet Provides fluent interface
*/
public function addExcludes(array $excludes)
{
foreach ($excludes AS $exclude) {
$this->addExclude($exclude);
}
return $this;
}
/**
* Get all excludes
*
* @return array
*/
public function getExcludes()
{
return array_keys($this->_excludes);
}
/**
* Remove a single exclude tag
*
* @param string $exclude
* @return Solarium_Query_Select_Facet Provides fluent interface
*/
public function removeExclude($exclude)
{
if (isset($this->_excludes[$exclude])) {
unset($this->_excludes[$exclude]);
}
return $this;
}
/**
* Remove all excludes
*
* @return Solarium_Query_Select_Facet Provides fluent interface
*/
public function clearExcludes()
{
$this->_excludes = array();
return $this;
}
/**
* Set multiple excludes at once, overwriting any existing excludes
*
* @param array $excludes
*/
public function setExcludes($excludes)
{
$this->clearExcludes();
$this->addExcludes($excludes);
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Facet query
*/
class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet
{
/**
* Facet sort types
*/
const SORT_INDEX = 'index';
const SORT_COUNT = 'count';
/**
* Facet methods
*/
const METHOD_ENUM = 'enum';
const METHOD_FC = 'fc';
/**
* Default options
*
* @var array
*/
protected $_options = array(
'field' => 'id'
);
/**
* @return string
*/
public function getType()
{
return self::FIELD;
}
/**
* Set the field name
*
* @param string $query
* @return Solarium_Query_Select_Facet_Field Provides fluent interface
*/
public function setField($field)
{
return $this->_setOption('field', $field);
}
/**
* Get the field name
*
* @return string
*/
public function getField()
{
return $this->getOption('field');
}
/**
* Set the facet sort order (use one of the constants)
*
* @param string $sort
* @return Solarium_Query_Select_Facet_Field Provides fluent interface
*/
public function setSort($sort)
{
return $this->_setOption('sort', $sort);
}
/**
* Get the facet sort order
*
* @return string
*/
public function getSort()
{
return $this->getOption('sort');
}
/**
* Limit the terms for faceting by a prefix
*
* @param string $prefix
* @return Solarium_Query_Select_Facet_Field Provides fluent interface
*/
public function setPrefix($prefix)
{
return $this->_setOption('prefix', $prefix);
}
/**
* Get the facet prefix
*
* @return string
*/
public function getPrefix()
{
return $this->getOption('prefix');
}
/**
* Set the facet limit
*
* @param int $limit
* @return Solarium_Query_Select_Facet_Field Provides fluent interface
*/
public function setLimit($limit)
{
return $this->_setOption('limit', $limit);
}
/**
* Get the facet limit
*
* @return string
*/
public function getLimit()
{
return $this->getOption('limit');
}
/**
* Set the facet offset
*
* @param int $offset
* @return Solarium_Query_Select_Facet_Field Provides fluent interface
*/
public function setOffset($offset)
{
return $this->_setOption('offset', $offset);
}
/**
* Get the facet offset
*
* @return int
*/
public function getOffset()
{
return $this->getOption('offset');
}
/**
* Set the facet mincount
*
* @param int $mincount
* @return Solarium_Query_Select_Facet_Field Provides fluent interface
*/
public function setMinCount($minCount)
{
return $this->_setOption('mincount', $minCount);
}
/**
* Get the facet mincount
*
* @return int
*/
public function getMinCount()
{
return $this->getOption('mincount');
}
/**
* Set the missing count option
*
* @param boolean $missing
* @return Solarium_Query_Select_Facet_Field Provides fluent interface
*/
public function setMissing($missing)
{
return $this->_setOption('missing', $missing);
}
/**
* Get the facet missing option
*
* @return boolean
*/
public function getMissing()
{
return $this->getOption('missing');
}
/**
* Set the facet method (use one of the constants as value)
*
* @param string $method
* @return Solarium_Query_Select_Facet_Field Provides fluent interface
*/
public function setMethod($method)
{
return $this->_setOption('method', $method);
}
/**
* Get the facet method
*
* @return string
*/
public function getMethod()
{
return $this->getOption('method');
}
}
\ 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.
*/
/**
* Facet query
*/
class Solarium_Query_Select_Facet_Query extends Solarium_Query_Select_Facet
{
/**
* Default options
*
* @var array
*/
protected $_options = array(
'query' => '*:*'
);
/**
* @return string
*/
public function getType()
{
return self::QUERY;
}
/**
* Set the query string (overwrites the current value)
*
* @param string $query
* @return Solarium_Query_Select_Facet_Query Provides fluent interface
*/
public function setQuery($query)
{
return $this->_setOption('query', $query);
}
/**
* Get the query string
*
* @return string
*/
public function getQuery()
{
return $this->getOption('query');
}
}
\ 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.
*/
/**
* Filterquery
*/
abstract class Solarium_Query_Select_FilterQuery extends Solarium_Configurable
{
/**
* Tags for this filterquery
*
* @var array
*/
protected $_tags = array();
/**
* Query
*
* @var string
*/
protected $_query;
/**
* Initialize options
*
* @return void
*/
protected function _init()
{
foreach ($this->_options AS $name => $value) {
switch ($name) {
case 'tag':
$this->addTags($value);
break;
case 'query':
$this->setQuery($value);
break;
}
}
}
/**
* Get key value
*
* @return string
*/
public function getKey()
{
return $this->getOption('key');
}
/**
* Set key value
*
* @param string $value
* @return Solarium_Query_Select_FilterQuery Provides fluent interface
*/
public function setKey($value)
{
return $this->_setOption('key', $value);
}
/**
* Set the query string (overwrites the current value)
*
* @param string $query
* @return Solarium_Query Provides fluent interface
*/
public function setQuery($query)
{
$this->_query = trim($query);
return $this;
}
/**
* Get the query string
*
* @return string
*/
public function getQuery()
{
return $this->_query;
}
/**
* Add a tag
*
* @param string $tag
* @return Solarium_Query_Select_FilterQuery Provides fluent interface
*/
public function addTag($tag)
{
$this->_tags[$tag] = true;
return $this;
}
/**
* Add tags
*
* @param array $tags
* @return Solarium_Query_Select_FilterQuery Provides fluent interface
*/
public function addTags($tags)
{
foreach ($tags AS $tag) {
$this->addTag($tag);
}
return $this;
}
/**
* Get all tagss
*
* @return array
*/
public function getTags()
{
return array_keys($this->_tags);
}
/**
* Remove a tag
*
* @param string $tag
* @return Solarium_Query_Select_FilterQuery Provides fluent interface
*/
public function removeTag($tag)
{
if (isset($this->_tags[$tag])) {
unset($this->_tags[$tag]);
}
return $this;
}
/**
* Remove all tags
*
* @return Solarium_Query_Select_FilterQuery Provides fluent interface
*/
public function clearTags()
{
$this->_tags = array();
return $this;
}
/**
* Set multiple tags at once, overwriting any existing tags
*
* @param array $filterQueries
* @return Solarium_Query_Select_FilterQuery Provides fluent interface
*/
public function setTags($filterQueries)
{
$this->clearTags();
return $this->addTags($filterQueries);
}
}
\ No newline at end of file
...@@ -74,7 +74,7 @@ class Solarium_Query_Update extends Solarium_Query ...@@ -74,7 +74,7 @@ class Solarium_Query_Update extends Solarium_Query
*/ */
public function add($key, $command) public function add($key, $command)
{ {
if (!empty($key)) { if (0 !== strlen($key)) {
$this->_commands[$key] = $command; $this->_commands[$key] = $command;
} else { } else {
$this->_commands[] = $command; $this->_commands[] = $command;
......
...@@ -50,6 +50,13 @@ class Solarium_Result_Select implements Iterator, Countable ...@@ -50,6 +50,13 @@ class Solarium_Result_Select implements Iterator, Countable
*/ */
protected $_documents; protected $_documents;
/**
* Facet result instances
*
* @var array
*/
protected $_facets;
/** /**
* Pointer to document array position for iterator implementation * Pointer to document array position for iterator implementation
* *
...@@ -63,12 +70,14 @@ class Solarium_Result_Select implements Iterator, Countable ...@@ -63,12 +70,14 @@ class Solarium_Result_Select implements Iterator, Countable
* *
* @param int $numFound * @param int $numFound
* @param array $documents * @param array $documents
* @param array $facets
* @return void * @return void
*/ */
public function __construct($numFound, $documents) public function __construct($numFound, $documents, $facets)
{ {
$this->_numFound = $numFound; $this->_numFound = $numFound;
$this->_documents = $documents; $this->_documents = $documents;
$this->_facets = $facets;
} }
/** /**
...@@ -92,6 +101,31 @@ class Solarium_Result_Select implements Iterator, Countable ...@@ -92,6 +101,31 @@ class Solarium_Result_Select implements Iterator, Countable
return $this->_documents; return $this->_documents;
} }
/**
* Return all facet results in an array
*
* @return array
*/
public function getFacets()
{
return $this->_facets;
}
/**
* Return a facet result
*
* @param string $key
* @return Solarium_Result_Select_Facet
*/
public function getFacet($key)
{
if (isset($this->_facets[$key])) {
return $this->_facets[$key];
} else {
return null;
}
}
/** /**
* Count method for Countable interface * Count method for Countable interface
* *
......
<?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.
*/
/**
* Select query facet result
*/
class Solarium_Result_Select_Facet_Field implements Iterator, Countable
{
/**
* Pointer to document array position for iterator implementation
*
* @var int
*/
protected $_position;
/**
* Value array
*
* @var array
*/
protected $_values;
/**
* Constructor
*
* @param array $values
* @return void
*/
public function __construct($values)
{
$this->_values = $values;
}
/**
* Get all values
*
* @return array
*/
public function getValues()
{
return $this->_values;
}
/**
* Count method for Countable interface
*
* @return int
*/
public function count()
{
return count($this->_values);
}
/**
* Iterator implementation
*
* @return void
*/
public function rewind()
{
$this->_position = 0;
}
/**
* Iterator implementation
*
* @return Solarium_Result_Select_Document
*/
function current()
{
return $this->_values[$this->_position];
}
/**
* Iterator implementation
*
* @return integer
*/
public function key()
{
return $this->_position;
}
/**
* Iterator implementation
*
* @return void
*/
public function next()
{
++$this->_position;
}
/**
* Iterator implementation
*
* @return boolean
*/
public function valid()
{
return isset($this->_values[$this->_position]);
}
}
\ 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.
*/
/**
* Select query facet result
*/
class Solarium_Result_Select_Facet_Query
{
/**
* Value
*
* @var mixed
*/
protected $_value;
/**
* Constructor
*
* @param array $values
* @return void
*/
public function __construct($value)
{
$this->_value = $value;
}
/**
* Get the value
*
* @return mixed
*/
public function getValue()
{
return $this->_value;
}
}
\ No newline at end of file
...@@ -82,8 +82,8 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase ...@@ -82,8 +82,8 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
{ {
$this->_query->addSortField('id', Solarium_Query_Select::SORT_ASC); $this->_query->addSortField('id', Solarium_Query_Select::SORT_ASC);
$this->_query->addSortField('name', Solarium_Query_Select::SORT_DESC); $this->_query->addSortField('name', Solarium_Query_Select::SORT_DESC);
$this->_query->addFilterQuery('f1', 'published:true'); $this->_query->addFilterQuery(new Solarium_Query_Select_FilterQuery(array('key' => 'f1', 'query' => 'published:true')));
$this->_query->addFilterQuery('f2', 'category:23'); $this->_query->addFilterQuery(new Solarium_Query_Select_FilterQuery(array('key' => 'f2', 'query' => 'category:23')));
$request = new Solarium_Client_Request_Select($this->_options, $this->_query); $request = new Solarium_Client_Request_Select($this->_options, $this->_query);
$this->assertEquals( $this->assertEquals(
...@@ -96,4 +96,21 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase ...@@ -96,4 +96,21 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
$request->getUrl() $request->getUrl()
); );
} }
public function testSelectUrlWithFacets()
{
$this->_query->addFacet(new Solarium_Query_Select_Facet_Field(array('key' => 'f1', 'field' => 'owner')));
$this->_query->addFacet(new Solarium_Query_Select_Facet_Query(array('key' => 'f2', 'query' => 'category:23')));
$request = new Solarium_Client_Request_Select($this->_options, $this->_query);
$this->assertEquals(
null,
$request->getPostData()
);
$this->assertEquals(
'http://127.0.0.1:80/solr/select?q=%2A%3A%2A&start=0&rows=10&fl=%2A%2Cscore&wt=json&facet=true',
$request->getUrl()
);
}
} }
...@@ -115,7 +115,53 @@ class Solarium_Client_RequestTest extends PHPUnit_Framework_TestCase ...@@ -115,7 +115,53 @@ class Solarium_Client_RequestTest extends PHPUnit_Framework_TestCase
$this->_getRequest($this->_options, 'TestRequest')->getPostdata() $this->_getRequest($this->_options, 'TestRequest')->getPostdata()
); );
} }
public function testRenderLocalParams()
{
$myParams = array('tag' => 'mytag', 'ex' => array('exclude1','exclude2'));
$query = new Solarium_Query();
$this->assertEquals(
'{!tag=mytag ex=myexclude1,exclude2}myValue',
$query->renderLocalParams('myValue', $myParams)
);
}
public function testAddParamWithNewParam()
{
$request = $this->_getRequest($this->_options);
$request->addParam('myparam',1);
$this->assertEquals(
$request->getParams(),
array('myparam' => 1)
);
}
public function testAddParamNoValue()
{
$request = $this->_getRequest($this->_options);
$request->addParam('myparam',1);
$request->addParam('mysecondparam',"");
$this->assertEquals(
$request->getParams(),
array('myparam' => 1)
);
}
public function testAddParamWithExistingParam()
{
$request = $this->_getRequest($this->_options);
$request->addParam('myparam',1);
$request->addParam('myparam',2);
$this->assertEquals(
$request->getParams(),
array('myparam' => array(1,2))
);
}
} }
class TestRequest extends Solarium_Client_Request class TestRequest extends Solarium_Client_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.
*/
class Solarium_Client_Response_PingTest extends PHPUnit_Framework_TestCase
{
public function testGetResult()
{
$query = new Solarium_Query_Ping;
$response = new Solarium_Client_Response_Ping($query);
$this->assertThat($response->getResult(), $this->isInstanceOf($query->getResultClass()));
}
public function testGetResultWithCustomClass()
{
$query = new Solarium_Query_Ping;
$query->setResultClass('MyPingResult');
$response = new Solarium_Client_Response_Ping($query);
$this->assertThat($response->getResult(), $this->isInstanceOf($query->getResultClass()));
}
}
class MyPingResult extends Solarium_Result_Ping{
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Client_Response_SelectTest extends PHPUnit_Framework_TestCase
{
public function testGetResult()
{
$query = new Solarium_Query_Select;
$response = new Solarium_Client_Response_Ping($query);
$this->assertThat($response->getResult(), $this->isInstanceOf($query->getResultClass()));
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Client_Response_UpdateTest extends PHPUnit_Framework_TestCase
{
public function testGetResult()
{
$query = new Solarium_Query_Ping;
$data = array('responseheader' => array('status' => 0, 'QTime' => 145));
$response = new Solarium_Client_Response_Ping($query, $data);
$result = $response->getResult();
$this->assertEquals(
0,
$result->getStatus()
);
$this->assertEquals(
145,
$result->getQueryTime()
);
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Client_ResponseTest extends PHPUnit_Framework_TestCase
{
public function testConstructor()
{
$query = new Solarium_Query_Ping;
$data = array('response' => null);
$response = new MyTestResponse($query, $data);
$this->assertEquals(
array($query, $data),
$response->getResult()
);
}
}
class MyTestResponse extends Solarium_Client_Response
{
public function getResult()
{
return array($this->_query, $this->_data);
}
}
\ No newline at end of file
...@@ -43,7 +43,20 @@ class Solarium_ConfigurableTest extends PHPUnit_Framework_TestCase ...@@ -43,7 +43,20 @@ class Solarium_ConfigurableTest extends PHPUnit_Framework_TestCase
$this->assertEquals($configTest->getOptions(), $defaultOptions); $this->assertEquals($configTest->getOptions(), $defaultOptions);
} }
//TODO testConstructorWithZendConfig public function testConstructorWithObject()
{
$configTest = new ConfigTest(new myConfigObject);
// the default options should be merged with the constructor values,
// overwriting any default values.
$expectedOptions = array(
'option1' => 1,
'option2' => 'newvalue2',
'option3' => 3,
);
$this->assertEquals($expectedOptions, $configTest->getOptions());
}
public function testConstructorWithArrayConfig() public function testConstructorWithArrayConfig()
{ {
...@@ -88,7 +101,8 @@ class Solarium_ConfigurableTest extends PHPUnit_Framework_TestCase ...@@ -88,7 +101,8 @@ class Solarium_ConfigurableTest extends PHPUnit_Framework_TestCase
} }
class ConfigTest extends Solarium_Configurable{ class ConfigTest extends Solarium_Configurable
{
protected $_options = array( protected $_options = array(
'option1' => 1, 'option1' => 1,
...@@ -97,11 +111,20 @@ class ConfigTest extends Solarium_Configurable{ ...@@ -97,11 +111,20 @@ class ConfigTest extends Solarium_Configurable{
} }
class ConfigTestInit extends ConfigTest{ class ConfigTestInit extends ConfigTest
{
protected function _init() protected function _init()
{ {
throw new Solarium_Exception('test init'); throw new Solarium_Exception('test init');
} }
}
class myConfigObject
{
public function toArray()
{
return array('option2' => 'newvalue2', 'option3' => 3);
}
} }
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Query_Select_Facet_FieldTest extends PHPUnit_Framework_TestCase
{
public function testGetType()
{
//TODO
}
public function testSetAndGetField()
{
//TODO
}
public function testSetAndGetSort()
{
//TODO
}
public function testSetAndGetPrefix()
{
//TODO
}
public function testSetAndGetLimit()
{
//TODO
}
public function testSetAndGetOffset()
{
//TODO
}
public function testSetAndGetMinCount()
{
//TODO
}
public function testSetAndGetMissing()
{
//TODO
}
public function testSetAndGetMethod()
{
//TODO
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Query_Select_Facet_QueryTest extends PHPUnit_Framework_TestCase
{
public function testSetAndGetQuery()
{
//TODO
}
public function testGetType()
{
//TODO
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Query_Select_FacetTest extends PHPUnit_Framework_TestCase
{
public function testSetAndGetKey()
{
//TODO
}
public function testAddExclude()
{
//TODO
}
public function testAddExcludes()
{
//TODO
}
public function testRemoveExclude()
{
//TODO
}
public function testClearExcludes()
{
//TODO
}
public function testSetExcludes()
{
//TODO
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Query_Select_FilterQueryTest extends PHPUnit_Framework_TestCase
{
public function testSetAndGetKey()
{
//TODO
}
public function testSetAndGetQuery()
{
//TODO
}
public function testAddTag()
{
//TODO
}
public function testAddTags()
{
//TODO
}
public function testRemoveTags()
{
//TODO
}
public function testClearTags()
{
//TODO
}
public function testSetTags()
{
//TODO
}
}
...@@ -201,13 +201,38 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase ...@@ -201,13 +201,38 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
public function testAddAndGetFilterQuery() public function testAddAndGetFilterQuery()
{ {
$this->_query->addFilterQuery('fq1', 'category:1'); $fq = new Solarium_Query_Select_FilterQuery;
$fq->setKey('fq1')->setQuery('category:1');
$this->_query->addFilterQuery($fq);
$this->assertEquals( $this->assertEquals(
'category:1', $fq,
$this->_query->getFilterQuery('fq1') $this->_query->getFilterQuery('fq1')
); );
} }
public function testAddFilterQueryWithoutKey()
{
$fq = new Solarium_Query_Select_FilterQuery;
$fq->setQuery('category:1');
$this->setExpectedException('Solarium_Exception');
$this->_query->addFilterQuery($fq);
}
public function testAddFilterQueryWithUsedKey()
{
$fq1 = new Solarium_Query_Select_FilterQuery;
$fq1->setKey('fq1')->setQuery('category:1');
$fq2 = new Solarium_Query_Select_FilterQuery;
$fq2->setKey('fq1')->setQuery('category:2');
$this->_query->addFilterQuery($fq1);
$this->setExpectedException('Solarium_Exception');
$this->_query->addFilterQuery($fq2);
}
public function testGetInvalidFilterQuery() public function testGetInvalidFilterQuery()
{ {
$this->assertEquals( $this->assertEquals(
...@@ -218,10 +243,13 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase ...@@ -218,10 +243,13 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
public function testAddFilterQueries() public function testAddFilterQueries()
{ {
$filterQueries = array( $fq1 = new Solarium_Query_Select_FilterQuery;
'fq1' => 'category:1', $fq1->setKey('fq1')->setQuery('category:1');
'fq2' => 'group:2'
); $fq2 = new Solarium_Query_Select_FilterQuery;
$fq2->setKey('fq2')->setQuery('category:2');
$filterQueries = array($fq1, $fq2);
$this->_query->addFilterQueries($filterQueries); $this->_query->addFilterQueries($filterQueries);
$this->assertEquals( $this->assertEquals(
...@@ -232,25 +260,31 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase ...@@ -232,25 +260,31 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
public function testRemoveFilterQuery() public function testRemoveFilterQuery()
{ {
$filterQueries = array( $fq1 = new Solarium_Query_Select_FilterQuery;
'fq1' => 'category:1', $fq1->setKey('fq1')->setQuery('category:1');
'fq2' => 'group:2'
); $fq2 = new Solarium_Query_Select_FilterQuery;
$fq2->setKey('fq2')->setQuery('category:2');
$filterQueries = array($fq1, $fq2);
$this->_query->addFilterQueries($filterQueries); $this->_query->addFilterQueries($filterQueries);
$this->_query->removeFilterQuery('fq1'); $this->_query->removeFilterQuery('fq1');
$this->assertEquals( $this->assertEquals(
array('fq2' => 'group:2'), array($fq1),
$this->_query->getFilterQueries() $this->_query->getFilterQueries()
); );
} }
public function testRemoveInvalidFilterQuery() public function testRemoveInvalidFilterQuery()
{ {
$filterQueries = array( $fq1 = new Solarium_Query_Select_FilterQuery;
'fq1' => 'category:1', $fq1->setKey('fq1')->setQuery('category:1');
'fq2' => 'group:2'
); $fq2 = new Solarium_Query_Select_FilterQuery;
$fq2->setKey('fq2')->setQuery('category:2');
$filterQueries = array($fq1, $fq2);
$this->_query->addFilterQueries($filterQueries); $this->_query->addFilterQueries($filterQueries);
$this->_query->removeFilterQuery('fq3'); //continue silently $this->_query->removeFilterQuery('fq3'); //continue silently
...@@ -262,10 +296,13 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase ...@@ -262,10 +296,13 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
public function testClearFilterQueries() public function testClearFilterQueries()
{ {
$filterQueries = array( $fq1 = new Solarium_Query_Select_FilterQuery;
'fq1' => 'category:1', $fq1->setKey('fq1')->setQuery('category:1');
'fq2' => 'group:2'
); $fq2 = new Solarium_Query_Select_FilterQuery;
$fq2->setKey('fq2')->setQuery('category:2');
$filterQueries = array($fq1, $fq2);
$this->_query->addFilterQueries($filterQueries); $this->_query->addFilterQueries($filterQueries);
$this->_query->clearFilterQueries(); $this->_query->clearFilterQueries();
...@@ -277,21 +314,31 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase ...@@ -277,21 +314,31 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
public function testSetFilterQueries() public function testSetFilterQueries()
{ {
$filterQueries = array( $fq1 = new Solarium_Query_Select_FilterQuery;
'fq1' => 'category:1', $fq1->setKey('fq1')->setQuery('category:1');
'fq2' => 'group:2'
);
$this->_query->addFilterQueries($filterQueries);
$newFilterQueries = array( $fq2 = new Solarium_Query_Select_FilterQuery;
'fq3' => 'category:2', $fq2->setKey('fq2')->setQuery('category:2');
'fq4' => 'group:3'
); $filterQueries1 = array($fq1, $fq2);
$this->_query->setFilterQueries($newFilterQueries);
$this->_query->addFilterQueries($filterQueries1);
$fq3 = new Solarium_Query_Select_FilterQuery;
$fq3->setKey('fq3')->setQuery('category:3');
$fq4 = new Solarium_Query_Select_FilterQuery;
$fq4->setKey('fq4')->setQuery('category:4');
$filterQueries2 = array($fq3, $fq4);
$this->_query->setFilterQueries($filterQueries2);
$this->assertEquals( $this->assertEquals(
$newFilterQueries, $filterQueries2,
$this->_query->getFilterQueries() $this->_query->getFilterQueries()
); );
} }
//TODO test facet methods
} }
...@@ -63,17 +63,5 @@ class Solarium_QueryTest extends PHPUnit_Framework_TestCase ...@@ -63,17 +63,5 @@ class Solarium_QueryTest extends PHPUnit_Framework_TestCase
$query->renderLocalParams('myValue') $query->renderLocalParams('myValue')
); );
} }
public function testRenderLocalParams()
{
$myParams = array('tag' => 'mytag', 'ex' => 'myexclude');
$query = new Solarium_Query();
$this->assertEquals(
'{!tag=mytag ex=myexclude}myValue',
$query->renderLocalParams('myValue', $myParams)
);
}
} }
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Result_Select_Facet_FieldTest extends PHPUnit_Framework_TestCase
{
protected $_values, $_facet;
public function setUp()
{
$this->_values = array(
'a' => 12,
'b' => 5,
'c' => 3,
);
$this->_facet = new Solarium_Result_Select_Facet_Query($this->_values);
}
public function testGetValues()
{
$this->assertEquals($this->_values, $this->_facet->getValues());
}
public function testCount()
{
$this->assertEquals(count($this->_values), $this->_facet->count());
}
public function testIterator()
{
$values = array();
foreach($this->_facet->getValues() AS $key => $value)
{
$values[$key] = $value;
}
$this->assertEquals($this->_values, $values);
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Result_Select_Facet_QueryTest extends PHPUnit_Framework_TestCase
{
public function testGetValue()
{
$facet = new Solarium_Result_Select_Facet_Query(124);
$this->assertEquals(124, $facet->getValue());
}
}
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
{ {
protected $_result; protected $_result, $_docs, $_facets;
public function setUp() public function setUp()
{ {
...@@ -41,7 +41,13 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase ...@@ -41,7 +41,13 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
new Solarium_Document_ReadOnly(array('id'=>2,'name'=>'test2')), new Solarium_Document_ReadOnly(array('id'=>2,'name'=>'test2')),
new Solarium_Document_ReadOnly(array('id'=>3,'name'=>'test3')), new Solarium_Document_ReadOnly(array('id'=>3,'name'=>'test3')),
); );
$this->_result = new Solarium_Result_Select(100, $this->_docs);
$this->_facets = array(
'f1' => new Solarium_Result_Select_Facet_Field(array('a' => 14)),
'f2' => new Solarium_Result_Select_Facet_Field(array('b' => 5)),
);
$this->_result = new Solarium_Result_Select(100, $this->_docs, $this->_facets);
} }
public function testGetNumFound() public function testGetNumFound()
...@@ -54,6 +60,16 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase ...@@ -54,6 +60,16 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
$this->assertEquals($this->_docs, $this->_result->getDocuments()); $this->assertEquals($this->_docs, $this->_result->getDocuments());
} }
public function testGetFacets()
{
$this->assertEquals($this->_facets, $this->_result->getFacets());
}
public function testGetFacetByKey()
{
$this->assertEquals($this->_docs['f2'], $this->_result->getFacet('f2'));
}
public function testCount() public function testCount()
{ {
$this->assertEquals(3, $this->_result->count()); $this->assertEquals(3, $this->_result->count());
......
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