Commit 7ec23137 authored by Bas de Nooijer's avatar Bas de Nooijer

merged develop into feature branch

parents 89a7376c 31dc7f69
......@@ -81,6 +81,17 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
}
}
foreach ($this->_query->getComponents() as $component) {
switch ($component->getType())
{
case Solarium_Query_Select_Component::MORELIKETHIS:
$this->addMoreLikeThis($component);
break;
default:
throw new Solarium_Exception('Unknown component type');
}
}
$facets = $this->_query->getFacets();
if (count($facets) !== 0) {
......@@ -164,5 +175,28 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
$this->addFacetQuery($facetQuery);
}
}
/**
* Add params for morelikethis
*
* @param Solarium_Query_Select_Component_MoreLikeThis $component
* @return void
*/
public function addMoreLikeThis($component)
{
// enable morelikethis
$this->_params['mlt'] = 'true';
$this->addParam('mlt.fl', $component->getFields());
$this->addParam('mlt.mintf', $component->getMinimumTermFrequency());
$this->addParam('mlt.mindf', $component->getMinimumDocumentFrequency());
$this->addParam('mlt.minwl', $component->getMinimumWordLength());
$this->addParam('mlt.maxwl', $component->getMaximumWordLength());
$this->addParam('mlt.maxqt', $component->getMaximumQueryTerms());
$this->addParam('mlt.maxntp', $component->getMaximumNumberOfTokens());
$this->addParam('mlt.boost', $component->getBoost());
$this->addParam('mlt.qf', $component->getQueryFields());
$this->addParam('mlt.count', $component->getCount());
}
}
\ No newline at end of file
......@@ -129,8 +129,7 @@ class Solarium_Client_Request_Update extends Solarium_Client_Request
foreach ($doc->getFields() AS $name => $value) {
$boost = $doc->getFieldBoost($name);
if(is_array($value))
{
if (is_array($value)) {
foreach ($value AS $multival) {
$xml .= $this->_buildFieldXml($name, $boost, $multival);
}
......
......@@ -56,6 +56,13 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
*/
protected $_facets = array();
/**
* Component results
*
* @var array
*/
protected $_components = array();
/**
* Get a result instance for the response
*
......@@ -75,6 +82,18 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
}
}
// component results
foreach ($this->_query->getComponents() as $component) {
switch ($component->getType())
{
case Solarium_Query_Select_Component::MORELIKETHIS:
$this->_addMoreLikeThis($component);
break;
default:
throw new Solarium_Exception('Unknown component type');
}
}
// create facet results
foreach ($this->_query->getFacets() AS $facet) {
switch ($facet->getType()) {
......@@ -100,7 +119,7 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
// create the result instance that combines all data
$resultClass = $this->_query->getOption('resultclass');
return new $resultClass(
$status, $queryTime, $numFound, $documents, $this->_facets
$status, $queryTime, $numFound, $documents, $this->_facets, $this->_components
);
}
......@@ -167,4 +186,40 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
$this->_facets[$facet->getKey()] =
new Solarium_Result_Select_Facet_MultiQuery($values);
}
/**
* Add morelikethis result
*
* @param Solarium_Query_Select_Component_MoreLikeThis $component
* @return void
*/
protected function _addMoreLikeThis($component)
{
$results = array();
if (isset($this->_data['moreLikeThis'])) {
$documentClass = $this->_query->getOption('documentclass');
$searchResults = $this->_data['moreLikeThis'];
foreach ($searchResults AS $key => $result) {
// create document instances
$docs = array();
foreach ($result['docs'] AS $fields) {
$docs[] = new $documentClass($fields);
}
$results[$key] = new Solarium_Result_Select_MoreLikeThis_Result(
$result['numFound'],
$result['maxScore'],
$docs
);
}
}
$moreLikeThis = new Solarium_Result_Select_MoreLikeThis($results);
$this->_components[$component->getType()] = $moreLikeThis;
}
}
\ No newline at end of file
......@@ -97,6 +97,13 @@ class Solarium_Query_Select extends Solarium_Query
*/
protected $_facets = array();
/**
* Search components
*
* @var array
*/
protected $_components = array();
/**
* Initialize options
*
......@@ -643,4 +650,79 @@ class Solarium_Query_Select extends Solarium_Query
$this->addFacets($facets);
}
/**
* Get all registered components
*
* @return array
*/
public function getComponents()
{
return $this->_components;
}
/**
* Get a component instance by key
*
* You can optionally supply an autoload class to create a new component
* instance if there is no registered component for the given key yet.
*
* @param string $key Use one of the constants
* @param string $autoload Class to autoload if component needs to be created
* @return object|null
*/
public function getComponent($key, $autoload = null)
{
if (isset($this->_components[$key])) {
return $this->_components[$key];
} else {
if ($autoload !== null) {
$component = new $autoload;
$this->setComponent($key, $component);
return $this->_components[$key];
}
return null;
}
}
/**
* Set a component instance
*
* This overwrites any existing component registered with the same key.
*
* @param string $key
* @param object|null $value
* @return Solarium_Query_Select Provides fluent interface
*/
public function setComponent($key, $value)
{
$this->_components[$key] = $value;
return $this;
}
/**
* Remove a component instance
*
* @param string $key
* @return Solarium_Query_Select Provides fluent interface
*/
public function removeComponent($key)
{
if (isset($this->_components[$key])) {
unset($this->_components[$key]);
}
return $this;
}
/**
* Get a MoreLikeThis component instance
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Query_Select_Component_MoreLikeThis
*/
public function getMoreLikeThis()
{
return $this->getComponent('MoreLikeThis', 'Solarium_Query_Select_Component_MoreLikeThis');
}
}
\ 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
*/
/**
* Query component base class
*
* @package Solarium
* @subpackage Query
*/
class Solarium_Query_Select_Component extends Solarium_Configurable
{
/**
* Component types
*/
const MORELIKETHIS = 'morelikethis';
/**
* Component type
*
* To be implemented in extending classes
*
* @var string
*/
protected $_type = '';
/**
* Get component type
*
* @return string
*/
public function getType()
{
return $this->_type;
}
}
\ 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_MoreLikeThis
extends Solarium_Query_Select_Component
{
/**
* Component type
*
* @var string
*/
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
*
* The fields to use for similarity. NOTE: if possible, these should have a
* stored TermVector
*
* Separate multiple fields with commas.
*
* @param string $fields
* @return Solarium_Query_Component_MoreLikeThis Provides fluent interface
*/
public function setFields($fields)
{
return $this->_setOption('fields', $fields);
}
/**
* Get fields option
*
* @return string|null
*/
public function getFields()
{
return $this->getOption('fields');
}
/**
* Set minimumtermfrequency option
*
* Minimum Term Frequency - the frequency below which terms will be ignored
* in the source doc.
*
* @param int $minimum
* @return Solarium_Query_Component_MoreLikeThis Provides fluent interface
*/
public function setMinimumTermFrequency($minimum)
{
return $this->_setOption('minimumtermfrequency', $minimum);
}
/**
* Get minimumtermfrequency option
*
* @return integer|null
*/
public function getMinimumTermFrequency()
{
return $this->getOption('minimumtermfrequency');
}
/**
* Set minimumdocumentfrequency option
*
* Minimum Document Frequency - the frequency at which words will be
* ignored which do not occur in at least this many docs.
*
* @param int $minimum
* @return Solarium_Query_Component_MoreLikeThis Provides fluent interface
*/
public function setMinimumDocumentFrequency($minimum)
{
return $this->_setOption('minimumdocumentfrequency', $minimum);
}
/**
* Get minimumdocumentfrequency option
*
* @return integer|null
*/
public function getMinimumDocumentFrequency()
{
return $this->getOption('minimumdocumentfrequency');
}
/**
* Set minimumwordlength option
*
* Minimum word length below which words will be ignored.
*
* @param int $minimum
* @return Solarium_Query_Component_MoreLikeThis Provides fluent interface
*/
public function setMinimumWordLength($minimum)
{
return $this->_setOption('minimumwordlength', $minimum);
}
/**
* Get minimumwordlength option
*
* @return integer|null
*/
public function getMinimumWordLength()
{
return $this->getOption('minimumwordlength');
}
/**
* Set maximumwordlength option
*
* Maximum word length above which words will be ignored.
*
* @param int $maximum
* @return Solarium_Query_Component_MoreLikeThis Provides fluent interface
*/
public function setMaximumWordLength($maximum)
{
return $this->_setOption('maximumwordlength', $maximum);
}
/**
* Get maximumwordlength option
*
* @return integer|null
*/
public function getMaximumWordLength()
{
return $this->getOption('maximumwordlength');
}
/**
* Set maximumqueryterms option
*
* Maximum number of query terms that will be included in any generated
* query.
*
* @param int $maximum
* @return Solarium_Query_Component_MoreLikeThis Provides fluent interface
*/
public function setMaximumQueryTerms($maximum)
{
return $this->_setOption('maximumqueryterms', $maximum);
}
/**
* Get maximumqueryterms option
*
* @return integer|null
*/
public function getMaximumQueryTerms()
{
return $this->getOption('maximumqueryterms');
}
/**
* Set maximumnumberoftokens option
*
* Maximum number of tokens to parse in each example doc field that is not
* stored with TermVector support.
*
* @param int $maximum
* @return Solarium_Query_Component_MoreLikeThis Provides fluent interface
*/
public function setMaximumNumberOfTokens($maximum)
{
return $this->_setOption('maximumnumberoftokens', $maximum);
}
/**
* Get maximumnumberoftokens option
*
* @return integer|null
*/
public function getMaximumNumberOfTokens()
{
return $this->getOption('maximumnumberoftokens');
}
/**
* Set boost option
*
* If true the query will be boosted by the interesting term relevance.
*
* @param boolean $boost
* @return Solarium_Query_Component_MoreLikeThis Provides fluent interface
*/
public function setBoost($boost)
{
return $this->_setOption('boost', $boost);
}
/**
* Get boost option
*
* @return boolean|null
*/
public function getBoost()
{
return $this->getOption('boost');
}
/**
* Set queryfields option
*
* Query fields and their boosts using the same format as that used in
* DisMaxQParserPlugin. These fields must also be specified in fields.
*
* Separate multiple fields with commas.
*
* @param string $queryFields
* @return Solarium_Query_Component_MoreLikeThis 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 count option
*
* The number of similar documents to return for each result
*
* @param int $count
* @return Solarium_Query_Component_MoreLikeThis Provides fluent interface
*/
public function setCount($count)
{
return $this->_setOption('count', $count);
}
/**
* Get count option
*
* @return int|null
*/
public function getCount()
{
return $this->getOption('count');
}
}
\ No newline at end of file
......@@ -94,7 +94,9 @@ class Solarium_Query_Update extends Solarium_Query
$command = new Solarium_Query_Update_Command_Rollback($value);
break;
case 'add':
throw new Solarium_Exception("Adding documents is not supported in configuration, use the API for this");
throw new Solarium_Exception(
"Adding documents is not supported in configuration, use the API for this"
);
}
$this->add($key, $command);
......
......@@ -85,6 +85,11 @@ class Solarium_Result_Select extends Solarium_Result_Query
*/
protected $_facets;
/**
* Component results
*/
protected $_components;
/**
* Constructor
*
......@@ -96,16 +101,18 @@ class Solarium_Result_Select extends Solarium_Result_Query
* @param int $numFound
* @param array $documents
* @param array $facets
* @param array $components
* @return void
*/
public function __construct($status, $queryTime, $numFound, $documents,
$facets)
$facets, $components)
{
$this->_status = $status;
$this->_queryTime = $queryTime;
$this->_numFound = $numFound;
$this->_documents = $documents;
$this->_facets = $facets;
$this->_components = $components;
}
/**
......@@ -175,4 +182,41 @@ class Solarium_Result_Select extends Solarium_Result_Query
{
return count($this->_documents);
}
/**
* Get all component results
*
* @return array
*/
public function getComponents()
{
return $this->_components;
}
/**
* Get a component result by key
*
* @param string $key
* @return Solarium_Result_Select_Component
*/
public function getComponent($key)
{
if (isset($this->_components[$key])) {
return $this->_components[$key];
} else {
return null;
}
}
/**
* Get morelikethis component result
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Result_Select_Component_MoreLikeThis
*/
public function getMoreLikeThis()
{
return $this->getComponent(Solarium_Query_Select_Component::MORELIKETHIS);
}
}
\ 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 component morelikethis result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_MoreLikeThis implements IteratorAggregate, Countable
{
/**
* Result array
*
* @var array
*/
protected $_results;
/**
* Constructor
*
* @param array $results
* @return void
*/
public function __construct($results)
{
$this->_results = $results;
}
/**
* Get a result by key
*
* @param mixed $key
* @return Solarium_Result_Select_MoreLikeThis_Result|null
*/
public function getResult($key)
{
if (isset($this->_results[$key])) {
return $this->_results[$key];
} else {
return null;
}
}
/**
* Get all results
*
* @return array
*/
public function getResults()
{
return $this->_results;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->_results);
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
return count($this->_results);
}
}
\ 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 component morelikethis result item
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_MoreLikeThis_Result implements IteratorAggregate, Countable
{
/**
* Document instances array
*
* @var array
*/
protected $_documents;
/**
* Solr numFound
*
* This is NOT the number of MLT documents fetched from Solr!
*
* @var int
*/
protected $_numFound;
/**
* Maximum score in this MLT set
*
* @var float
*/
protected $_maximumScore;
/**
* Constructor
*
* @param int $numFound
* @param float $maxScore
* @param array $documents
* @return void
*/
public function __construct($numFound, $maxScore, $documents)
{
$this->_numFound = $numFound;
$this->_maximumScore = $maxScore;
$this->_documents = $documents;
}
/**
* get Solr numFound
*
* Returns the number of MLT documents found by Solr (this is NOT the
* number of documents fetched from Solr!)
*
* @return int
*/
public function getNumFound()
{
return $this->_numFound;
}
/**
* Get maximum score in the MLT document set
*
* @return float
*/
public function getMaximumScore()
{
return $this->_maximumScore;
}
/**
* Get all documents
*
* @return array
*/
public function getDocuments()
{
return $this->_documents;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->_documents);
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
return count($this->_documents);
}
}
\ No newline at end of file
......@@ -32,6 +32,9 @@
class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Select
*/
protected $_query;
protected $_options = array(
......@@ -130,6 +133,34 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
$request = new Solarium_Client_Request_Select($this->_options, $this->_query);
$request->getUri();
}
public function testSelectUrlWithMoreLikeThis()
{
$mlt = $this->_query->getMoreLikeThis();
$mlt->setFields('description,name');
$mlt->setMinimumTermFrequency(1);
$mlt->setMinimumDocumentFrequency(3);
$mlt->setMinimumWordLength(2);
$mlt->setMaximumWordLength(15);
$mlt->setMaximumQueryTerms(4);
$mlt->setMaximumNumberOfTokens(5);
$mlt->setBoost(true);
$mlt->setQueryFields('description');
$mlt->setCount(6);
$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&mlt=true&mlt.fl=description,name&mlt.mintf=1&mlt.mindf=3&mlt.minwl=2&mlt.maxwl=15&mlt.maxqt=4&mlt.maxntp=5&mlt.boost=1&mlt.qf=description&mlt.count=6',
urldecode($request->getUri())
);
}
}
class UnknownFacet extends Solarium_Query_Select_Facet_Field{
......
<?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_moreLikeThisTest extends PHPUnit_Framework_TestCase
{
protected $_mlt;
public function setUp()
{
$this->_mlt = new Solarium_Query_Select_Component_MoreLikeThis;
}
public function testSetAndGetFields()
{
$value = 'name,description';
$this->_mlt->setFields($value);
$this->assertEquals(
$value,
$this->_mlt->getFields()
);
}
public function testSetAndGetMinimumTermFrequency()
{
$value = 2;
$this->_mlt->setMinimumTermFrequency($value);
$this->assertEquals(
$value,
$this->_mlt->getMinimumTermFrequency()
);
}
public function testMinimumDocumentFrequency()
{
$value = 4;
$this->_mlt->setMinimumDocumentFrequency($value);
$this->assertEquals(
$value,
$this->_mlt->getMinimumDocumentFrequency()
);
}
public function testSetAndGetMinimumWordLength()
{
$value = 3;
$this->_mlt->setMinimumWordLength($value);
$this->assertEquals(
$value,
$this->_mlt->getMinimumWordLength()
);
}
public function testSetAndGetMaximumWordLength()
{
$value = 15;
$this->_mlt->setMaximumWordLength($value);
$this->assertEquals(
$value,
$this->_mlt->getMaximumWordLength()
);
}
public function testSetAndGetMaximumQueryTerms()
{
$value = 5;
$this->_mlt->setMaximumQueryTerms($value);
$this->assertEquals(
$value,
$this->_mlt->getMaximumQueryTerms()
);
}
public function testSetAndGetMaximumNumberOfTokens()
{
$value = 5;
$this->_mlt->setMaximumNumberOfTokens($value);
$this->assertEquals(
$value,
$this->_mlt->getMaximumNumberOfTokens()
);
}
public function testSetAndGetBoost()
{
$value = true;
$this->_mlt->setBoost($value);
$this->assertEquals(
$value,
$this->_mlt->getBoost()
);
}
public function testSetAndGetQueryFields()
{
$value = 'content,name';
$this->_mlt->setQueryFields($value);
$this->assertEquals(
$value,
$this->_mlt->getQueryFields()
);
}
public function testSetAndGetCount()
{
$value = 8;
$this->_mlt->setCount($value);
$this->assertEquals(
$value,
$this->_mlt->getCount()
);
}
}
<?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_ComponentTest extends PHPUnit_Framework_TestCase
{
public function testGetType()
{
$component = new TestComponent();
$this->assertEquals('testtype', $component->getType());
}
}
class TestComponent extends Solarium_Query_Select_Component{
protected $_type = 'testtype';
}
\ No newline at end of file
......@@ -541,4 +541,62 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
$facets['category13']->getQuery()
);
}
}
public function testSetAndGetComponents()
{
$mlt = new Solarium_Query_Select_Component_MoreLikeThis;
$this->_query->setComponent('mlt',$mlt);
$this->assertEquals(
array('mlt' => $mlt),
$this->_query->getComponents()
);
}
public function testSetAndGetComponent()
{
$mlt = new Solarium_Query_Select_Component_MoreLikeThis;
$this->_query->setComponent('mlt',$mlt);
$this->assertEquals(
$mlt,
$this->_query->getComponent('mlt')
);
}
public function testGetInvalidComponent()
{
$this->assertEquals(
null,
$this->_query->getComponent('invalid')
);
}
public function testRemoveComponent()
{
$mlt = new Solarium_Query_Select_Component_MoreLikeThis;
$this->_query->setComponent('mlt',$mlt);
$this->assertEquals(
array('mlt' => $mlt),
$this->_query->getComponents()
);
$this->_query->removeComponent('mlt');
$this->assertEquals(
array(),
$this->_query->getComponents()
);
}
public function testGetMoreLikeThis()
{
$mlt = $this->_query->getMoreLikeThis();
$this->assertEquals(
'Solarium_Query_Select_Component_MoreLikeThis',
get_class($mlt)
);
}
}
\ 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_MoreLikeThis_ResultTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_MoreLikeThis_Result
*/
protected $_mltResult;
public function setUp()
{
$this->_docs = array(
new Solarium_Document_ReadOnly(array('id'=>1,'name'=>'test1')),
new Solarium_Document_ReadOnly(array('id'=>2,'name'=>'test2')),
);
$this->_mltResult = new Solarium_Result_Select_MoreLikeThis_Result(2, 5.13, $this->_docs);
}
public function testGetNumFound()
{
$this->assertEquals(2, $this->_mltResult->getNumFound());
}
public function testGetMaximumScore()
{
$this->assertEquals(5.13, $this->_mltResult->getMaximumScore());
}
public function testGetDocuments()
{
$this->assertEquals($this->_docs, $this->_mltResult->getDocuments());
}
public function testIterator()
{
$docs = array();
foreach($this->_mltResult AS $key => $doc)
{
$docs[$key] = $doc;
}
$this->assertEquals($this->_docs, $docs);
}
public function testCount()
{
$this->assertEquals(count($this->_docs), count($this->_mltResult));
}
}
<?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_MoreLikeThisTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_MoreLikeThis
*/
protected $_mlt;
protected $_results;
public function setUp()
{
$docs = array(
new Solarium_Document_ReadOnly(array('id'=>1,'name'=>'test1')),
new Solarium_Document_ReadOnly(array('id'=>2,'name'=>'test2')),
);
$this->_results = array(
'key1' => new Solarium_Result_Select_MoreLikeThis_Result(2, 5.13, $docs),
'key2' => new Solarium_Result_Select_MoreLikeThis_Result(2, 2.3, $docs),
);
$this->_mlt = new Solarium_Result_Select_MoreLikeThis($this->_results);
}
public function testGetResults()
{
$this->assertEquals($this->_results, $this->_mlt->getResults());
}
public function testGetResult()
{
$this->assertEquals(
$this->_results['key1'],
$this->_mlt->getResult('key1')
);
}
public function testGetInvalidResult()
{
$this->assertEquals(
null,
$this->_mlt->getResult('invalid')
);
}
public function testIterator()
{
$items = array();
foreach($this->_mlt AS $key => $item)
{
$items[$key] = $item;
}
$this->assertEquals($this->_results, $items);
}
public function testCount()
{
$this->assertEquals(count($this->_results), count($this->_mlt));
}
}
......@@ -47,7 +47,11 @@ class Solarium_Result_SelectTest extends Solarium_Result_QueryTest
'f2' => new Solarium_Result_Select_Facet_Field(array('b' => 5)),
);
$this->_result = new Solarium_Result_Select(0,45,100, $this->_docs, $this->_facets);
$this->_components = array(
Solarium_Query_Select_Component::MORELIKETHIS => new Solarium_Result_Select_MoreLikeThis(array())
);
$this->_result = new Solarium_Result_Select(0,45,100, $this->_docs, $this->_facets, $this->_components);
}
public function testGetNumFound()
......@@ -80,6 +84,35 @@ class Solarium_Result_SelectTest extends Solarium_Result_QueryTest
$this->assertEquals(3, count($this->_result));
}
public function testGetComponents()
{
$this->assertEquals($this->_components, $this->_result->getComponents());
}
public function testGetComponent()
{
$this->assertEquals(
$this->_components[Solarium_Query_Select_Component::MORELIKETHIS],
$this->_result->getComponent(Solarium_Query_Select_Component::MORELIKETHIS)
);
}
public function testGetInvalidComponent()
{
$this->assertEquals(
null,
$this->_result->getComponent('invalid')
);
}
public function testGetMoreLikeThis()
{
$this->assertEquals(
$this->_components[Solarium_Query_Select_Component::MORELIKETHIS],
$this->_result->getMoreLikeThis()
);
}
public function testIterator()
{
$docs = array();
......@@ -90,5 +123,5 @@ class Solarium_Result_SelectTest extends Solarium_Result_QueryTest
$this->assertEquals($this->_docs, $docs);
}
}
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