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

Merge branch 'feature/facet-improvements' into develop

parents 31dc7f69 114f3b2c
...@@ -87,39 +87,66 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request ...@@ -87,39 +87,66 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
case Solarium_Query_Select_Component::MORELIKETHIS: case Solarium_Query_Select_Component::MORELIKETHIS:
$this->addMoreLikeThis($component); $this->addMoreLikeThis($component);
break; break;
case Solarium_Query_Select_Component::FACETSET:
$this->addFacetSet($component);
break;
case Solarium_Query_Select_Component::DISMAX:
$this->addDisMax($component);
break;
default: default:
throw new Solarium_Exception('Unknown component type'); throw new Solarium_Exception('Unknown component type');
} }
} }
$facets = $this->_query->getFacets(); return $this->buildUri();
}
/**
* @throws Solarium_Exception
* @param Solarium_Query_Select_Component_FacetSet $facetSet
* @return void
*/
public function addFacetSet($facetSet)
{
$facets = $facetSet->getFacets();
if (count($facets) !== 0) { if (count($facets) !== 0) {
// enable faceting // enable faceting
$this->_params['facet'] = 'true'; $this->_params['facet'] = 'true';
// global facet params
$this->addParam('facet.sort', $facetSet->getSort());
$this->addParam('facet.prefix', $facetSet->getPrefix());
$this->addParam('facet.missing', $facetSet->getMissing());
$this->addParam('facet.mincount', $facetSet->getMinCount());
$this->addParam('facet.limit', $facetSet->getLimit());
foreach ($facets AS $facet) { foreach ($facets AS $facet) {
switch ($facet->getType()) switch ($facet->getType())
{ {
case Solarium_Query_Select_Facet::FIELD: case Solarium_Query_Select_Component_Facet::FIELD:
$this->addFacetField($facet); $this->addFacetField($facet);
break; break;
case Solarium_Query_Select_Facet::QUERY: case Solarium_Query_Select_Component_Facet::QUERY:
$this->addFacetQuery($facet); $this->addFacetQuery($facet);
break; break;
case Solarium_Query_Select_Component_Facet::MULTIQUERY:
$this->addFacetMultiQuery($facet);
break;
case Solarium_Query_Select_Component_Facet::RANGE:
$this->addFacetRange($facet);
break;
default: default:
throw new Solarium_Exception('Unknown facet type'); throw new Solarium_Exception('Unknown facet type');
} }
} }
} }
return $this->buildUri();
} }
/** /**
* Add params for a field facet to request * Add params for a field facet to request
* *
* @param mixed $facet * @param Solarium_Query_Select_Component_Facet_Field $facet
* @return void * @return void
*/ */
public function addFacetField($facet) public function addFacetField($facet)
...@@ -144,9 +171,9 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request ...@@ -144,9 +171,9 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
} }
/** /**
* Add params for a field query to request * Add params for a facet query to request
* *
* @param mixed $facet * @param Solarium_Query_Select_Component_Facet_Query $facet
* @return void * @return void
*/ */
public function addFacetQuery($facet) public function addFacetQuery($facet)
...@@ -160,6 +187,53 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request ...@@ -160,6 +187,53 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
); );
} }
/**
* Add params for a multiquery facet to request
*
* @param Solarium_Query_Select_Component_Facet_MultiQuery $facet
* @return void
*/
public function addFacetMultiQuery($facet)
{
foreach ($facet->getQueries() AS $facetQuery) {
$this->addFacetQuery($facetQuery);
}
}
/**
* Add params for a range facet to request
*
* @param Solarium_Query_Select_Component_Facet_Range $facet
* @return void
*/
public function addFacetRange($facet)
{
$field = $facet->getField();
$this->addParam(
'facet.range',
$this->renderLocalParams(
$field,
array('key' => $facet->getKey(), 'ex' => $facet->getExcludes())
)
);
$this->addParam("f.$field.facet.range.start", $facet->getStart());
$this->addParam("f.$field.facet.range.end", $facet->getEnd());
$this->addParam("f.$field.facet.range.gap", $facet->getGap());
$this->addParam("f.$field.facet.range.hardend", $facet->getHardend());
$other = explode(',', $facet->getOther());
foreach ($other AS $otherValue) {
$this->addParam("f.$field.facet.range.other", trim($otherValue));
}
$include = explode(',', $facet->getInclude());
foreach ($include AS $includeValue) {
$this->addParam("f.$field.facet.range.include", trim($includeValue));
}
}
/** /**
* Add params for morelikethis * Add params for morelikethis
* *
...@@ -183,4 +257,26 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request ...@@ -183,4 +257,26 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
$this->addParam('mlt.count', $component->getCount()); $this->addParam('mlt.count', $component->getCount());
} }
/**
* Add params for DisMax
*
* @param Solarium_Query_Select_Component_DisMax $component
* @return void
*/
public function addDisMax($component)
{
// enable dismax
$this->_params['defType'] = 'dismax';
$this->addParam('q.alt', $component->getQueryAlternative());
$this->addParam('qf', $component->getQueryFields());
$this->addParam('mm', $component->getMinimumMatch());
$this->addParam('pf', $component->getPhraseFields());
$this->addParam('ps', $component->getPhraseSlop());
$this->addParam('qs', $component->getQueryPhraseSlop());
$this->addParam('tie', $component->getTie());
$this->addParam('bq', $component->getBoostQuery());
$this->addParam('bf', $component->getBoostFunctions());
}
} }
\ No newline at end of file
...@@ -89,22 +89,14 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response ...@@ -89,22 +89,14 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
case Solarium_Query_Select_Component::MORELIKETHIS: case Solarium_Query_Select_Component::MORELIKETHIS:
$this->_addMoreLikeThis($component); $this->_addMoreLikeThis($component);
break; break;
default: case Solarium_Query_Select_Component::FACETSET:
throw new Solarium_Exception('Unknown component type'); $this->_addFacetSet($component);
}
}
// create facet results
foreach ($this->_query->getFacets() AS $facet) {
switch ($facet->getType()) {
case Solarium_Query_Select_Facet::FIELD:
$this->_addFacetField($facet);
break; break;
case Solarium_Query_Select_Facet::QUERY: case Solarium_Query_Select_Component::DISMAX:
$this->_addFacetQuery($facet); // no result action needed
break; break;
default: default:
throw new Solarium_Exception('Unknown facet type'); throw new Solarium_Exception('Unknown component type');
} }
} }
...@@ -120,10 +112,33 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response ...@@ -120,10 +112,33 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
); );
} }
protected function _addFacetSet($facetSet)
{
// create facet results
foreach ($facetSet->getFacets() AS $facet) {
switch ($facet->getType()) {
case Solarium_Query_Select_Component_Facet::FIELD:
$this->_addFacetField($facet);
break;
case Solarium_Query_Select_Component_Facet::QUERY:
$this->_addFacetQuery($facet);
break;
case Solarium_Query_Select_Component_Facet::MULTIQUERY:
$this->_addFacetMultiQuery($facet);
break;
case Solarium_Query_Select_Component_Facet::RANGE:
$this->_addFacetRange($facet);
break;
default:
throw new Solarium_Exception('Unknown facet type');
}
}
}
/** /**
* Add a facet result for a field facet * Add a facet result for a field facet
* *
* @param mixed $facet * @param Solarium_Query_Select_Component_Facet_Field $facet
* @return void * @return void
*/ */
protected function _addFacetField($facet) protected function _addFacetField($facet)
...@@ -147,9 +162,9 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response ...@@ -147,9 +162,9 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
} }
/** /**
* Add a facet result for a field query * Add a facet result for a facet query
* *
* @param mixed $facet * @param Solarium_Query_Select_Component_Facet_Query $facet
* @return void * @return void
*/ */
protected function _addFacetQuery($facet) protected function _addFacetQuery($facet)
...@@ -163,6 +178,50 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response ...@@ -163,6 +178,50 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
} }
} }
/**
* Add a facet result for a multiquery facet
*
* @param Solarium_Query_Select_Component_Facet_MultiQuery $facet
* @return void
*/
protected function _addFacetMultiQuery($facet)
{
$values = array();
foreach ($facet->getQueries() AS $query) {
$key = $query->getKey();
if (isset($this->_data['facet_counts']['facet_queries'][$key])) {
$count = $this->_data['facet_counts']['facet_queries'][$key];
$values[$key] = $count;
}
}
$this->_facets[$facet->getKey()] =
new Solarium_Result_Select_Facet_MultiQuery($values);
}
/**
* Add a facet result for a range facet
*
* @param Solarium_Query_Select_Component_Facet_Range $facet
* @return void
*/
protected function _addFacetRange($facet)
{
$key = $facet->getKey();
if (isset($this->_data['facet_counts']['facet_ranges'][$key])) {
$data = $this->_data['facet_counts']['facet_ranges'][$key];
$before = (isset($data['before'])) ? $data['before'] : null;
$after = (isset($data['after'])) ? $data['after'] : null;
$between = (isset($data['after'])) ? $data['after'] : null;
$this->_facets[$key] =
new Solarium_Result_Select_Facet_Range($data['counts'], $before, $after, $between);
}
}
/** /**
* Add morelikethis result * Add morelikethis result
* *
......
...@@ -90,13 +90,6 @@ class Solarium_Query_Select extends Solarium_Query ...@@ -90,13 +90,6 @@ class Solarium_Query_Select extends Solarium_Query
*/ */
protected $_filterQueries = array(); protected $_filterQueries = array();
/**
* Facets
*
* @var array
*/
protected $_facets = array();
/** /**
* Search components * Search components
* *
...@@ -122,9 +115,6 @@ class Solarium_Query_Select extends Solarium_Query ...@@ -122,9 +115,6 @@ 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;
...@@ -137,6 +127,9 @@ class Solarium_Query_Select extends Solarium_Query ...@@ -137,6 +127,9 @@ class Solarium_Query_Select extends Solarium_Query
case 'start': case 'start':
$this->setStart((int)$value); $this->setStart((int)$value);
break; break;
case 'component':
$this->_createComponents($value);
break;
} }
} }
} }
...@@ -537,119 +530,6 @@ class Solarium_Query_Select extends Solarium_Query ...@@ -537,119 +530,6 @@ class Solarium_Query_Select extends Solarium_Query
$this->addFilterQueries($filterQueries); $this->addFilterQueries($filterQueries);
} }
/**
* Add a facet
*
* @param Solarium_Query_Select_Facet|array $facet
* @return Solarium_Query Provides fluent interface
*/
public function addFacet($facet)
{
if (is_array($facet)) {
$className = 'Solarium_Query_Select_Facet_'.ucfirst($facet['type']);
$facet = new $className($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 $key => $facet) {
// in case of a config array: add key to config
if (is_array($facet) && !isset($facet['key'])) {
$facet['key'] = $key;
}
$this->addFacet($facet);
}
return $this;
}
/**
* Get a facet
*
* @param string $key
* @return string
*/
public function getFacet($key)
{
if (isset($this->_facets[$key])) {
return $this->_facets[$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->_facets[$key])) {
unset($this->_facets[$key]);
}
return $this;
}
/**
* Remove all facets
*
* @return Solarium_Query Provides fluent interface
*/
public function clearFacets()
{
$this->_facets = array();
return $this;
}
/**
* Set multiple facets
*
* This overwrites any existing facets
*
* @param array $facets
*/
public function setFacets($facets)
{
$this->clearFacets();
$this->addFacets($facets);
}
/** /**
* Get all registered components * Get all registered components
* *
...@@ -668,15 +548,31 @@ class Solarium_Query_Select extends Solarium_Query ...@@ -668,15 +548,31 @@ class Solarium_Query_Select extends Solarium_Query
* *
* @param string $key Use one of the constants * @param string $key Use one of the constants
* @param string $autoload Class to autoload if component needs to be created * @param string $autoload Class to autoload if component needs to be created
* @param array $config Configuration to use for autoload
* @return object|null * @return object|null
*/ */
public function getComponent($key, $autoload = null) public function getComponent($key, $autoload = false, $config = null)
{ {
if (isset($this->_components[$key])) { if (isset($this->_components[$key])) {
return $this->_components[$key]; return $this->_components[$key];
} else { } else {
if ($autoload !== null) { if ($autoload == true) {
$component = new $autoload;
switch ($key) {
case Solarium_Query_Select_Component::MORELIKETHIS:
$className = 'Solarium_Query_Select_Component_MoreLikeThis';
break;
case Solarium_Query_Select_Component::FACETSET:
$className = 'Solarium_Query_Select_Component_FacetSet';
break;
case Solarium_Query_Select_Component::DISMAX:
$className = 'Solarium_Query_Select_Component_DisMax';
break;
default:
throw new Solarium_Exception('Cannot autoload unknown component: ' . $key);
}
$component = new $className($config);
$this->setComponent($key, $component); $this->setComponent($key, $component);
return $this->_components[$key]; return $this->_components[$key];
} }
...@@ -713,6 +609,20 @@ class Solarium_Query_Select extends Solarium_Query ...@@ -713,6 +609,20 @@ class Solarium_Query_Select extends Solarium_Query
return $this; return $this;
} }
/**
* Build component instances based on config
*
* @param array $configs
* @return void
*/
protected function _createComponents($configs)
{
foreach ($configs AS $type => $config) {
$this->getComponent($type, true, $config);
}
}
/** /**
* Get a MoreLikeThis component instance * Get a MoreLikeThis component instance
* *
...@@ -722,7 +632,31 @@ class Solarium_Query_Select extends Solarium_Query ...@@ -722,7 +632,31 @@ class Solarium_Query_Select extends Solarium_Query
*/ */
public function getMoreLikeThis() public function getMoreLikeThis()
{ {
return $this->getComponent('MoreLikeThis', 'Solarium_Query_Select_Component_MoreLikeThis'); return $this->getComponent(Solarium_Query_Select_Component::MORELIKETHIS, true);
}
/**
* Get a FacetSet component instance
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Query_Select_Component_FacetSet
*/
public function getFacetSet()
{
return $this->getComponent(Solarium_Query_Select_Component::FACETSET, true);
}
/**
* Get a DisMax component instance
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Query_Select_Component_DisMax
*/
public function getDisMax()
{
return $this->getComponent(Solarium_Query_Select_Component::DISMAX, true);
} }
} }
\ No newline at end of file
...@@ -48,6 +48,8 @@ class Solarium_Query_Select_Component extends Solarium_Configurable ...@@ -48,6 +48,8 @@ class Solarium_Query_Select_Component extends Solarium_Configurable
* Component types * Component types
*/ */
const MORELIKETHIS = 'morelikethis'; const MORELIKETHIS = 'morelikethis';
const FACETSET = 'facetset';
const DISMAX = 'dismax';
/** /**
* Component type * Component type
......
<?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
*
* @package Solarium
* @subpackage Query
*/
/**
* DisMax component
*
* @link http://wiki.apache.org/solr/DisMaxQParserPlugin
*
* @package Solarium
* @subpackage Query
*/
class Solarium_Query_Select_Component_DisMax extends Solarium_Query_Select_Component
{
/**
* Component type
*
* @var string
*/
protected $_type = self::DISMAX;
/**
* Set QueryAlternative option
*
* If specified, this query will be used (and parsed by default using
* standard query parsing syntax) when the main query string is not
* specified or blank.
*
* @param string $queryAlternative
* @return Solarium_Query_Component_DisMax Provides fluent interface
*/
public function setQueryAlternative($queryAlternative)
{
return $this->_setOption('queryalternative', $queryAlternative);
}
/**
* Get QueryAlternative option
*
* @return string|null
*/
public function getQueryAlternative()
{
return $this->getOption('queryalternative');
}
/**
* Set QueryFields option
*
* List of fields and the "boosts" to associate with each of them when
* building DisjunctionMaxQueries from the user's query.
*
* The format supported is "fieldOne^2.3 fieldTwo fieldThree^0.4"
*
* @param string $queryFields
* @return Solarium_Query_Component_DisMax Provides fluent interface
*/
public function setQueryFields($queryFields)
{
return $this->_setOption('queryfields', $queryFields);
}
/**
* Get QueryFields option
*
* @return string|null
*/
public function getQueryFields()
{
return $this->getOption('queryfields');
}
/**
* Set MinimumMatch option
*
* This option makes it possible to say that a certain minimum number of
* clauses must match. See Solr manual for details.
*
* @param string $minimumMatch
* @return Solarium_Query_Component_DisMax Provides fluent interface
*/
public function setMinimumMatch($minimumMatch)
{
return $this->_setOption('minimummatch', $minimumMatch);
}
/**
* Get MinimumMatch option
*
* @return string|null
*/
public function getMinimumMatch()
{
return $this->getOption('minimummatch');
}
/**
* Set PhraseFields option
*
* This param can be used to "boost" the score of documents in cases
* where all of the terms in the "q" param appear in close proximity.
*
* Format is: "fieldA^1.0 fieldB^2.2"
*
* @param string $phraseFields
* @return Solarium_Query_Component_DisMax Provides fluent interface
*/
public function setPhraseFields($phraseFields)
{
return $this->_setOption('phrasefields', $phraseFields);
}
/**
* Get PhraseFields option
*
* @return string|null
*/
public function getPhraseFields()
{
return $this->getOption('phrasefields');
}
/**
* Set PhraseSlop option
*
* Amount of slop on phrase queries built for "pf" fields
* (affects boosting)
*
* @param string $phraseSlop
* @return Solarium_Query_Component_DisMax Provides fluent interface
*/
public function setPhraseSlop($phraseSlop)
{
return $this->_setOption('phraseslop', $phraseSlop);
}
/**
* Get PhraseSlop option
*
* @return string|null
*/
public function getPhraseSlop()
{
return $this->getOption('phraseslop');
}
/**
* Set QueryPhraseSlop option
*
* Amount of slop on phrase queries explicitly included in the user's
* query string (in qf fields; affects matching)
*
* @param string $queryPhraseSlop
* @return Solarium_Query_Component_DisMax Provides fluent interface
*/
public function setQueryPhraseSlop($queryPhraseSlop)
{
return $this->_setOption('queryphraseslop', $queryPhraseSlop);
}
/**
* Get QueryPhraseSlop option
*
* @return string|null
*/
public function getQueryPhraseSlop()
{
return $this->getOption('queryphraseslop');
}
/**
* Set Tie option
*
* Float value to use as tiebreaker in DisjunctionMaxQueries
*
* @param float $tie
* @return Solarium_Query_Component_DisMax Provides fluent interface
*/
public function setTie($tie)
{
return $this->_setOption('tie', $tie);
}
/**
* Get Tie option
*
* @return float|null
*/
public function getTie()
{
return $this->getOption('tie');
}
/**
* Set BoostQuery option
*
* A raw query string (in the SolrQuerySyntax) that will be included
* with the user's query to influence the score.
*
* @param string $boostQuery
* @return Solarium_Query_Component_DisMax Provides fluent interface
*/
public function setBoostQuery($boostQuery)
{
return $this->_setOption('boostquery', $boostQuery);
}
/**
* Get BoostQuery option
*
* @return string|null
*/
public function getBoostQuery()
{
return $this->getOption('boostquery');
}
/**
* Set BoostFunctions option
*
* Functions (with optional boosts) that will be included in the
* user's query to influence the score.
*
* Format is: "funcA(arg1,arg2)^1.2 funcB(arg3,arg4)^2.2"
*
* @param string $boostFunctions
* @return Solarium_Query_Component_DisMax Provides fluent interface
*/
public function setBoostFunctions($boostFunctions)
{
return $this->_setOption('boostfunctions', $boostFunctions);
}
/**
* Get BoostFunctions option
*
* @return string|null
*/
public function getBoostFunctions()
{
return $this->getOption('boostfunctions');
}
}
\ No newline at end of file
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
* @package Solarium * @package Solarium
* @subpackage Query * @subpackage Query
*/ */
abstract class Solarium_Query_Select_Facet extends Solarium_Configurable abstract class Solarium_Query_Select_Component_Facet extends Solarium_Configurable
{ {
/** /**
...@@ -51,6 +51,8 @@ abstract class Solarium_Query_Select_Facet extends Solarium_Configurable ...@@ -51,6 +51,8 @@ abstract class Solarium_Query_Select_Facet extends Solarium_Configurable
*/ */
const QUERY = 'query'; const QUERY = 'query';
const FIELD = 'field'; const FIELD = 'field';
const MULTIQUERY = 'multiquery';
const RANGE = 'range';
/** /**
* Exclude tags for this facet * Exclude tags for this facet
...@@ -82,6 +84,7 @@ abstract class Solarium_Query_Select_Facet extends Solarium_Configurable ...@@ -82,6 +84,7 @@ abstract class Solarium_Query_Select_Facet extends Solarium_Configurable
case 'exclude': case 'exclude':
if(!is_array($value)) $value = array($value); if(!is_array($value)) $value = array($value);
$this->setExcludes($value); $this->setExcludes($value);
unset($this->_options['exclude']);
break; break;
} }
} }
...@@ -101,7 +104,7 @@ abstract class Solarium_Query_Select_Facet extends Solarium_Configurable ...@@ -101,7 +104,7 @@ abstract class Solarium_Query_Select_Facet extends Solarium_Configurable
* Set key value * Set key value
* *
* @param string $value * @param string $value
* @return Solarium_Query_Select_Facet Provides fluent interface * @return Solarium_Query_Select_Component_Facet Provides fluent interface
*/ */
public function setKey($value) public function setKey($value)
{ {
...@@ -112,7 +115,7 @@ abstract class Solarium_Query_Select_Facet extends Solarium_Configurable ...@@ -112,7 +115,7 @@ abstract class Solarium_Query_Select_Facet extends Solarium_Configurable
* Add an exclude tag * Add an exclude tag
* *
* @param string $tag * @param string $tag
* @return Solarium_Query_Select_Facet Provides fluent interface * @return Solarium_Query_Select_Component_Facet Provides fluent interface
*/ */
public function addExclude($exclude) public function addExclude($exclude)
{ {
...@@ -124,7 +127,7 @@ abstract class Solarium_Query_Select_Facet extends Solarium_Configurable ...@@ -124,7 +127,7 @@ abstract class Solarium_Query_Select_Facet extends Solarium_Configurable
* Add multiple exclude tags * Add multiple exclude tags
* *
* @param array $excludes * @param array $excludes
* @return Solarium_Query_Select_Facet Provides fluent interface * @return Solarium_Query_Select_Component_Facet Provides fluent interface
*/ */
public function addExcludes(array $excludes) public function addExcludes(array $excludes)
{ {
...@@ -149,7 +152,7 @@ abstract class Solarium_Query_Select_Facet extends Solarium_Configurable ...@@ -149,7 +152,7 @@ abstract class Solarium_Query_Select_Facet extends Solarium_Configurable
* Remove a single exclude tag * Remove a single exclude tag
* *
* @param string $exclude * @param string $exclude
* @return Solarium_Query_Select_Facet Provides fluent interface * @return Solarium_Query_Select_Component_Facet Provides fluent interface
*/ */
public function removeExclude($exclude) public function removeExclude($exclude)
{ {
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
* @package Solarium * @package Solarium
* @subpackage Query * @subpackage Query
*/ */
class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet class Solarium_Query_Select_Component_Facet_Field extends Solarium_Query_Select_Component_Facet
{ {
/** /**
...@@ -81,7 +81,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet ...@@ -81,7 +81,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet
* Set the field name * Set the field name
* *
* @param string $query * @param string $query
* @return Solarium_Query_Select_Facet_Field Provides fluent interface * @return Solarium_Query_Select_Component_Facet_Field Provides fluent interface
*/ */
public function setField($field) public function setField($field)
{ {
...@@ -104,7 +104,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet ...@@ -104,7 +104,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet
* Use one of the SORT_* constants as the value * Use one of the SORT_* constants as the value
* *
* @param string $sort * @param string $sort
* @return Solarium_Query_Select_Facet_Field Provides fluent interface * @return Solarium_Query_Select_Component_Facet_Field Provides fluent interface
*/ */
public function setSort($sort) public function setSort($sort)
{ {
...@@ -125,7 +125,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet ...@@ -125,7 +125,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet
* Limit the terms for faceting by a prefix * Limit the terms for faceting by a prefix
* *
* @param string $prefix * @param string $prefix
* @return Solarium_Query_Select_Facet_Field Provides fluent interface * @return Solarium_Query_Select_Component_Facet_Field Provides fluent interface
*/ */
public function setPrefix($prefix) public function setPrefix($prefix)
{ {
...@@ -146,7 +146,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet ...@@ -146,7 +146,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet
* Set the facet limit * Set the facet limit
* *
* @param int $limit * @param int $limit
* @return Solarium_Query_Select_Facet_Field Provides fluent interface * @return Solarium_Query_Select_Component_Facet_Field Provides fluent interface
*/ */
public function setLimit($limit) public function setLimit($limit)
{ {
...@@ -167,7 +167,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet ...@@ -167,7 +167,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet
* Set the facet offset * Set the facet offset
* *
* @param int $offset * @param int $offset
* @return Solarium_Query_Select_Facet_Field Provides fluent interface * @return Solarium_Query_Select_Component_Facet_Field Provides fluent interface
*/ */
public function setOffset($offset) public function setOffset($offset)
{ {
...@@ -188,7 +188,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet ...@@ -188,7 +188,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet
* Set the facet mincount * Set the facet mincount
* *
* @param int $mincount * @param int $mincount
* @return Solarium_Query_Select_Facet_Field Provides fluent interface * @return Solarium_Query_Select_Component_Facet_Field Provides fluent interface
*/ */
public function setMinCount($minCount) public function setMinCount($minCount)
{ {
...@@ -209,7 +209,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet ...@@ -209,7 +209,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet
* Set the missing count option * Set the missing count option
* *
* @param boolean $missing * @param boolean $missing
* @return Solarium_Query_Select_Facet_Field Provides fluent interface * @return Solarium_Query_Select_Component_Facet_Field Provides fluent interface
*/ */
public function setMissing($missing) public function setMissing($missing)
{ {
......
<?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
*
* @package Solarium
* @subpackage Query
*/
/**
* Facet MultiQuery
*
* This is a 'virtual' querytype that combines multiple facet queries into a
* single resultset
*
* @package Solarium
* @subpackage Query
*/
class Solarium_Query_Select_Component_Facet_MultiQuery extends Solarium_Query_Select_Component_Facet
{
/**
* Facet query objects
*
* @var array
*/
protected $_facetQueries = 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 'query':
if(!is_array($value)) $value = array($value);
$this->addQueries($value);
break;
}
}
}
/**
* Get the facet type
*
* @return string
*/
public function getType()
{
return self::MULTIQUERY;
}
/**
* Create a new facetQuery
*
* Convenience method so you don't need to manually create facetquery
* objects.
*
* @param string $key
* @param string $query
* @param array $excludes
* @return Solarium_Query_Select_Component_Facet_MultiQuery Provides fluent interface
*/
public function createQuery($key, $query, $excludes = array())
{
// merge excludes with shared excludes
$excludes = array_merge($this->getExcludes(), $excludes);
$facetQuery = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery->setKey($key);
$facetQuery->setQuery($query);
$facetQuery->setExcludes($excludes);
return $this->addQuery($facetQuery);
}
/**
* Add a facetquery
*
* Supports a facetquery instance or a config array, in that case a new
* facetquery instance wil be created based on the options.
*
* @param Solarium_Query_Select_Component_Facet_Query|array $facetQuery
* @return Solarium_Query_Select_Component_Facet_MultiQuery Provides fluent interface
*/
public function addQuery($facetQuery)
{
if (is_array($facetQuery)) {
$facetQuery = new Solarium_Query_Select_Component_Facet_Query($facetQuery);
}
$key = $facetQuery->getKey();
if (0 === strlen($key)) {
throw new Solarium_Exception('A facetquery must have a key value');
}
if (array_key_exists($key, $this->_facetQueries)) {
throw new Solarium_Exception('A query must have a unique key'
. ' value within a multiquery facet');
}
// forward shared excludes
$facetQuery->addExcludes($this->getExcludes());
$this->_facetQueries[$key] = $facetQuery;
return $this;
}
/**
* Add multiple facetqueries
*
* @param array $facetQueries Instances or config array
* @return Solarium_Query_Select_Component_Facet_MultiQuery Provides fluent interface
*/
public function addQueries(array $facetQueries)
{
foreach ($facetQueries AS $key => $facetQuery) {
// in case of a config array: add key to config
if (is_array($facetQuery) && !isset($facetQuery['key'])) {
$facetQuery['key'] = $key;
}
$this->addQuery($facetQuery);
}
return $this;
}
/**
* Get a facetquery
*
* @param string $key
* @return string
*/
public function getQuery($key)
{
if (isset($this->_facetQueries[$key])) {
return $this->_facetQueries[$key];
} else {
return null;
}
}
/**
* Get all facetqueries
*
* @return array
*/
public function getQueries()
{
return $this->_facetQueries;
}
/**
* Remove a single facetquery by key
*
* @param string $key
* @return Solarium_Query_Select_Component_Facet_MultiQuery Provides fluent interface
*/
public function removeQuery($key)
{
if (isset($this->_facetQueries[$key])) {
unset($this->_facetQueries[$key]);
}
return $this;
}
/**
* Remove all facetqueries
*
* @return Solarium_Query_Select_Component_Facet_MultiQuery Provides fluent interface
*/
public function clearQueries()
{
$this->_facetQueries = array();
return $this;
}
/**
* Set multiple facetqueries
*
* This overwrites any existing facetqueries
*
* @param array $facetQueries
* @return Solarium_Query_Select_Component_Facet_MultiQuery Provides fluent interface
*/
public function setQueries($facetQueries)
{
$this->clearQueries();
return $this->addQueries($facetQueries);
}
/**
* Add an exclude tag
*
* Excludes added to the MultiQuery facet a shared by all underlying
* FacetQueries, so they must be forwarded to any existing instances.
*
* If you don't want to share an exclude use the addExclude method of a
* specific FacetQuery instance instead.
*
* @param string $tag
* @return Solarium_Query_Select_Component_Facet Provides fluent interface
*/
public function addExclude($exclude)
{
foreach ($this->_facetQueries AS $facetQuery) {
$facetQuery->addExclude($exclude);
}
return parent::addExclude($exclude);
}
/**
* Remove a single exclude tag
*
* Excludes added to the MultiQuery facet a shared by all underlying
* FacetQueries, so changes must be forwarded to any existing instances.
*
* If you don't want this use the removeExclude method of a
* specific FacetQuery instance instead.
*
* @param string $exclude
* @return Solarium_Query_Select_Component_Facet_MultiQuery Provides fluent interface
*/
public function removeExclude($exclude)
{
foreach ($this->_facetQueries AS $facetQuery) {
$facetQuery->removeExclude($exclude);
}
return parent::removeExclude($exclude);
}
/**
* Remove all excludes
*
* Excludes added to the MultiQuery facet a shared by all underlying
* FacetQueries, so changes must be forwarded to any existing instances.
*
* If you don't want this use the clearExcludes method of a
* specific FacetQuery instance instead.
*
* @return Solarium_Query_Select_Component_Facet_MultiQuery Provides fluent interface
*/
public function clearExcludes()
{
foreach ($this->_facetQueries AS $facetQuery) {
$facetQuery->clearExcludes();
}
return parent::clearExcludes();
}
}
\ No newline at end of file
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
* @package Solarium * @package Solarium
* @subpackage Query * @subpackage Query
*/ */
class Solarium_Query_Select_Facet_Query extends Solarium_Query_Select_Facet class Solarium_Query_Select_Component_Facet_Query extends Solarium_Query_Select_Component_Facet
{ {
/** /**
......
<?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
*
* @package Solarium
* @subpackage Query
*/
/**
* Facet range
*
* @link http://wiki.apache.org/solr/SimpleFacetParameters#Facet_by_Range
*
* @package Solarium
* @subpackage Query
*/
class Solarium_Query_Select_Component_Facet_Range extends Solarium_Query_Select_Component_Facet
{
/**
* Values for the 'other' option
*/
const OTHER_BEFORE = 'before';
const OTHER_AFTER = 'after';
const OTHER_BETWEEN = 'between';
const OTHER_ALL = 'all';
const OTHER_NONE = 'none';
/**
* Values for the 'include' option
*/
const INCLUDE_LOWER = 'lower';
const INCLUDE_UPPER = 'upper';
const INCLUDE_EDGE = 'edge';
const INCLUDE_OUTER = 'outer';
const INCLUDE_ALL = 'all';
/**
* 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 'include':
$this->setInclude($value);
break;
case 'other':
$this->setOther($value);
break;
}
}
}
/**
* Get the facet type
*
* @return string
*/
public function getType()
{
return self::RANGE;
}
/**
* Set the field name
*
* @param string $query
* @return Solarium_Query_Select_Component_Facet_Range 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 lower bound of the range
*
* @param string $start
* @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
*/
public function setStart($start)
{
return $this->_setOption('start', $start);
}
/**
* Get the lower bound of the range
*
* @return string
*/
public function getStart()
{
return $this->getOption('start');
}
/**
* Set the upper bound of the range
*
* @param string $end
* @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
*/
public function setEnd($end)
{
return $this->_setOption('end', $end);
}
/**
* Get the upper bound of the range
*
* @return string
*/
public function getEnd()
{
return $this->getOption('end');
}
/**
* Set range gap
*
* The size of each range expressed as a value to be added to the lower bound
*
* @param string $gap
* @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
*/
public function setGap($gap)
{
return $this->_setOption('gap', $gap);
}
/**
* Get range gap
*
* The size of each range expressed as a value to be added to the lower bound
*
* @return string
*/
public function getGap()
{
return $this->getOption('gap');
}
/**
* Set hardend option
*
* A Boolean parameter instructing Solr what to do in the event that facet.range.gap
* does not divide evenly between facet.range.start and facet.range.end
*
* @param boolean $hardend
* @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
*/
public function setHardend($hardend)
{
return $this->_setOption('hardend', $hardend);
}
/**
* Get hardend option
*
* @return boolean
*/
public function getHardend()
{
return $this->getOption('hardend');
}
/**
* Set other counts
*
* Use one of the constants as value.
* If you want to use multiple values supply an array or comma separated string
*
* @param string|array $other
* @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
*/
public function setOther($other)
{
if (is_array($other)) {
$other = implode(',', $other);
}
return $this->_setOption('other', $other);
}
/**
* Get other counts
*
* In case of multiple values a comma separated string will be returned
*
* @return string
*/
public function getOther()
{
return $this->getOption('other');
}
/**
* Set include option
*
* Use one of the constants as value.
* If you want to use multiple values supply an array or comma separated string
*
* @param string|array $include
* @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
*/
public function setInclude($include)
{
if (is_array($include)) {
$include = implode(',', $include);
}
return $this->_setOption('include', $include);
}
/**
* Get include option
*
* In case of multiple values a comma separated string will be returned
*
* @return string
*/
public function getInclude()
{
return $this->getOption('include');
}
}
\ 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
*
* @package Solarium
* @subpackage Query
*/
/**
* MoreLikeThis component
*
* @link http://wiki.apache.org/solr/MoreLikeThis
*
* @package Solarium
* @subpackage Query
*/
class Solarium_Query_Select_Component_FacetSet extends Solarium_Query_Select_Component
{
/**
* Component type
*
* @var string
*/
protected $_type = self::FACETSET;
/**
* Default options
*
* @var array
*/
protected $_options = array();
/**
* Facets
*
* @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()
{
if (isset($this->_options['facet'])) {
foreach ($this->_options['facet'] AS $key => $config) {
if (!isset($config['key'])) {
$config['key'] = $key;
}
$this->addFacet($config);
}
}
}
/**
* Limit the terms for faceting by a prefix
*
* This is a global value for all facets in this facetset
*
* @param string $prefix
* @return Solarium_Query_Select_Component_FacetSet Provides fluent interface
*/
public function setPrefix($prefix)
{
return $this->_setOption('prefix', $prefix);
}
/**
* Get the facet prefix
*
* This is a global value for all facets in this facetset
*
* @return string
*/
public function getPrefix()
{
return $this->getOption('prefix');
}
/**
* Set the facet sort order
*
* Use one of the SORT_* constants as the value
*
* This is a global value for all facets in this facetset
*
* @param string $sort
* @return Solarium_Query_Select_Component_FacetSet Provides fluent interface
*/
public function setSort($sort)
{
return $this->_setOption('sort', $sort);
}
/**
* Get the facet sort order
*
* This is a global value for all facets in this facetset
*
* @return string
*/
public function getSort()
{
return $this->getOption('sort');
}
/**
* Set the facet limit
*
* This is a global value for all facets in this facetset
*
* @param int $limit
* @return Solarium_Query_Select_Component_FacetSet Provides fluent interface
*/
public function setLimit($limit)
{
return $this->_setOption('limit', $limit);
}
/**
* Get the facet limit
*
* This is a global value for all facets in this facetset
*
* @return string
*/
public function getLimit()
{
return $this->getOption('limit');
}
/**
* Set the facet mincount
*
* This is a global value for all facets in this facetset
*
* @param int $mincount
* @return Solarium_Query_Select_Component_FacetSet Provides fluent interface
*/
public function setMinCount($minCount)
{
return $this->_setOption('mincount', $minCount);
}
/**
* Get the facet mincount
*
* This is a global value for all facets in this facetset
*
* @return int
*/
public function getMinCount()
{
return $this->getOption('mincount');
}
/**
* Set the missing count option
*
* This is a global value for all facets in this facetset
*
* @param boolean $missing
* @return Solarium_Query_Select_Component_FacetSet Provides fluent interface
*/
public function setMissing($missing)
{
return $this->_setOption('missing', $missing);
}
/**
* Get the facet missing option
*
* This is a global value for all facets in this facetset
*
* @return boolean
*/
public function getMissing()
{
return $this->getOption('missing');
}
/**
* Add a facet
*
* @param Solarium_Query_Select_Component_Facet|array $facet
* @return Solarium_Query Provides fluent interface
*/
public function addFacet($facet)
{
if (is_array($facet)) {
$className = 'Solarium_Query_Select_Component_Facet_'.ucfirst($facet['type']);
$facet = new $className($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 $key => $facet) {
// in case of a config array: add key to config
if (is_array($facet) && !isset($facet['key'])) {
$facet['key'] = $key;
}
$this->addFacet($facet);
}
return $this;
}
/**
* Get a facet
*
* @param string $key
* @return string
*/
public function getFacet($key)
{
if (isset($this->_facets[$key])) {
return $this->_facets[$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->_facets[$key])) {
unset($this->_facets[$key]);
}
return $this;
}
/**
* Remove all facets
*
* @return Solarium_Query Provides fluent interface
*/
public function clearFacets()
{
$this->_facets = array();
return $this;
}
/**
* Set multiple facets
*
* This overwrites any existing facets
*
* @param array $facets
*/
public function setFacets($facets)
{
$this->clearFacets();
$this->addFacets($facets);
}
}
\ No newline at end of file
...@@ -43,8 +43,7 @@ ...@@ -43,8 +43,7 @@
* @package Solarium * @package Solarium
* @subpackage Query * @subpackage Query
*/ */
class Solarium_Query_Select_Component_MoreLikeThis class Solarium_Query_Select_Component_MoreLikeThis extends Solarium_Query_Select_Component
extends Solarium_Query_Select_Component
{ {
/** /**
...@@ -54,24 +53,6 @@ class Solarium_Query_Select_Component_MoreLikeThis ...@@ -54,24 +53,6 @@ class Solarium_Query_Select_Component_MoreLikeThis
*/ */
protected $_type = self::MORELIKETHIS; protected $_type = self::MORELIKETHIS;
/**
* Default options
*
* @var array
*/
protected $_options = array(
'fields' => null,
'minimumtermfrequency' => null,
'minimumdocumentfrequency' => null,
'minimumwordlength' => null,
'maximumwordlength' => null,
'maximumqueryterms' => null,
'maximumnumberoftokens' => null,
'boost' => null,
'queryfields' => null,
'count' => null,
);
/** /**
* Set fields option * Set fields option
* *
......
<?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
*
* @package Solarium
* @subpackage Result
*/
/**
* Select multiquery facet result
*
* A multiquery facet will usually return a dataset of multiple rows, in each
* row a query key and it's count. You can access the values as an array using
* {@link getValues()} or iterate this object.
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_Facet_MultiQuery extends Solarium_Result_Select_Facet_Field
{
}
\ 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
*
* @package Solarium
* @subpackage Result
*/
/**
* Select range facet result
*
* A multiquery facet will usually return a dataset of multiple count, in each
* row a range as key and it's count. You can access the values as an array using
* {@link getValues()} or iterate this object.
*
* The extra counts 'before', 'between' and 'after' are only available if the
* right settings for the option 'other' were used in the query.
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_Facet_Range extends Solarium_Result_Select_Facet_Field
{
/**
* Count of all records with field values lower then lower bound of the first range
*
* @var int
*/
protected $_before;
/**
* Count of all records with field values greater then the upper bound of the last range
*
* @var int
*/
protected $_after;
/**
* Count all records with field values between the start and end bounds of all ranges
*
* @var int
*/
protected $_between;
/**
* Constructor
*
* @param array $values
* @return void
*/
public function __construct($values, $before, $after, $between)
{
$this->_values = $values;
$this->_before = $before;
$this->_after = $after;
$this->_between = $between;
}
/**
* Get 'before' count
*
* Count of all records with field values lower then lower bound of the first range
* Only available if the 'other' setting was used in the query facet.
*
* @return int
*/
public function getBefore()
{
return $this->_before;
}
/**
* Get 'after' count
*
* Count of all records with field values greater then the upper bound of the last range
* Only available if the 'other' setting was used in the query facet.
*
* @return int
*/
public function getAfter()
{
return $this->_after;
}
/**
* Get 'between' count
*
* Count all records with field values between the start and end bounds of all ranges
* Only available if the 'other' setting was used in the query facet.
*
* @return int
*/
public function getBetween()
{
return $this->_between;
}
}
\ No newline at end of file
...@@ -111,8 +111,9 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase ...@@ -111,8 +111,9 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
public function testSelectUrlWithFacets() public function testSelectUrlWithFacets()
{ {
$this->_query->addFacet(new Solarium_Query_Select_Facet_Field(array('key' => 'f1', 'field' => 'owner'))); $this->_query->getFacetSet()->addFacet(new Solarium_Query_Select_Component_Facet_Field(array('key' => 'f1', 'field' => 'owner')));
$this->_query->addFacet(new Solarium_Query_Select_Facet_Query(array('key' => 'f2', 'query' => 'category:23'))); $this->_query->getFacetSet()->addFacet(new Solarium_Query_Select_Component_Facet_Query(array('key' => 'f2', 'query' => 'category:23')));
$this->_query->getFacetSet()->addFacet(new Solarium_Query_Select_Component_Facet_MultiQuery(array('key' => 'f3', 'query' => array('f4' =>array('query' => 'category:40')))));
$request = new Solarium_Client_Request_Select($this->_options, $this->_query); $request = new Solarium_Client_Request_Select($this->_options, $this->_query);
$this->assertEquals( $this->assertEquals(
...@@ -121,14 +122,61 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase ...@@ -121,14 +122,61 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
); );
$this->assertEquals( $this->assertEquals(
'http://127.0.0.1:80/solr/select?q=*:*&start=0&rows=10&fl=*,score&wt=json&facet=true&facet.field={!key=f1}owner&facet.query={!key=f2}category:23', 'http://127.0.0.1:80/solr/select?q=*:*&start=0&rows=10&fl=*,score&wt=json&facet=true&facet.field={!key=f1}owner&facet.query={!key=f2}category:23&facet.query={!key=f4}category:40',
urldecode($request->getUri())
);
}
public function testSelectUrlWithRangeFacet()
{
$this->_query->getFacetSet()->addFacet(new Solarium_Query_Select_Component_Facet_Range(
array(
'key' => 'f1',
'field' => 'price',
'start' => '1',
'end' => 100,
'gap' => 10,
'other' => 'all',
'include' => 'outer'
)
));
$request = new Solarium_Client_Request_Select($this->_options, $this->_query);
$this->assertEquals(
null,
$request->getRawData()
);
$this->assertEquals(
'http://127.0.0.1:80/solr/select?q=*:*&start=0&rows=10&fl=*,score&wt=json&facet=true&facet.range={!key=f1}price&f.price.facet.range.start=1&f.price.facet.range.end=100&f.price.facet.range.gap=10&f.price.facet.range.other=all&f.price.facet.range.include=outer',
urldecode($request->getUri())
);
}
public function testSelectUrlWithFacetsAndGlobalFacetSettings()
{
$this->_query->getFacetSet()->setMissing(true);
$this->_query->getFacetSet()->setLimit(10);
$this->_query->getFacetSet()->addFacet(new Solarium_Query_Select_Component_Facet_Field(array('key' => 'f1', 'field' => 'owner')));
$this->_query->getFacetSet()->addFacet(new Solarium_Query_Select_Component_Facet_Query(array('key' => 'f2', 'query' => 'category:23')));
$this->_query->getFacetSet()->addFacet(new Solarium_Query_Select_Component_Facet_MultiQuery(array('key' => 'f3', 'query' => array('f4' =>array('query' => 'category:40')))));
$request = new Solarium_Client_Request_Select($this->_options, $this->_query);
$this->assertEquals(
null,
$request->getRawData()
);
$this->assertEquals(
'http://127.0.0.1:80/solr/select?q=*:*&start=0&rows=10&fl=*,score&wt=json&facet=true&facet.missing=1&facet.limit=10&facet.field={!key=f1}owner&facet.query={!key=f2}category:23&facet.query={!key=f4}category:40',
urldecode($request->getUri()) urldecode($request->getUri())
); );
} }
public function testUnknownFacetType() public function testUnknownFacetType()
{ {
$this->_query->addFacet(new UnknownFacet(array('key' => 'f1', 'field' => 'owner'))); $this->_query->getFacetSet()->addFacet(new UnknownFacet(array('key' => 'f1', 'field' => 'owner')));
$this->setExpectedException('Solarium_Exception'); $this->setExpectedException('Solarium_Exception');
$request = new Solarium_Client_Request_Select($this->_options, $this->_query); $request = new Solarium_Client_Request_Select($this->_options, $this->_query);
$request->getUri(); $request->getUri();
...@@ -163,7 +211,7 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase ...@@ -163,7 +211,7 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
} }
class UnknownFacet extends Solarium_Query_Select_Facet_Field{ class UnknownFacet extends Solarium_Query_Select_Component_Facet_Field{
public function getType() public function getType()
{ {
......
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Query_Select_Component_DisMaxTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Select_Component_DisMax
*/
protected $_disMax;
public function setUp()
{
$this->_disMax = new Solarium_Query_Select_Component_DisMax;
}
public function testGetType()
{
$this->assertEquals(
Solarium_Query_Select_Component::DISMAX,
$this->_disMax->getType()
);
}
public function testSetAndGetQueryAlternative()
{
$value = '*:*';
$this->_disMax->setQueryAlternative($value);
$this->assertEquals(
$value,
$this->_disMax->getQueryAlternative()
);
}
public function testSetAndGetQueryFields()
{
$value = 'title^2.0 description';
$this->_disMax->setQueryFields($value);
$this->assertEquals(
$value,
$this->_disMax->getQueryFields()
);
}
public function testSetAndGetMinimumMatch()
{
$value = '2.0';
$this->_disMax->setMinimumMatch($value);
$this->assertEquals(
$value,
$this->_disMax->getMinimumMatch()
);
}
public function testSetAndGetPhraseFields()
{
$value = 'title^2.0 description^3.5';
$this->_disMax->setPhraseFields($value);
$this->assertEquals(
$value,
$this->_disMax->getPhraseFields()
);
}
public function testSetAndGetPhraseSlop()
{
$value = '2';
$this->_disMax->setPhraseSlop($value);
$this->assertEquals(
$value,
$this->_disMax->getPhraseSlop()
);
}
public function testSetAndGetQueryPhraseSlop()
{
$value = '3';
$this->_disMax->setQueryPhraseSlop($value);
$this->assertEquals(
$value,
$this->_disMax->getQueryPhraseSlop()
);
}
public function testSetAndGetTie()
{
$value = 2.1;
$this->_disMax->setTie($value);
$this->assertEquals(
$value,
$this->_disMax->getTie()
);
}
public function testSetAndGetBoostQuery()
{
$value = 'cat:1^3';
$this->_disMax->setBoostQuery($value);
$this->assertEquals(
$value,
$this->_disMax->getBoostQuery()
);
}
public function testSetAndGetBoostFunctions()
{
$value = 'funcA(arg1,arg2)^1.2 funcB(arg3,arg4)^2.2';
$this->_disMax->setBoostFunctions($value);
$this->assertEquals(
$value,
$this->_disMax->getBoostFunctions()
);
}
}
...@@ -29,20 +29,20 @@ ...@@ -29,20 +29,20 @@
* policies, either expressed or implied, of the copyright holder. * policies, either expressed or implied, of the copyright holder.
*/ */
class Solarium_Query_Select_Facet_FieldTest extends PHPUnit_Framework_TestCase class Solarium_Query_Select_Component_Facet_FieldTest extends PHPUnit_Framework_TestCase
{ {
protected $_facet; protected $_facet;
public function setUp() public function setUp()
{ {
$this->_facet = new Solarium_Query_Select_Facet_Field; $this->_facet = new Solarium_Query_Select_Component_Facet_Field;
} }
public function testGetType() public function testGetType()
{ {
$this->assertEquals( $this->assertEquals(
Solarium_Query_Select_Facet::FIELD, Solarium_Query_Select_Component_Facet::FIELD,
$this->_facet->getType() $this->_facet->getType()
); );
} }
......
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Query_Select_Component_Facet_MultiQueryTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Select_Component_Facet_MultiQuery
*/
protected $_facet;
public function setUp()
{
$this->_facet = new Solarium_Query_Select_Component_Facet_MultiQuery;
}
public function testGetType()
{
$this->assertEquals(
Solarium_Query_Select_Component_Facet::MULTIQUERY,
$this->_facet->getType()
);
}
public function testCreateAndGetQuery()
{
$key = 'k1';
$query = 'category:1';
$excludes = array('fq1','fq2');
$facetQuery = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery->setKey($key);
$facetQuery->setQuery($query);
$facetQuery->setExcludes($excludes);
$this->_facet->createQuery($key, $query, $excludes);
$this->assertEquals(
$facetQuery,
$this->_facet->getQuery($key)
);
}
public function testAddAndGetQuery()
{
$key = 'k1';
$query = 'category:1';
$excludes = array('fq1','fq2');
$facetQuery = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery->setKey($key);
$facetQuery->setQuery($query);
$facetQuery->setExcludes($excludes);
$this->_facet->addQuery($facetQuery);
$this->assertEquals(
$facetQuery,
$this->_facet->getQuery($key)
);
}
public function testAddQueryWithConfig()
{
$config = array(
'key' => 'k1',
'query' => 'category:1',
'excludes' => array('fq1','fq2')
);
$facetQuery = new Solarium_Query_Select_Component_Facet_Query($config);
$this->_facet->addQuery($config);
$this->assertEquals(
$facetQuery,
$this->_facet->getQuery($config['key'])
);
}
public function testAddQueryNoKey()
{
$query = 'category:1';
$excludes = array('fq1','fq2');
$facetQuery = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery->setQuery($query);
$facetQuery->setExcludes($excludes);
$this->setExpectedException('Solarium_Exception');
$this->_facet->addQuery($facetQuery);
}
public function testAddQueryNoUniqueKey()
{
$facetQuery1 = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery1->setKey('k1');
$facetQuery1->setQuery('category:1');
$facetQuery2 = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery2->setKey('k1');
$facetQuery2->setQuery('category:2');
$this->_facet->addQuery($facetQuery1);
$this->setExpectedException('Solarium_Exception');
$this->_facet->addQuery($facetQuery2);
}
public function testAddQueryExcludeForwarding()
{
$this->_facet->addExclude('fq1');
$facetQuery = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery->setKey('k1');
$facetQuery->setQuery('category:1');
$this->_facet->addQuery($facetQuery);
$this->assertEquals(
array('fq1'),
$facetQuery->getExcludes()
);
}
public function testAddAndGetQueries()
{
$facetQuery1 = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery1->setKey('k1');
$facetQuery1->setQuery('category:1');
$facetQuery2 = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery2->setKey('k2');
$facetQuery2->setQuery('category:2');
$this->_facet->addQueries(array($facetQuery1, $facetQuery2));
$this->assertEquals(
array('k1' => $facetQuery1, 'k2' => $facetQuery2),
$this->_facet->getQueries()
);
}
public function testAddQueriesWithConfig()
{
$facetQuery1 = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery1->setKey('k1');
$facetQuery1->setQuery('category:1');
$facetQuery1->addExcludes(array('fq1','fq2'));
$facetQuery2 = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery2->setKey('k2');
$facetQuery2->setQuery('category:2');
$facetQueries = array('k1' => $facetQuery1, 'k2' => $facetQuery2);
$config = array(
array(
'key' => 'k1',
'query' => 'category:1',
'exclude' => array('fq1','fq2')
),
'k2' => array(
'query' => 'category:2'
),
);
$this->_facet->addQueries($config);
$this->assertEquals(
$facetQueries,
$this->_facet->getQueries()
);
}
public function testGetInvalidQuery()
{
$this->assertEquals(
null,
$this->_facet->getQuery('invalidkey')
);
}
public function testRemoveQuery()
{
$facetQuery = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery->setKey('k1');
$facetQuery->setQuery('category:1');
$this->_facet->addQuery($facetQuery);
$this->assertEquals(
array('k1' => $facetQuery),
$this->_facet->getQueries()
);
$this->_facet->removeQuery('k1');
$this->assertEquals(
array(),
$this->_facet->getQueries()
);
}
public function testRemoveInvalidQuery()
{
$facetQuery = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery->setKey('k1');
$facetQuery->setQuery('category:1');
$this->_facet->addQuery($facetQuery);
$before = $this->_facet->getQueries();
$this->_facet->removeQuery('invalidkey');
$after = $this->_facet->getQueries();
$this->assertEquals(
$before,
$after
);
}
public function testClearQueries()
{
$facetQuery1 = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery1->setKey('k1');
$facetQuery1->setQuery('category:1');
$facetQuery2 = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery2->setKey('k2');
$facetQuery2->setQuery('category:2');
$this->_facet->addQueries(array($facetQuery1, $facetQuery2));
$this->_facet->clearQueries();
$this->assertEquals(
array(),
$this->_facet->getQueries()
);
}
public function testSetQueries()
{
$facetQuery1 = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery1->setKey('k1');
$facetQuery1->setQuery('category:1');
$this->_facet->addQuery($facetQuery1);
$facetQuery2 = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery2->setKey('k2');
$facetQuery2->setQuery('category:2');
$facetQuery3 = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery3->setKey('k3');
$facetQuery3->setQuery('category:3');
$this->_facet->setQueries(array($facetQuery2, $facetQuery3));
$this->assertEquals(
array('k2' => $facetQuery2, 'k3' => $facetQuery3),
$this->_facet->getQueries()
);
}
public function testAddExcludeForwarding()
{
$facetQuery = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery->setKey('k1');
$facetQuery->setQuery('category:1');
$this->_facet->addQuery($facetQuery);
$this->_facet->addExclude('fq1');
$this->assertEquals(
array('fq1'),
$facetQuery->getExcludes()
);
}
public function testRemoveExcludeForwarding()
{
$this->_facet->addExclude('fq1');
$facetQuery = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery->setKey('k1');
$facetQuery->setQuery('category:1');
$this->_facet->addQuery($facetQuery);
$this->assertEquals(
array('fq1'),
$facetQuery->getExcludes()
);
$this->_facet->removeExclude('fq1');
$this->assertEquals(
array(),
$facetQuery->getExcludes()
);
}
public function testClearExcludesForwarding()
{
$this->_facet->addExclude('fq1');
$this->_facet->addExclude('fq2');
$facetQuery = new Solarium_Query_Select_Component_Facet_Query;
$facetQuery->setKey('k1');
$facetQuery->setQuery('category:1');
$this->_facet->addQuery($facetQuery);
$this->assertEquals(
array('fq1','fq2'),
$facetQuery->getExcludes()
);
$this->_facet->clearExcludes();
$this->assertEquals(
array(),
$facetQuery->getExcludes()
);
}
}
...@@ -29,20 +29,20 @@ ...@@ -29,20 +29,20 @@
* policies, either expressed or implied, of the copyright holder. * policies, either expressed or implied, of the copyright holder.
*/ */
class Solarium_Query_Select_Facet_QueryTest extends PHPUnit_Framework_TestCase class Solarium_Query_Select_Component_Facet_QueryTest extends PHPUnit_Framework_TestCase
{ {
protected $_facet; protected $_facet;
public function setUp() public function setUp()
{ {
$this->_facet = new Solarium_Query_Select_Facet_Query; $this->_facet = new Solarium_Query_Select_Component_Facet_Query;
} }
public function testGetType() public function testGetType()
{ {
$this->assertEquals( $this->assertEquals(
Solarium_Query_Select_Facet::QUERY, Solarium_Query_Select_Component_Facet::QUERY,
$this->_facet->getType() $this->_facet->getType()
); );
} }
......
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Query_Select_Component_Facet_RangeTest extends PHPUnit_Framework_TestCase
{
protected $_facet;
public function setUp()
{
$this->_facet = new Solarium_Query_Select_Component_Facet_Range;
}
public function testGetType()
{
$this->assertEquals(
Solarium_Query_Select_Component_Facet::RANGE,
$this->_facet->getType()
);
}
public function testSetAndGetField()
{
$this->_facet->setField('price');
$this->assertEquals('price', $this->_facet->getField());
}
public function testSetAndGetStart()
{
$this->_facet->setStart(1);
$this->assertEquals(1, $this->_facet->getStart());
}
public function testSetAndGetEnd()
{
$this->_facet->setEnd(100);
$this->assertEquals(100, $this->_facet->getEnd());
}
public function testSetAndGetGap()
{
$this->_facet->setGap(10);
$this->assertEquals(10, $this->_facet->getGap());
}
public function testSetAndGetHardend()
{
$this->_facet->setHardend(true);
$this->assertEquals(true, $this->_facet->getHardend());
}
public function testSetAndGetOther()
{
$this->_facet->setOther('all');
$this->assertEquals('all', $this->_facet->getOther());
}
public function testSetAndGetOtherArray()
{
$this->_facet->setOther(array('before','after'));
$this->assertEquals('before,after', $this->_facet->getOther());
}
public function testSetAndGetInclude()
{
$this->_facet->setInclude('all');
$this->assertEquals('all', $this->_facet->getInclude());
}
public function testSetAndGetIncludeArray()
{
$this->_facet->setInclude(array('lower','upper'));
$this->assertEquals('lower,upper', $this->_facet->getInclude());
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Query_Select_Component_FacetSetTest extends PHPUnit_Framework_TestCase
{
protected $_facetSet;
public function setUp()
{
$this->_facetSet = new Solarium_Query_Select_Component_FacetSet;
}
public function testGetType()
{
$this->assertEquals(Solarium_Query_Select_Component::FACETSET, $this->_facetSet->getType());
}
public function testSetAndGetSort()
{
$this->_facetSet->setSort('index');
$this->assertEquals('index', $this->_facetSet->getSort());
}
public function testSetAndGetPrefix()
{
$this->_facetSet->setPrefix('xyz');
$this->assertEquals('xyz', $this->_facetSet->getPrefix());
}
public function testSetAndGetLimit()
{
$this->_facetSet->setLimit(12);
$this->assertEquals(12, $this->_facetSet->getLimit());
}
public function testSetAndGetMinCount()
{
$this->_facetSet->setMincount(100);
$this->assertEquals(100, $this->_facetSet->getMincount());
}
public function testSetAndGetMissing()
{
$this->_facetSet->setMissing(true);
$this->assertEquals(true, $this->_facetSet->getMissing());
}
public function testAddAndGetFacet()
{
$fq = new Solarium_Query_Select_Component_Facet_Query;
$fq->setKey('f1')->setQuery('category:1');
$this->_facetSet->addFacet($fq);
$this->assertEquals(
$fq,
$this->_facetSet->getFacet('f1')
);
}
public function testAddFacetWithoutKey()
{
$fq = new Solarium_Query_Select_Component_Facet_Query;
$fq->setQuery('category:1');
$this->setExpectedException('Solarium_Exception');
$this->_facetSet->addFacet($fq);
}
public function testAddFacetWithUsedKey()
{
$fq1 = new Solarium_Query_Select_Component_Facet_Query;
$fq1->setKey('f1')->setQuery('category:1');
$fq2 = new Solarium_Query_Select_Component_Facet_Query;
$fq2->setKey('f1')->setQuery('category:2');
$this->_facetSet->addFacet($fq1);
$this->setExpectedException('Solarium_Exception');
$this->_facetSet->addFacet($fq2);
}
public function testGetInvalidFacet()
{
$this->assertEquals(
null,
$this->_facetSet->getFacet('invalidtag')
);
}
public function testAddFacets()
{
$fq1 = new Solarium_Query_Select_Component_Facet_Query;
$fq1->setKey('f1')->setQuery('category:1');
$fq2 = new Solarium_Query_Select_Component_Facet_Query;
$fq2->setKey('f2')->setQuery('category:2');
$facets = array('f1' => $fq1, 'f2' => $fq2);
$this->_facetSet->addFacets($facets);
$this->assertEquals(
$facets,
$this->_facetSet->getFacets()
);
}
public function testAddFacetsWithConfig()
{
$facets = array(
array('type' => 'query', 'key' => 'f1', 'query' => 'category:1'),
'f2' => array('type' => 'query', 'query' => 'category:2')
);
$this->_facetSet->addFacets($facets);
$this->assertEquals(
2,
count($this->_facetSet->getFacets())
);
}
public function testRemoveFacet()
{
$fq1 = new Solarium_Query_Select_Component_Facet_Query;
$fq1->setKey('f1')->setQuery('category:1');
$fq2 = new Solarium_Query_Select_Component_Facet_Query;
$fq2->setKey('f2')->setQuery('category:2');
$facets = array('f1' => $fq1, 'f2' => $fq2);
$this->_facetSet->addFacets($facets);
$this->_facetSet->removeFacet('f1');
$this->assertEquals(
array('f2' => $fq2),
$this->_facetSet->getFacets()
);
}
public function testRemoveInvalidFacet()
{
$fq1 = new Solarium_Query_Select_Component_Facet_Query;
$fq1->setKey('f1')->setQuery('category:1');
$fq2 = new Solarium_Query_Select_Component_Facet_Query;
$fq2->setKey('f2')->setQuery('category:2');
$facets = array('f1' => $fq1, 'f2' => $fq2);
$this->_facetSet->addFacets($facets);
$this->_facetSet->removeFacet('f3'); //continue silently
$this->assertEquals(
$facets,
$this->_facetSet->getFacets()
);
}
public function testClearFacets()
{
$fq1 = new Solarium_Query_Select_Component_Facet_Query;
$fq1->setKey('f1')->setQuery('category:1');
$fq2 = new Solarium_Query_Select_Component_Facet_Query;
$fq2->setKey('f2')->setQuery('category:2');
$facets = array('f1' => $fq1, 'f2' => $fq2);
$this->_facetSet->addFacets($facets);
$this->_facetSet->clearFacets();
$this->assertEquals(
array(),
$this->_facetSet->getFacets()
);
}
public function testSetFacets()
{
$fq1 = new Solarium_Query_Select_Component_Facet_Query;
$fq1->setKey('f1')->setQuery('category:1');
$fq2 = new Solarium_Query_Select_Component_Facet_Query;
$fq2->setKey('f2')->setQuery('category:2');
$facets = array('f1' => $fq1, 'f2' => $fq2);
$this->_facetSet->addFacets($facets);
$fq3 = new Solarium_Query_Select_Component_Facet_Query;
$fq3->setKey('f3')->setQuery('category:3');
$fq4 = new Solarium_Query_Select_Component_Facet_Query;
$fq4->setKey('f4')->setQuery('category:4');
$facets = array('f3' => $fq3, 'f4' => $fq4);
$this->_facetSet->setFacets($facets);
$this->assertEquals(
$facets,
$this->_facetSet->getFacets()
);
}
}
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
* policies, either expressed or implied, of the copyright holder. * policies, either expressed or implied, of the copyright holder.
*/ */
class Solarium_Query_Select_FacetTest extends PHPUnit_Framework_TestCase class Solarium_Query_Select_Component_FacetTest extends PHPUnit_Framework_TestCase
{ {
protected $_facet; protected $_facet;
...@@ -91,7 +91,7 @@ class Solarium_Query_Select_FacetTest extends PHPUnit_Framework_TestCase ...@@ -91,7 +91,7 @@ class Solarium_Query_Select_FacetTest extends PHPUnit_Framework_TestCase
} }
} }
class TestFacet extends Solarium_Query_Select_Facet{ class TestFacet extends Solarium_Query_Select_Component_Facet{
public function getType() public function getType()
{ {
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
* policies, either expressed or implied, of the copyright holder. * policies, either expressed or implied, of the copyright holder.
*/ */
class Solarium_Query_Select_Component_moreLikeThisTest extends PHPUnit_Framework_TestCase class Solarium_Query_Select_Component_MoreLikeThisTest extends PHPUnit_Framework_TestCase
{ {
protected $_mlt; protected $_mlt;
...@@ -39,6 +39,11 @@ class Solarium_Query_Select_Component_moreLikeThisTest extends PHPUnit_Framework ...@@ -39,6 +39,11 @@ class Solarium_Query_Select_Component_moreLikeThisTest extends PHPUnit_Framework
$this->_mlt = new Solarium_Query_Select_Component_MoreLikeThis; $this->_mlt = new Solarium_Query_Select_Component_MoreLikeThis;
} }
public function testGetType()
{
$this->assertEquals(Solarium_Query_Select_Component::MORELIKETHIS, $this->_mlt->getType());
}
public function testSetAndGetFields() public function testSetAndGetFields()
{ {
$value = 'name,description'; $value = 'name,description';
......
...@@ -340,147 +340,6 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase ...@@ -340,147 +340,6 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
); );
} }
public function testAddAndGetFacet()
{
$fq = new Solarium_Query_Select_Facet_Query;
$fq->setKey('f1')->setQuery('category:1');
$this->_query->addFacet($fq);
$this->assertEquals(
$fq,
$this->_query->getFacet('f1')
);
}
public function testAddFacetWithoutKey()
{
$fq = new Solarium_Query_Select_Facet_Query;
$fq->setQuery('category:1');
$this->setExpectedException('Solarium_Exception');
$this->_query->addFacet($fq);
}
public function testAddFacetWithUsedKey()
{
$fq1 = new Solarium_Query_Select_Facet_Query;
$fq1->setKey('f1')->setQuery('category:1');
$fq2 = new Solarium_Query_Select_Facet_Query;
$fq2->setKey('f1')->setQuery('category:2');
$this->_query->addFacet($fq1);
$this->setExpectedException('Solarium_Exception');
$this->_query->addFacet($fq2);
}
public function testGetInvalidFacet()
{
$this->assertEquals(
null,
$this->_query->getFacet('invalidtag')
);
}
public function testAddFacets()
{
$fq1 = new Solarium_Query_Select_Facet_Query;
$fq1->setKey('f1')->setQuery('category:1');
$fq2 = new Solarium_Query_Select_Facet_Query;
$fq2->setKey('f2')->setQuery('category:2');
$facets = array('f1' => $fq1, 'f2' => $fq2);
$this->_query->addFacets($facets);
$this->assertEquals(
$facets,
$this->_query->getFacets()
);
}
public function testRemoveFacet()
{
$fq1 = new Solarium_Query_Select_Facet_Query;
$fq1->setKey('f1')->setQuery('category:1');
$fq2 = new Solarium_Query_Select_Facet_Query;
$fq2->setKey('f2')->setQuery('category:2');
$facets = array('f1' => $fq1, 'f2' => $fq2);
$this->_query->addFacets($facets);
$this->_query->removeFacet('f1');
$this->assertEquals(
array('f2' => $fq2),
$this->_query->getFacets()
);
}
public function testRemoveInvalidFacet()
{
$fq1 = new Solarium_Query_Select_Facet_Query;
$fq1->setKey('f1')->setQuery('category:1');
$fq2 = new Solarium_Query_Select_Facet_Query;
$fq2->setKey('f2')->setQuery('category:2');
$facets = array('f1' => $fq1, 'f2' => $fq2);
$this->_query->addFacets($facets);
$this->_query->removeFacet('f3'); //continue silently
$this->assertEquals(
$facets,
$this->_query->getFacets()
);
}
public function testClearFacets()
{
$fq1 = new Solarium_Query_Select_Facet_Query;
$fq1->setKey('f1')->setQuery('category:1');
$fq2 = new Solarium_Query_Select_Facet_Query;
$fq2->setKey('f2')->setQuery('category:2');
$facets = array('f1' => $fq1, 'f2' => $fq2);
$this->_query->addFacets($facets);
$this->_query->clearFacets();
$this->assertEquals(
array(),
$this->_query->getFacets()
);
}
public function testSetFacets()
{
$fq1 = new Solarium_Query_Select_Facet_Query;
$fq1->setKey('f1')->setQuery('category:1');
$fq2 = new Solarium_Query_Select_Facet_Query;
$fq2->setKey('f2')->setQuery('category:2');
$facets = array('f1' => $fq1, 'f2' => $fq2);
$this->_query->addFacets($facets);
$fq3 = new Solarium_Query_Select_Facet_Query;
$fq3->setKey('f3')->setQuery('category:3');
$fq4 = new Solarium_Query_Select_Facet_Query;
$fq4->setKey('f4')->setQuery('category:4');
$facets = array('f3' => $fq3, 'f4' => $fq4);
$this->_query->setFacets($facets);
$this->assertEquals(
$facets,
$this->_query->getFacets()
);
}
public function testConstructorWithConfig() public function testConstructorWithConfig()
{ {
$config = array( $config = array(
...@@ -493,10 +352,14 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase ...@@ -493,10 +352,14 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
array('key' => 'pub', 'tag' => array('pub'),'query' => 'published:true'), array('key' => 'pub', 'tag' => array('pub'),'query' => 'published:true'),
'online' => array('tag' => 'onl','query' => 'online:true') 'online' => array('tag' => 'onl','query' => 'online:true')
), ),
'facet' => array( 'component' => array(
array('type' => 'field', 'key' => 'categories', 'field' => 'category'), 'facetset' => array(
'category13' => array('type' => 'query', 'query' => 'category:13') 'facet' => array(
), array('type' => 'field', 'key' => 'categories', 'field' => 'category'),
'category13' => array('type' => 'query', 'query' => 'category:13')
)
),
)
); );
$query = new Solarium_Query_Select($config); $query = new Solarium_Query_Select($config);
...@@ -531,7 +394,7 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase ...@@ -531,7 +394,7 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
$fq->getQuery() $fq->getQuery()
); );
$facets = $query->getFacets(); $facets = $query->getFacetSet()->getFacets();
$this->assertEquals( $this->assertEquals(
'category', 'category',
$facets['categories']->getField() $facets['categories']->getField()
...@@ -572,6 +435,12 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase ...@@ -572,6 +435,12 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
); );
} }
public function testGetInvalidComponentAutoload()
{
$this->setExpectedException('Solarium_Exception');
$this->_query->getComponent('invalid', true);
}
public function testRemoveComponent() public function testRemoveComponent()
{ {
$mlt = new Solarium_Query_Select_Component_MoreLikeThis; $mlt = new Solarium_Query_Select_Component_MoreLikeThis;
...@@ -599,4 +468,14 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase ...@@ -599,4 +468,14 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
get_class($mlt) get_class($mlt)
); );
} }
public function testGetDisMax()
{
$dismax = $this->_query->getDisMax();
$this->assertEquals(
'Solarium_Query_Select_Component_DisMax',
get_class($dismax)
);
}
} }
\ 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_MultiQueryTest 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_MultiQuery($this->_values);
}
public function testGetValues()
{
$this->assertEquals($this->_values, $this->_facet->getValues());
}
public function testCount()
{
$this->assertEquals(count($this->_values), count($this->_facet));
}
public function testIterator()
{
$values = array();
foreach($this->_facet 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_RangeTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Facet_Range
*/
protected $_facet;
protected $_values, $_before, $_after, $_between;
public function setUp()
{
$this->_values = array(
'10.0' => 12,
'20.0' => 5,
'30.0' => 3,
);
$this->_before = 2;
$this->_after = 4;
$this->_between = 3;
$this->_facet = new Solarium_Result_Select_Facet_Range($this->_values, $this->_before, $this->_after, $this->_between);
}
public function testGetValues()
{
$this->assertEquals($this->_values, $this->_facet->getValues());
}
public function testCount()
{
$this->assertEquals(count($this->_values), count($this->_facet));
}
public function testIterator()
{
$values = array();
foreach($this->_facet AS $key => $value)
{
$values[$key] = $value;
}
$this->assertEquals($this->_values, $values);
}
public function testGetBefore()
{
$this->assertEquals($this->_before, $this->_facet->getBefore());
}
public function testGetAfter()
{
$this->assertEquals($this->_after, $this->_facet->getAfter());
}
public function testGetBetween()
{
$this->assertEquals($this->_between, $this->_facet->getBetween());
}
}
...@@ -29,6 +29,9 @@ ...@@ -29,6 +29,9 @@
* policies, either expressed or implied, of the copyright holder. * policies, either expressed or implied, of the copyright holder.
*/ */
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors',true);
// Define path to application directory // Define path to application directory
$basePath = realpath(dirname(__FILE__) . '/../'); $basePath = realpath(dirname(__FILE__) . '/../');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment