Commit 325f917e authored by Markus Kalkbrenner's avatar Markus Kalkbrenner Committed by GitHub

Introduce Spellcheck component as successor of the 3.x Suggester. (#538)

The 3.x Suggester was in fact Spellcheck. the 4.x Suggester is a real Suggester now.
parent 1e011d9c
<?php
require(__DIR__.'/init.php');
htmlHeader();
// create a client instance
$client = new Solarium\Client($config);
// get a spellcheck query instance
$query = $client->createSpellcheck();
$query->setQuery('ap ip v'); //multiple terms
$query->setDictionary('suggest');
$query->setOnlyMorePopular(true);
$query->setCount(10);
$query->setCollate(true);
// this executes the query and returns the result
$resultset = $client->spellcheck($query);
echo '<b>Query:</b> '.$query->getQuery().'<hr/>';
// display results for each term
foreach ($resultset as $term => $termResult) {
echo '<h3>' . $term . '</h3>';
echo 'NumFound: '.$termResult->getNumFound().'<br/>';
echo 'StartOffset: '.$termResult->getStartOffset().'<br/>';
echo 'EndOffset: '.$termResult->getEndOffset().'<br/>';
echo 'Suggestions:<br/>';
foreach ($termResult as $result) {
echo '- '.$result.'<br/>';
}
echo '<hr/>';
}
// display collation
echo 'Collation: '.$resultset->getCollation();
htmlFooter();
...@@ -9,10 +9,9 @@ $client = new Solarium\Client($config); ...@@ -9,10 +9,9 @@ $client = new Solarium\Client($config);
// get a suggester query instance // get a suggester query instance
$query = $client->createSuggester(); $query = $client->createSuggester();
$query->setQuery('ap ip v'); //multiple terms $query->setQuery('ap ip v'); //multiple terms
$query->setDictionary('suggest'); $query->setDictionary('mySuggester');
$query->setOnlyMorePopular(true); $query->setBuild(true);
$query->setCount(10); $query->setCount(10);
$query->setCollate(true);
// this executes the query and returns the result // this executes the query and returns the result
$resultset = $client->suggester($query); $resultset = $client->suggester($query);
......
...@@ -115,6 +115,11 @@ class Client extends Configurable implements ClientInterface ...@@ -115,6 +115,11 @@ class Client extends Configurable implements ClientInterface
*/ */
const QUERY_TERMS = 'terms'; const QUERY_TERMS = 'terms';
/**
* Querytype spellcheck.
*/
const QUERY_SPELLCHECK = 'spell';
/** /**
* Querytype suggester. * Querytype suggester.
*/ */
...@@ -155,6 +160,7 @@ class Client extends Configurable implements ClientInterface ...@@ -155,6 +160,7 @@ class Client extends Configurable implements ClientInterface
self::QUERY_ANALYSIS_DOCUMENT => 'Solarium\QueryType\Analysis\Query\Document', self::QUERY_ANALYSIS_DOCUMENT => 'Solarium\QueryType\Analysis\Query\Document',
self::QUERY_ANALYSIS_FIELD => 'Solarium\QueryType\Analysis\Query\Field', self::QUERY_ANALYSIS_FIELD => 'Solarium\QueryType\Analysis\Query\Field',
self::QUERY_TERMS => 'Solarium\QueryType\Terms\Query', self::QUERY_TERMS => 'Solarium\QueryType\Terms\Query',
self::QUERY_SPELLCHECK => 'Solarium\QueryType\Spellcheck\Query',
self::QUERY_SUGGESTER => 'Solarium\QueryType\Suggester\Query', self::QUERY_SUGGESTER => 'Solarium\QueryType\Suggester\Query',
self::QUERY_EXTRACT => 'Solarium\QueryType\Extract\Query', self::QUERY_EXTRACT => 'Solarium\QueryType\Extract\Query',
self::QUERY_REALTIME_GET => 'Solarium\QueryType\RealtimeGet\Query', self::QUERY_REALTIME_GET => 'Solarium\QueryType\RealtimeGet\Query',
...@@ -948,6 +954,22 @@ class Client extends Configurable implements ClientInterface ...@@ -948,6 +954,22 @@ class Client extends Configurable implements ClientInterface
return $this->execute($query, $endpoint); return $this->execute($query, $endpoint);
} }
/**
* Execute a spellcheck query.
*
* This is a convenience method that forwards the query to the
* execute method, thus allowing for an easy to use and clean API.
*
* @param QueryInterface|\Solarium\QueryType\Spellcheck\Query $query
* @param Endpoint|string|null $endpoint
*
* @return \Solarium\QueryType\Spellcheck\Result\Result
*/
public function spellcheck(QueryInterface $query, $endpoint = null)
{
return $this->execute($query, $endpoint);
}
/** /**
* Execute a suggester query. * Execute a suggester query.
* *
...@@ -1119,6 +1141,18 @@ class Client extends Configurable implements ClientInterface ...@@ -1119,6 +1141,18 @@ class Client extends Configurable implements ClientInterface
return $this->createQuery(self::QUERY_TERMS, $options); return $this->createQuery(self::QUERY_TERMS, $options);
} }
/**
* Create a specllcheck query instance.
*
* @param mixed $options
*
* @return \Solarium\QueryType\Spellcheck\Query
*/
public function createSpellcheck($options = null)
{
return $this->createQuery(self::QUERY_SPELLCHECK, $options);
}
/** /**
* Create a suggester query instance. * Create a suggester query instance.
* *
......
...@@ -432,6 +432,18 @@ interface ClientInterface ...@@ -432,6 +432,18 @@ interface ClientInterface
*/ */
public function terms(QueryInterface $query, $endpoint = null); public function terms(QueryInterface $query, $endpoint = null);
/**
* Execute a spellcheck query
*
* @internal This is a convenience method that forwards the query to the
* execute method, thus allowing for an easy to use and clean API.
*
* @param QueryInterface|\Solarium\QueryType\Spellcheck\Query $query
* @param Endpoint|string|null $endpoint
* @return \Solarium\QueryType\Spellcheck\Result\Result
*/
public function spellcheck(QueryInterface $query, $endpoint = null);
/** /**
* Execute a suggester query * Execute a suggester query
* *
...@@ -534,6 +546,14 @@ interface ClientInterface ...@@ -534,6 +546,14 @@ interface ClientInterface
*/ */
public function createTerms($options = null); public function createTerms($options = null);
/**
* Create a spellcheck query instance
*
* @param mixed $options
* @return \Solarium\QueryType\Spellcheck\Query
*/
public function createSpellcheck($options = null);
/** /**
* Create a suggester query instance * Create a suggester query instance
* *
......
...@@ -47,7 +47,7 @@ use Solarium\QueryType\Select\ResponseParser\Component\Spellcheck as ResponsePar ...@@ -47,7 +47,7 @@ use Solarium\QueryType\Select\ResponseParser\Component\Spellcheck as ResponsePar
/** /**
* Spellcheck component. * Spellcheck component.
* *
* @link http://wiki.apache.org/solr/SpellCheckComponent * @link http://wiki.apache.org/solr/SpellcheckComponent
*/ */
class Spellcheck extends AbstractComponent class Spellcheck extends AbstractComponent
{ {
......
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\QueryType\Select\Query\Component;
use Solarium\QueryType\Select\Query\Query as SelectQuery;
use Solarium\QueryType\Select\RequestBuilder\Component\Spellcheck as RequestBuilder;
use Solarium\QueryType\Select\ResponseParser\Component\Spellcheck as ResponseParser;
/**
* Spellcheck component.
*
* @link http://wiki.apache.org/solr/SpellcheckComponent
*/
class Spellcheck extends AbstractComponent
{
/**
* Used to further customize collation parameters.
*
* @var array
*/
protected $collateParams = array();
/**
* Get component type.
*
* @return string
*/
public function getType()
{
return SelectQuery::COMPONENT_SPELLCHECK;
}
/**
* Get a requestbuilder for this query.
*
* @return RequestBuilder
*/
public function getRequestBuilder()
{
return new RequestBuilder();
}
/**
* Get a response parser for this query.
*
* @return ResponseParser
*/
public function getResponseParser()
{
return new ResponseParser();
}
/**
* Set spellcheck query option.
*
* @param string $query
* @param array $bind Bind values for placeholders in the query string
*
* @return self Provides fluent interface
*/
public function setQuery($query, $bind = null)
{
if (!is_null($bind)) {
$query = $this->getQueryInstance()->getHelper()->assemble($query, $bind);
}
return $this->setOption('query', trim($query));
}
/**
* Get query option.
*
* @return string|null
*/
public function getQuery()
{
return $this->getOption('query');
}
/**
* Set build option.
*
* Build the spellcheck?
*
* @param boolean $build
*
* @return self Provides fluent interface
*/
public function setBuild($build)
{
return $this->setOption('build', $build);
}
/**
* Get build option.
*
* @return boolean|null
*/
public function getBuild()
{
return $this->getOption('build');
}
/**
* Set reload option.
*
* Reload the dictionary?
*
* @param boolean $reload
*
* @return self Provides fluent interface
*/
public function setReload($reload)
{
return $this->setOption('reload', $reload);
}
/**
* Get fragsize option.
*
* @return boolean|null
*/
public function getReload()
{
return $this->getOption('reload');
}
/**
* Set dictionary option.
*
* The name of the dictionary to use
*
* @param string $dictionary
*
* @return self Provides fluent interface
*/
public function setDictionary($dictionary)
{
return $this->setOption('dictionary', $dictionary);
}
/**
* Get dictionary option.
*
* @return string|null
*/
public function getDictionary()
{
return $this->getOption('dictionary');
}
/**
* Set count option.
*
* The maximum number of suggestions to return
*
* @param int $count
*
* @return self 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');
}
/**
* Set onlyMorePopular option.
*
* Only return suggestions that result in more hits for the query than the existing query
*
* @param boolean $onlyMorePopular
*
* @return self Provides fluent interface
*/
public function setOnlyMorePopular($onlyMorePopular)
{
return $this->setOption('onlymorepopular', $onlyMorePopular);
}
/**
* Get onlyMorePopular option.
*
* @return boolean|null
*/
public function getOnlyMorePopular()
{
return $this->getOption('onlymorepopular');
}
/**
* Set extendedResults option.
*
* @param boolean $extendedResults
*
* @return self Provides fluent interface
*/
public function setExtendedResults($extendedResults)
{
return $this->setOption('extendedresults', $extendedResults);
}
/**
* Get extendedResults option.
*
* @return boolean|null
*/
public function getExtendedResults()
{
return $this->getOption('extendedresults');
}
/**
* Set collate option.
*
* @param boolean $collate
*
* @return self Provides fluent interface
*/
public function setCollate($collate)
{
return $this->setOption('collate', $collate);
}
/**
* Get collate option.
*
* @return boolean|null
*/
public function getCollate()
{
return $this->getOption('collate');
}
/**
* Set maxCollations option.
*
* @param int $maxCollations
*
* @return self Provides fluent interface
*/
public function setMaxCollations($maxCollations)
{
return $this->setOption('maxcollations', $maxCollations);
}
/**
* Get maxCollations option.
*
* @return int|null
*/
public function getMaxCollations()
{
return $this->getOption('maxcollations');
}
/**
* Set maxCollationTries option.
*
* @param string $maxCollationTries
*
* @return self Provides fluent interface
*/
public function setMaxCollationTries($maxCollationTries)
{
return $this->setOption('maxcollationtries', $maxCollationTries);
}
/**
* Get maxCollationTries option.
*
* @return string|null
*/
public function getMaxCollationTries()
{
return $this->getOption('maxcollationtries');
}
/**
* Set maxCollationEvaluations option.
*
* @param int $maxCollationEvaluations
*
* @return self Provides fluent interface
*/
public function setMaxCollationEvaluations($maxCollationEvaluations)
{
return $this->setOption('maxcollationevaluations', $maxCollationEvaluations);
}
/**
* Get maxCollationEvaluations option.
*
* @return int|null
*/
public function getMaxCollationEvaluations()
{
return $this->getOption('maxcollationevaluations');
}
/**
* Set collateExtendedResults option.
*
* @param string $collateExtendedResults
*
* @return self Provides fluent interface
*/
public function setCollateExtendedResults($collateExtendedResults)
{
return $this->setOption('collateextendedresults', $collateExtendedResults);
}
/**
* Get collateExtendedResults option.
*
* @return string|null
*/
public function getCollateExtendedResults()
{
return $this->getOption('collateextendedresults');
}
/**
* Set accuracy option.
*
* @param float $accuracy
*
* @return self Provides fluent interface
*/
public function setAccuracy($accuracy)
{
return $this->setOption('accuracy', $accuracy);
}
/**
* Get accuracy option.
*
* @return float|null
*/
public function getAccuracy()
{
return $this->getOption('accuracy');
}
/**
* Set a collation param.
*
* @param string $param
* @param mixed $value
*
* @return self Provides fluent interface
*/
public function setCollateParam($param, $value)
{
$this->collateParams[$param] = $value;
return $this;
}
/**
* Returns the array of collate params.
*
* @return array
*/
public function getCollateParams()
{
return $this->collateParams;
}
}
...@@ -107,6 +107,11 @@ class Query extends BaseQuery ...@@ -107,6 +107,11 @@ class Query extends BaseQuery
*/ */
const COMPONENT_SPELLCHECK = 'spellcheck'; const COMPONENT_SPELLCHECK = 'spellcheck';
/**
* Query component spellcheck.
*/
const COMPONENT_SUGGESTER = 'suggest';
/** /**
* Query component grouping. * Query component grouping.
*/ */
......
...@@ -42,7 +42,7 @@ namespace Solarium\QueryType\Select\Result; ...@@ -42,7 +42,7 @@ namespace Solarium\QueryType\Select\Result;
use Solarium\QueryType\Select\Query\Query as SelectQuery; use Solarium\QueryType\Select\Query\Query as SelectQuery;
use Solarium\Core\Query\Result\QueryType as BaseResult; use Solarium\Core\Query\Result\QueryType as BaseResult;
use Solarium\QueryType\Select\Result\Spellcheck\Result as SpellCheckResult; use Solarium\QueryType\Select\Result\Spellcheck\Result as SpellcheckResult;
use Solarium\QueryType\Select\Result\Stats\Result as StatsResult; use Solarium\QueryType\Select\Result\Stats\Result as StatsResult;
use Solarium\QueryType\Select\Result\Debug\Result as DebugResult; use Solarium\QueryType\Select\Result\Debug\Result as DebugResult;
use Solarium\QueryType\Select\Result\Grouping\Result as GroupingResult; use Solarium\QueryType\Select\Result\Grouping\Result as GroupingResult;
...@@ -320,7 +320,7 @@ class Result extends BaseResult implements \IteratorAggregate, \Countable ...@@ -320,7 +320,7 @@ class Result extends BaseResult implements \IteratorAggregate, \Countable
* *
* This is a convenience method that maps presets to getComponent * This is a convenience method that maps presets to getComponent
* *
* @return SpellCheckResult|null * @return SpellcheckResult|null
*/ */
public function getSpellcheck() public function getSpellcheck()
{ {
......
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\QueryType\Spellcheck;
use Solarium\Core\Query\AbstractQuery as BaseQuery;
use Solarium\Core\Client\Client;
/**
* Spellcheck Query.
*
* Can be used for an autocomplete feature. See http://wiki.apache.org/solr/SpellcheckComponent for more info.
*/
class Query extends BaseQuery
{
/**
* Default options.
*
* @var array
*/
protected $options = array(
'handler' => 'spell',
'resultclass' => 'Solarium\QueryType\Spellcheck\Result\Result',
'termclass' => 'Solarium\QueryType\Spellcheck\Result\Term',
'omitheader' => true,
'build' => false,
);
/**
* Get type for this query.
*
* @return string
*/
public function getType()
{
return Client::QUERY_SPELLCHECK;
}
/**
* Get a requestbuilder for this query.
*
* @return RequestBuilder
*/
public function getRequestBuilder()
{
return new RequestBuilder();
}
/**
* Get a response parser for this query.
*
* @return ResponseParser
*/
public function getResponseParser()
{
return new ResponseParser();
}
/**
* Set query option.
*
* Query to spellcheck
*
* @param string $query
*
* @return self Provides fluent interface
*/
public function setQuery($query)
{
return $this->setOption('query', $query);
}
/**
* Get query option.
*
* @return string|null
*/
public function getQuery()
{
return $this->getOption('query');
}
/**
* Set dictionary option.
*
* The name of the dictionary to use
*
* @param string $dictionary
*
* @return self Provides fluent interface
*/
public function setDictionary($dictionary)
{
return $this->setOption('dictionary', $dictionary);
}
/**
* Get dictionary option.
*
* @return string|null
*/
public function getDictionary()
{
return $this->getOption('dictionary');
}
/**
* Set count option.
*
* The maximum number of suggestions to return
*
* @param int $count
*
* @return self 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');
}
/**
* Set onlyMorePopular option.
*
* Only return suggestions that result in more hits for the query than the existing query
*
* @param boolean $onlyMorePopular
*
* @return self Provides fluent interface
*/
public function setOnlyMorePopular($onlyMorePopular)
{
return $this->setOption('onlymorepopular', $onlyMorePopular);
}
/**
* Get onlyMorePopular option.
*
* @return boolean|null
*/
public function getOnlyMorePopular()
{
return $this->getOption('onlymorepopular');
}
/**
* Set collate option.
*
* @param boolean $collate
*
* @return self Provides fluent interface
*/
public function setCollate($collate)
{
return $this->setOption('collate', $collate);
}
/**
* Get collate option.
*
* @return boolean|null
*/
public function getCollate()
{
return $this->getOption('collate');
}
/**
* Set build option.
*
* @param boolean $build
*
* @return self Provides fluent interface
*/
public function setBuild($build)
{
return $this->setOption('build', $build);
}
/**
* Get build option.
*
* @return boolean|null
*/
public function getBuild()
{
return $this->getOption('build');
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\QueryType\Spellcheck;
use Solarium\Core\Client\Request;
use Solarium\Core\Query\AbstractRequestBuilder as BaseRequestBuilder;
use Solarium\Core\Query\QueryInterface;
/**
* Build a Spellcheck query request.
*/
class RequestBuilder extends BaseRequestBuilder
{
/**
* Build request for a Suggester query.
*
* @param QueryInterface|Query $query
*
* @return Request
*/
public function build(QueryInterface $query)
{
$request = parent::build($query);
$request->addParam('spellcheck', 'true');
$request->addParam('spellcheck.q', $query->getQuery());
$request->addParam('spellcheck.dictionary', $query->getDictionary());
$request->addParam('spellcheck.count', $query->getCount());
$request->addParam('spellcheck.onlyMorePopular', $query->getOnlyMorePopular());
$request->addParam('spellcheck.collate', $query->getCollate());
$request->addParam('spellcheck.build', $query->getBuild());
return $request;
}
}
<?php
/**
* Copyright 2011 Gasol Wu. PIXNET Digital Media Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Gasol Wu <gasol.wu@gmail.com>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\QueryType\Spellcheck;
use Solarium\Core\Query\AbstractResponseParser as ResponseParserAbstract;
use Solarium\Core\Query\ResponseParserInterface as ResponseParserInterface;
use Solarium\QueryType\Spellcheck\Result\Result;
/**
* Parse Spellcheck response data.
*/
class ResponseParser extends ResponseParserAbstract implements ResponseParserInterface
{
/**
* Get result data for the response.
*
* @param Result $result
*
* @return array
*/
public function parse($result)
{
$data = $result->getData();
$query = $result->getQuery();
$suggestions = array();
$allSuggestions = array();
$collation = null;
if (isset($data['spellcheck']['suggestions']) && is_array($data['spellcheck']['suggestions'])) {
$suggestResults = $data['spellcheck']['suggestions'];
$termClass = $query->getOption('termclass');
if ($query->getResponseWriter() == $query::WT_JSON) {
$suggestResults = $this->convertToKeyValueArray($suggestResults);
}
foreach ($suggestResults as $term => $termData) {
if ($term == 'collation') {
$collation = $termData;
} else {
if (!array_key_exists(0, $termData)) {
$termData = array($termData);
}
foreach ($termData as $currentTermData) {
$allSuggestions[] = $this->createTerm($termClass, $currentTermData);
if (!array_key_exists($term, $suggestions)) {
$suggestions[$term] = $this->createTerm($termClass, $currentTermData);
}
}
}
}
}
return $this->addHeaderInfo(
$data,
array(
'results' => $suggestions,
'all' => $allSuggestions,
'collation' => $collation,
)
);
}
private function createTerm($termClass, array $termData)
{
return new $termClass(
$termData['numFound'],
$termData['startOffset'],
$termData['endOffset'],
$termData['suggestion']
);
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\QueryType\Spellcheck\Result;
use Solarium\Core\Query\Result\QueryType as BaseResult;
/**
* Spellcheck query result.
*/
class Result extends BaseResult implements \IteratorAggregate, \Countable
{
/**
* Status code returned by Solr.
*
* @var int
*/
protected $status;
/**
* Solr index queryTime.
*
* This doesn't include things like the HTTP responsetime. Purely the Solr
* query execution time.
*
* @var int
*/
protected $queryTime;
/**
* Suggester results.
*
* @var array
*/
protected $results;
/**
* Suggester flat results.
*
* @var array
*/
protected $all;
/**
* Collation result.
*
* Only available when collate is enabled in the suggester query
*
* @var string
*/
protected $collation;
/**
* Get Solr status code.
*
* This is not the HTTP status code! The normal value for success is 0.
*
* @return int
*/
public function getStatus()
{
$this->parseResponse();
return $this->status;
}
/**
* Get Solr query time.
*
* This doesn't include things like the HTTP responsetime. Purely the Solr
* query execution time.
*
* @return int
*/
public function getQueryTime()
{
$this->parseResponse();
return $this->queryTime;
}
/**
* Get all results.
*
* @return array
*/
public function getResults()
{
$this->parseResponse();
return $this->results;
}
/**
* Get flat results.
*
* @return array
*/
public function getAll()
{
$this->parseResponse();
return $this->all;
}
/**
* Get results for a specific term.
*
* @param string $term
*
* @return array
*/
public function getTerm($term)
{
$this->parseResponse();
if (isset($this->results[$term])) {
return $this->results[$term];
} else {
return array();
}
}
/**
* IteratorAggregate implementation.
*
* @return \ArrayIterator
*/
public function getIterator()
{
$this->parseResponse();
return new \ArrayIterator($this->results);
}
/**
* Countable implementation.
*
* @return int
*/
public function count()
{
$this->parseResponse();
return count($this->results);
}
/**
* Get collation.
*
* @return null|string
*/
public function getCollation()
{
$this->parseResponse();
return $this->collation;
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\QueryType\Spellcheck\Result;
/**
* Spellcheck query term result.
*/
class Term implements \IteratorAggregate, \Countable
{
/**
* NumFound.
*
* @var int
*/
protected $numFound;
/**
* StartOffset.
*
* @var int
*/
protected $startOffset;
/**
* EndOffset.
*
* @var int
*/
protected $endOffset;
/**
* Suggestions.
*
* @var array
*/
protected $suggestions;
/**
* Constructor.
*
* @param int $numFound
* @param int $startOffset
* @param int $endOffset
* @param array $suggestions
*/
public function __construct($numFound, $startOffset, $endOffset, $suggestions)
{
$this->numFound = $numFound;
$this->startOffset = $startOffset;
$this->endOffset = $endOffset;
$this->suggestions = $suggestions;
}
/**
* Get NumFound.
*
* @return int
*/
public function getNumFound()
{
return $this->numFound;
}
/**
* Get StartOffset.
*
* @return int
*/
public function getStartOffset()
{
return $this->startOffset;
}
/**
* Get EndOffset.
*
* @return int
*/
public function getEndOffset()
{
return $this->endOffset;
}
/**
* Get suggestions.
*
* @return array
*/
public function getSuggestions()
{
return $this->suggestions;
}
/**
* IteratorAggregate implementation.
*
* @return \ArrayIterator
*/
public function getIterator()
{
return new \ArrayIterator($this->suggestions);
}
/**
* Countable implementation.
*
* @return int
*/
public function count()
{
return count($this->suggestions);
}
}
...@@ -56,12 +56,13 @@ class Query extends BaseQuery ...@@ -56,12 +56,13 @@ class Query extends BaseQuery
* @var array * @var array
*/ */
protected $options = array( protected $options = array(
'handler' => 'suggest', 'handler' => 'suggest',
'resultclass' => 'Solarium\QueryType\Suggester\Result\Result', 'resultclass' => 'Solarium\QueryType\Suggester\Result\Result',
'termclass' => 'Solarium\QueryType\Suggester\Result\Term', 'dictionaryclass' => 'Solarium\QueryType\Suggester\Result\Dictionary',
'omitheader' => true, 'termclass' => 'Solarium\QueryType\Suggester\Result\Term',
'build' => false, 'omitheader' => true,
'reload' => false, 'build' => false,
'reload' => false,
); );
/** /**
......
...@@ -62,44 +62,36 @@ class ResponseParser extends ResponseParserAbstract implements ResponseParserInt ...@@ -62,44 +62,36 @@ class ResponseParser extends ResponseParserAbstract implements ResponseParserInt
$data = $result->getData(); $data = $result->getData();
$query = $result->getQuery(); $query = $result->getQuery();
$suggestions = array(); $dictionaries = [];
$allSuggestions = array(); $allSuggestions = [];
$collation = null;
if (isset($data['spellcheck']['suggestions']) && is_array($data['spellcheck']['suggestions'])) { if (isset($data['suggest']) && is_array($data['suggest'])) {
$suggestResults = $data['spellcheck']['suggestions']; $dictionaryClass = $query->getOption('dictionaryclass');
$termClass = $query->getOption('termclass'); $termClass = $query->getOption('termclass');
if ($query->getResponseWriter() == $query::WT_JSON) { foreach ($data['suggest'] as $dictionary => $dictionaryResults) {
$suggestResults = $this->convertToKeyValueArray($suggestResults); $terms = [];
} foreach ($dictionaryResults as $term => $termData) {
$allSuggestions[] = $this->createTerm($termClass, $termData);
foreach ($suggestResults as $term => $termData) { $terms[$term] = $this->createTerm($termClass, $termData);
if ($term == 'collation') {
$collation = $termData;
} else {
if (!array_key_exists(0, $termData)) {
$termData = array($termData);
}
foreach ($termData as $currentTermData) {
$allSuggestions[] = $this->createTerm($termClass, $currentTermData);
if (!array_key_exists($term, $suggestions)) {
$suggestions[$term] = $this->createTerm($termClass, $currentTermData);
}
}
} }
$dictionaries[$dictionary] = $this->createDictionary($dictionaryClass, $terms);
} }
} }
return $this->addHeaderInfo( return $this->addHeaderInfo(
$data, $data,
array( [
'results' => $suggestions, 'results' => $dictionaries,
'all' => $allSuggestions, 'all' => $allSuggestions,
'collation' => $collation, ]
) );
}
private function createDictionary($dictionaryClass, array $terms)
{
return new $dictionaryClass(
$terms
); );
} }
...@@ -107,9 +99,7 @@ class ResponseParser extends ResponseParserAbstract implements ResponseParserInt ...@@ -107,9 +99,7 @@ class ResponseParser extends ResponseParserAbstract implements ResponseParserInt
{ {
return new $termClass( return new $termClass(
$termData['numFound'], $termData['numFound'],
$termData['startOffset'], $termData['suggestions']
$termData['endOffset'],
$termData['suggestion']
); );
} }
} }
<?php
/**
* Copyright 2011 Markus Kalkbrenner. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\QueryType\Suggester\Result;
/**
* Suggester query dictionary result.
*/
class Dictionary implements \IteratorAggregate, \Countable
{
/**
* Suggestions.
*
* @var Term[]
*/
protected $terms;
/**
* Constructor.
*
* @param Term[] $terms
*/
public function __construct(array $terms)
{
$this->terms = $terms;
}
/**
* Get Terms.
*
* @return Term[]
*/
public function getTerms()
{
return $this->terms;
}
/**
* Get results for a specific term.
*
* @param string $term
*
* @return Term|null
*/
public function getTerm($term)
{
if (isset($this->terms[$term])) {
return $this->terms[$term];
} else {
return null;
}
}
/**
* IteratorAggregate implementation.
*
* @return \ArrayIterator
*/
public function getIterator()
{
return new \ArrayIterator($this->terms);
}
/**
* Countable implementation.
*
* @return int
*/
public function count()
{
return count($this->terms);
}
}
...@@ -78,15 +78,6 @@ class Result extends BaseResult implements \IteratorAggregate, \Countable ...@@ -78,15 +78,6 @@ class Result extends BaseResult implements \IteratorAggregate, \Countable
*/ */
protected $all; protected $all;
/**
* Collation result.
*
* Only available when collate is enabled in the suggester query
*
* @var string
*/
protected $collation;
/** /**
* Get Solr status code. * Get Solr status code.
* *
...@@ -141,20 +132,20 @@ class Result extends BaseResult implements \IteratorAggregate, \Countable ...@@ -141,20 +132,20 @@ class Result extends BaseResult implements \IteratorAggregate, \Countable
} }
/** /**
* Get results for a specific term. * Get results for a specific dictionary.
* *
* @param string $term * @param string $dictionary
* *
* @return array * @return Dictionary|null
*/ */
public function getTerm($term) public function getDictionary($dictionary)
{ {
$this->parseResponse(); $this->parseResponse();
if (isset($this->results[$term])) { if (isset($this->results[$dictionary])) {
return $this->results[$term]; return $this->results[$dictionary];
} else { } else {
return array(); return null;
} }
} }
...@@ -182,15 +173,4 @@ class Result extends BaseResult implements \IteratorAggregate, \Countable ...@@ -182,15 +173,4 @@ class Result extends BaseResult implements \IteratorAggregate, \Countable
return count($this->results); return count($this->results);
} }
/**
* Get collation.
*
* @return null|string
*/
public function getCollation()
{
$this->parseResponse();
return $this->collation;
}
} }
...@@ -52,20 +52,6 @@ class Term implements \IteratorAggregate, \Countable ...@@ -52,20 +52,6 @@ class Term implements \IteratorAggregate, \Countable
*/ */
protected $numFound; protected $numFound;
/**
* StartOffset.
*
* @var int
*/
protected $startOffset;
/**
* EndOffset.
*
* @var int
*/
protected $endOffset;
/** /**
* Suggestions. * Suggestions.
* *
...@@ -77,15 +63,11 @@ class Term implements \IteratorAggregate, \Countable ...@@ -77,15 +63,11 @@ class Term implements \IteratorAggregate, \Countable
* Constructor. * Constructor.
* *
* @param int $numFound * @param int $numFound
* @param int $startOffset
* @param int $endOffset
* @param array $suggestions * @param array $suggestions
*/ */
public function __construct($numFound, $startOffset, $endOffset, $suggestions) public function __construct($numFound, $suggestions)
{ {
$this->numFound = $numFound; $this->numFound = $numFound;
$this->startOffset = $startOffset;
$this->endOffset = $endOffset;
$this->suggestions = $suggestions; $this->suggestions = $suggestions;
} }
...@@ -99,26 +81,6 @@ class Term implements \IteratorAggregate, \Countable ...@@ -99,26 +81,6 @@ class Term implements \IteratorAggregate, \Countable
return $this->numFound; return $this->numFound;
} }
/**
* Get StartOffset.
*
* @return int
*/
public function getStartOffset()
{
return $this->startOffset;
}
/**
* Get EndOffset.
*
* @return int
*/
public function getEndOffset()
{
return $this->endOffset;
}
/** /**
* Get suggestions. * Get suggestions.
* *
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Solarium\Tests\Integration; namespace Solarium\Tests\Integration;
use Solarium\Core\Client\ClientInterface; use Solarium\Core\Client\ClientInterface;
use Solarium\QueryType\Select\Query\Query as SelectQuery;
class TechproductsTest extends \PHPUnit_Framework_TestCase class TechproductsTest extends \PHPUnit_Framework_TestCase
{ {
...@@ -41,7 +42,7 @@ class TechproductsTest extends \PHPUnit_Framework_TestCase ...@@ -41,7 +42,7 @@ class TechproductsTest extends \PHPUnit_Framework_TestCase
public function testSelect() public function testSelect()
{ {
$select = $this->client->createSelect(); $select = $this->client->createSelect();
$select->setSorts(['id' => 'asc']); $select->setSorts(['id' => SelectQuery::SORT_ASC]);
$result = $this->client->select($select); $result = $this->client->select($select);
$this->assertEquals(32, $result->getNumFound()); $this->assertEquals(32, $result->getNumFound());
$this->assertEquals(10, $result->count()); $this->assertEquals(10, $result->count());
...@@ -65,4 +66,50 @@ class TechproductsTest extends \PHPUnit_Framework_TestCase ...@@ -65,4 +66,50 @@ class TechproductsTest extends \PHPUnit_Framework_TestCase
], $ids); ], $ids);
} }
public function testSpellcheck()
{
$spellcheck = $this->client->createSpellcheck();
$spellcheck->setQuery('power cort');
// Some spellcheck dictionaries needs to build first, but not on every request!
$spellcheck->setBuild(true);
$result = $this->client->spellcheck($spellcheck);
$words = [];
foreach ($result as $term => $suggestions) {
$this->assertEquals('cort', $term);
foreach ($suggestions as $suggestion) {
$words[] = $suggestion['word'];
}
}
$this->assertEquals([
'corp',
'cord',
'card',
], $words);
}
public function testSuggester()
{
$suggester = $this->client->createSuggester();
// The techproducts example doesn't provide a default suggester, but 'mySuggester'.
$suggester->setDictionary('mySuggester');
$suggester->setQuery('electronics');
// A suggester dictionary needs to build first, but not on every request!
$suggester->setBuild(true);
$result = $this->client->suggester($suggester);
$phrases = [];
foreach ($result as $dictionary => $terms) {
$this->assertEquals('mySuggester', $dictionary);
foreach ($terms as $term => $suggestions) {
$this->assertEquals('electronics', $term);
foreach ($suggestions as $suggestion) {
$phrases[] = $suggestion['term'];
}
}
}
$this->assertEquals([
'electronics',
'electronics and computer1',
'electronics and stuff2'
], $phrases);
}
} }
<?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.
*/
namespace Solarium\Tests\QueryType\Spellcheck;
use Solarium\QueryType\Spellcheck\Query;
use Solarium\Core\Client\Client;
class QueryTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Query
*/
protected $query;
public function setUp()
{
$this->query = new Query;
}
public function testGetType()
{
$this->assertEquals(Client::QUERY_SPELLCHECK, $this->query->getType());
}
public function testGetResponseParser()
{
$this->assertInstanceOf('Solarium\QueryType\Spellcheck\ResponseParser', $this->query->getResponseParser());
}
public function testGetRequestBuilder()
{
$this->assertInstanceOf('Solarium\QueryType\Spellcheck\RequestBuilder', $this->query->getRequestBuilder());
}
public function testSetAndGetQuery()
{
$value = 'testquery';
$this->query->setQuery($value);
$this->assertEquals(
$value,
$this->query->getQuery()
);
}
public function testSetAndGetDictionary()
{
$value = 'myDictionary';
$this->query->setDictionary($value);
$this->assertEquals(
$value,
$this->query->getDictionary()
);
}
public function testSetAndGetCount()
{
$value = 11;
$this->query->setCount($value);
$this->assertEquals(
$value,
$this->query->getCount()
);
}
public function testSetAndGetOnlyMorePopular()
{
$value = false;
$this->query->setOnlyMorePopular($value);
$this->assertEquals(
$value,
$this->query->getOnlyMorePopular()
);
}
public function testSetAndGetCollate()
{
$value = false;
$this->query->setCollate($value);
$this->assertEquals(
$value,
$this->query->getCollate()
);
}
}
<?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.
*/
namespace Solarium\Tests\QueryType\Spellcheck;
use Solarium\QueryType\Spellcheck\Query;
use Solarium\QueryType\Spellcheck\RequestBuilder;
use Solarium\Core\Client\Request;
class RequestBuilderTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Query
*/
protected $query;
/**
* @var RequestBuilder
*/
protected $builder;
public function setUp()
{
$this->query = new Query;
$this->builder = new RequestBuilder;
}
public function testBuildParams()
{
$this->query->setCollate(true);
$this->query->setCount(13);
$this->query->setDictionary('suggest');
$this->query->setQuery('ap ip');
$this->query->setOnlyMorePopular(true);
$request = $this->builder->build($this->query);
$this->assertEquals(
array(
'spellcheck' => 'true',
'spellcheck.q' => 'ap ip',
'spellcheck.dictionary' => 'suggest',
'spellcheck.count' => 13,
'spellcheck.onlyMorePopular' => 'true',
'spellcheck.collate' => 'true',
'spellcheck.build' => 'false',
'wt' => 'json',
'json.nl' => 'flat',
'omitHeader' => 'true',
),
$request->getParams()
);
$this->assertEquals(
Request::METHOD_GET,
$request->getMethod()
);
}
}
<?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.
*/
namespace Solarium\Tests\QueryType\Spellcheck;
use Solarium\QueryType\Spellcheck\Query;
use Solarium\QueryType\Spellcheck\ResponseParser;
use Solarium\QueryType\Spellcheck\Result\Term;
class ResponseParserTest extends \PHPUnit_Framework_TestCase
{
public function testParse()
{
$data = array(
'responseHeader' => array(
'status' => 1,
'QTime' => 13,
),
'spellcheck' => array(
'suggestions' => array(
'd',
array(
'numFound' => 2,
'startOffset' => 3,
'endOffset' => 7,
'suggestion' => array(
'disk',
'ddr'
)
),
'vid',
array(
'numFound' => 1,
'startOffset' => 2,
'endOffset' => 5,
'suggestion' => array(
'video',
)
),
'vid',
array(
'numFound' => 1,
'startOffset' => 6,
'endOffset' => 9,
'suggestion' => array(
'video',
)
),
'collation',
'disk video'
),
),
);
$query = new Query();
$resultStub = $this->getMock('Solarium\QueryType\Spellcheck\Result\Result', array(), array(), '', false);
$resultStub->expects($this->any())
->method('getData')
->will($this->returnValue($data));
$resultStub->expects($this->any())
->method('getQuery')
->will($this->returnValue($query));
$parser = new ResponseParser;
$result = $parser->parse($resultStub);
$expected = array(
'd' => new Term(2, 3, 7, array('disk', 'ddr')),
'vid' => new Term(1, 2, 5, array('video'))
);
$allExpected = array(
new Term(2, 3, 7, array('disk', 'ddr')),
new Term(1, 2, 5, array('video')),
new Term(1, 6, 9, array('video')),
);
$this->assertEquals($expected, $result['results']);
$this->assertEquals($allExpected, $result['all']);
$this->assertEquals('disk video', $result['collation']);
}
}
<?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.
*/
namespace Solarium\Tests\QueryType\Spellcheck\Result;
use Solarium\QueryType\Spellcheck\Result\Result;
class ResultTest extends \PHPUnit_Framework_TestCase
{
/**
* @var SpellcheckDummy
*/
protected $result;
/**
* @var array
*/
protected $data;
/**
* @var array
*/
protected $allData;
/**
* @var string
*/
protected $collation;
public function setUp()
{
$this->data = array(
'term1' => 'data1',
'term2' => 'data2',
);
$this->allData = array_values($this->data);
$this->collation = 'collation result';
$this->result = new SpellcheckDummy($this->data, $this->allData, $this->collation);
}
public function testGetStatus()
{
$this->assertEquals(
1,
$this->result->getStatus()
);
}
public function testGetQueryTime()
{
$this->assertEquals(
12,
$this->result->getQueryTime()
);
}
public function testGetResults()
{
$this->assertEquals($this->data, $this->result->getResults());
}
public function testGetAll()
{
$this->assertEquals($this->allData, $this->result->getAll());
}
public function testGetTerm()
{
$this->assertEquals($this->data['term1'], $this->result->getTerm('term1'));
}
public function testGetTermsWithInvalidFieldName()
{
$this->assertEquals(array(), $this->result->getTerm('term3'));
}
public function testCount()
{
$this->assertEquals(count($this->data), count($this->result));
}
public function testIterator()
{
$results = array();
foreach ($this->result as $key => $doc) {
$results[$key] = $doc;
}
$this->assertEquals($this->data, $results);
}
public function testGetCollation()
{
$this->assertEquals($this->collation, $this->result->getCollation());
}
}
class SpellcheckDummy extends Result
{
protected $parsed = true;
public function __construct($results, $all, $collation)
{
$this->results = $results;
$this->all = $all;
$this->collation = $collation;
$this->status = 1;
$this->queryTime = 12;
}
}
<?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.
*/
namespace Solarium\Tests\QueryType\Spellcheck\Result;
use Solarium\QueryType\Spellcheck\Result\Term;
class TermTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Term
*/
protected $result;
/**
* @var int
*/
protected $numFound;
/**
* @var int
*/
protected $startOffset;
/**
* @var int
*/
protected $endOffset;
/**
* @var array
*/
protected $suggestions;
public function setUp()
{
$this->numFound = 5;
$this->startOffset = 2;
$this->endOffset = 6;
$this->suggestions = array(
'suggestion1',
'suggestion2',
);
$this->result = new Term($this->numFound, $this->startOffset, $this->endOffset, $this->suggestions);
}
public function testGetNumFound()
{
$this->assertEquals(
$this->numFound,
$this->result->getNumFound()
);
}
public function testGetStartOffset()
{
$this->assertEquals(
$this->startOffset,
$this->result->getStartOffset()
);
}
public function testGetEndOffset()
{
$this->assertEquals(
$this->endOffset,
$this->result->getEndOffset()
);
}
public function testGetSuggestions()
{
$this->assertEquals(
$this->suggestions,
$this->result->getSuggestions()
);
}
public function testCount()
{
$this->assertEquals(count($this->suggestions), count($this->result));
}
public function testIterator()
{
$results = array();
foreach ($this->result as $key => $doc) {
$results[$key] = $doc;
}
$this->assertEquals($this->suggestions, $results);
}
}
...@@ -33,6 +33,7 @@ namespace Solarium\Tests\QueryType\Suggester; ...@@ -33,6 +33,7 @@ namespace Solarium\Tests\QueryType\Suggester;
use Solarium\QueryType\Suggester\Query; use Solarium\QueryType\Suggester\Query;
use Solarium\QueryType\Suggester\ResponseParser; use Solarium\QueryType\Suggester\ResponseParser;
use Solarium\QueryType\Suggester\Result\Dictionary;
use Solarium\QueryType\Suggester\Result\Term; use Solarium\QueryType\Suggester\Result\Term;
class ResponseParserTest extends \PHPUnit_Framework_TestCase class ResponseParserTest extends \PHPUnit_Framework_TestCase
...@@ -44,38 +45,40 @@ class ResponseParserTest extends \PHPUnit_Framework_TestCase ...@@ -44,38 +45,40 @@ class ResponseParserTest extends \PHPUnit_Framework_TestCase
'status' => 1, 'status' => 1,
'QTime' => 13, 'QTime' => 13,
), ),
'spellcheck' => array( 'suggest' => array(
'suggestions' => array( 'dictionary1' => array(
'd', 'foo' => array(
array(
'numFound' => 2, 'numFound' => 2,
'startOffset' => 3, 'suggestions' => array(
'endOffset' => 7, array(
'suggestion' => array( 'term' => 'foo',
'disk', ),
'ddr' array(
) 'term' => 'foobar',
),
),
), ),
'vid', 'zoo' => array(
array(
'numFound' => 1, 'numFound' => 1,
'startOffset' => 2, 'suggestions' => array(
'endOffset' => 5, array(
'suggestion' => array( 'term' => 'zoo keeper',
'video', ),
) ),
), ),
'vid', ),
array( 'dictionary2' => array(
'numFound' => 1, 'free' => array(
'startOffset' => 6, 'numFound' => 2,
'endOffset' => 9, 'suggestions' => array(
'suggestion' => array( array(
'video', 'term' => 'free beer',
) ),
array(
'term' => 'free software',
),
),
), ),
'collation',
'disk video'
), ),
), ),
); );
...@@ -94,17 +97,21 @@ class ResponseParserTest extends \PHPUnit_Framework_TestCase ...@@ -94,17 +97,21 @@ class ResponseParserTest extends \PHPUnit_Framework_TestCase
$result = $parser->parse($resultStub); $result = $parser->parse($resultStub);
$expected = array( $expected = array(
'd' => new Term(2, 3, 7, array('disk', 'ddr')), 'dictionary1' => new Dictionary([
'vid' => new Term(1, 2, 5, array('video')) 'foo' => new Term(2, [['term' => 'foo'], ['term' => 'foobar']]),
'zoo' => new Term(1, [['term' => 'zoo keeper']]),
]),
'dictionary2' => new Dictionary([
'free' => new Term(2, [['term' => 'free beer'], ['term' => 'free software']]),
]),
); );
$allExpected = array( $allExpected = array(
new Term(2, 3, 7, array('disk', 'ddr')), new Term(2, [['term' => 'foo'], ['term' => 'foobar']]),
new Term(1, 2, 5, array('video')), new Term(1, [['term' => 'zoo keeper']]),
new Term(1, 6, 9, array('video')), new Term(2, [['term' => 'free beer'], ['term' => 'free software']]),
); );
$this->assertEquals($expected, $result['results']); $this->assertEquals($expected, $result['results']);
$this->assertEquals($allExpected, $result['all']); $this->assertEquals($allExpected, $result['all']);
$this->assertEquals('disk video', $result['collation']);
} }
} }
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
namespace Solarium\Tests\QueryType\Suggester\Result; namespace Solarium\Tests\QueryType\Suggester\Result;
use Solarium\QueryType\Suggester\Result\Dictionary;
use Solarium\QueryType\Suggester\Result\Result; use Solarium\QueryType\Suggester\Result\Result;
class ResultTest extends \PHPUnit_Framework_TestCase class ResultTest extends \PHPUnit_Framework_TestCase
...@@ -50,20 +51,19 @@ class ResultTest extends \PHPUnit_Framework_TestCase ...@@ -50,20 +51,19 @@ class ResultTest extends \PHPUnit_Framework_TestCase
*/ */
protected $allData; protected $allData;
/**
* @var string
*/
protected $collation;
public function setUp() public function setUp()
{ {
$this->data = array( $this->data = [
'term1' => 'data1', 'dictionary1' => new Dictionary([
'term2' => 'data2', 'term1' => 'data1',
); 'term2' => 'data2',
$this->allData = array_values($this->data); ]),
$this->collation = 'collation result'; 'dictionary2' => new Dictionary([
$this->result = new SuggesterDummy($this->data, $this->allData, $this->collation); 'term3' => 'data3',
]),
];
$this->allData = ['data1', 'data2', 'data3'];
$this->result = new SuggesterDummy($this->data, $this->allData);
} }
public function testGetStatus() public function testGetStatus()
...@@ -92,14 +92,15 @@ class ResultTest extends \PHPUnit_Framework_TestCase ...@@ -92,14 +92,15 @@ class ResultTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($this->allData, $this->result->getAll()); $this->assertEquals($this->allData, $this->result->getAll());
} }
public function testGetTerm() public function testGetDictionary()
{ {
$this->assertEquals($this->data['term1'], $this->result->getTerm('term1')); $dictionary = $this->result->getDictionary('dictionary1');
$this->assertEquals('data1', $dictionary->getTerm('term1'));
} }
public function testGetTermsWithInvalidFieldName() public function testGetDictionaryWithInvalidFieldName()
{ {
$this->assertEquals(array(), $this->result->getTerm('term3')); $this->assertEquals(null, $this->result->getDictionary('dictionary3'));
} }
public function testCount() public function testCount()
...@@ -117,21 +118,16 @@ class ResultTest extends \PHPUnit_Framework_TestCase ...@@ -117,21 +118,16 @@ class ResultTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($this->data, $results); $this->assertEquals($this->data, $results);
} }
public function testGetCollation()
{
$this->assertEquals($this->collation, $this->result->getCollation());
}
} }
class SuggesterDummy extends Result class SuggesterDummy extends Result
{ {
protected $parsed = true; protected $parsed = true;
public function __construct($results, $all, $collation) public function __construct($results, $all)
{ {
$this->results = $results; $this->results = $results;
$this->all = $all; $this->all = $all;
$this->collation = $collation;
$this->status = 1; $this->status = 1;
$this->queryTime = 12; $this->queryTime = 12;
} }
......
...@@ -45,16 +45,6 @@ class TermTest extends \PHPUnit_Framework_TestCase ...@@ -45,16 +45,6 @@ class TermTest extends \PHPUnit_Framework_TestCase
*/ */
protected $numFound; protected $numFound;
/**
* @var int
*/
protected $startOffset;
/**
* @var int
*/
protected $endOffset;
/** /**
* @var array * @var array
*/ */
...@@ -63,14 +53,12 @@ class TermTest extends \PHPUnit_Framework_TestCase ...@@ -63,14 +53,12 @@ class TermTest extends \PHPUnit_Framework_TestCase
public function setUp() public function setUp()
{ {
$this->numFound = 5; $this->numFound = 5;
$this->startOffset = 2; $this->suggestions = [
$this->endOffset = 6;
$this->suggestions = array(
'suggestion1', 'suggestion1',
'suggestion2', 'suggestion2',
); ];
$this->result = new Term($this->numFound, $this->startOffset, $this->endOffset, $this->suggestions); $this->result = new Term($this->numFound, $this->suggestions);
} }
public function testGetNumFound() public function testGetNumFound()
...@@ -81,22 +69,6 @@ class TermTest extends \PHPUnit_Framework_TestCase ...@@ -81,22 +69,6 @@ class TermTest extends \PHPUnit_Framework_TestCase
); );
} }
public function testGetStartOffset()
{
$this->assertEquals(
$this->startOffset,
$this->result->getStartOffset()
);
}
public function testGetEndOffset()
{
$this->assertEquals(
$this->endOffset,
$this->result->getEndOffset()
);
}
public function testGetSuggestions() public function testGetSuggestions()
{ {
$this->assertEquals( $this->assertEquals(
......
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