Commit 475e2675 authored by Bas de Nooijer's avatar Bas de Nooijer

Merge latest changes in branch 'develop' into feature/nextgen, all changes...

Merge latest changes in branch 'develop' into feature/nextgen, all changes modified to use namespaces
parents 4e71fc88 9e02303e
<?php
require('init.php');
htmlHeader();
// create a client instance
$client = new Solarium\Client\Client($config);
// get a suggester query instance
$query = $client->createSuggester();
$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->suggester($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();
\ No newline at end of file
<?php
require('init.php');
htmlHeader();
// create a client instance and get a select query instance
$client = new Solarium\Client\Client($config);
// first an example manually defining dereferenced params
$query = $client->createSelect();
$helper = $query->getHelper();
$join = $helper->qparser('join', array('from' => 'manu_id', 'to' => 'id'), true);
$queryString = $join . 'id:1';
$query->setQuery($queryString);
$request = $client->createRequest($query);
// output resulting url with dereferenced params
echo urldecode($request->getUri()) . '<hr/>';
// this second example gives the exact same result, using the special join helper
$query = $client->createSelect();
$helper = $query->getHelper();
$join = $helper->join('manu_id', 'id', true);
$queryString = $join . 'id:1';
$query->setQuery($queryString);
$request = $client->createRequest($query);
echo urldecode($request->getUri());
htmlFooter();
\ No newline at end of file
<?php
require('init.php');
htmlHeader();
// create a client instance and autoload the customize request plugin
$client = new Solarium\Client\Client($config);
$parallel = $client->getPlugin('parallelexecution');
// create two queries to execute in an array. Keys are important for fetching the results later!
$queries = array(
'instock' => $client->createSelect()->setQuery('inStock:true'),
'lowprice' => $client->createSelect()->setQuery('price:[1 TO 300]'),
);
// first execute the queries the normal way and time it
$start = microtime(true);
$client->execute($queries['instock']);
$client->execute($queries['lowprice']);
echo 'Execution time for normal "serial" execution of two queries: ' . round(microtime(true)-$start, 3);
echo '<hr/>';
// now execute the two queries parallel and time it
$start = microtime(true);
$results = $parallel->execute($queries);
echo 'Execution time for parallel execution of two queries: ' . round(microtime(true)-$start, 3);
htmlFooter();
// Note: for this example on a default Solr index (with a tiny index) the performance gain is minimal to none.
// With a bigger dataset, more complex queries or multiple solr instances the performance gain is much more.
// For testing you can use a Solr delay component (see https://github.com/basdenooijer/raspberry-solr-plugins) to
// artificially slow Solr down by an exact amount of time.
\ No newline at end of file
......@@ -83,6 +83,8 @@
</ul>
<li><a href="2.5-terms-query.php">2.5 Terms query</a></li>
<li><a href="2.6-suggester-query.php">2.6 Suggester query</a></li>
</ul>
<li>4. Usage modes</li>
......@@ -113,13 +115,15 @@
</ul>
<li><a href="6.2-escaping.php">6.2 Escaping</a></li>
<li><a href="6.3-placeholder-syntax.php">6.3 Placeholder syntax</a></li>
<li><a href="6.4-dereferenced-params.php">6.4 Dereferenced params</a></li>
</ul>
<li>7. Plugins</li>
<ul style="list-style:none;">
<li><a href="7.1-plugin-loadbalancer.php">7.1 Loadbalancer</a></li>
<li><a href="7.2-plugin-postbigrequest.php">7.2 Post Big Requests</a></li>
<li><a href="7.3-plugin-customizerequest.php">7.3 customize Requests</a></li>
<li><a href="7.3-plugin-customizerequest.php">7.3 Customize Requests</a></li>
<li><a href="7.4-plugin-parallelexecution.php">7.4 Parallel Execution</a></li>
</ul>
</ul>
......
......@@ -77,9 +77,7 @@ class Curl extends Adapter
*/
public function execute($request)
{
list($data, $headers) = $this->_getData($request);
$this->check($data, $headers);
return new Client\Response($data, $headers);
return $this->_getData($request);
}
/**
......@@ -89,64 +87,88 @@ class Curl extends Adapter
* @return array
*/
protected function _getData($request)
{
// @codeCoverageIgnoreStart
$handle = $this->createHandle($request);
$httpResponse = curl_exec($handle);
return $this->getResponse($handle, $httpResponse);
// @codeCoverageIgnoreEnd
}
public function getResponse($handle, $httpResponse)
{
// @codeCoverageIgnoreStart
if ($httpResponse !== false) {
$data = $httpResponse;
$info = curl_getinfo($handle);
$headers = array();
$headers[] = 'HTTP/1.1 ' . $info['http_code']. ' OK';
} else {
$headers = array();
$data = '';
}
curl_close($handle);
$this->check($data, $headers);
return new Client\Response($data, $headers);
// @codeCoverageIgnoreEnd
}
/**
* Create curl handle for a request
*
* @param \Solarium\Client\Request $request
* @return resource
*/
public function createHandle($request)
{
// @codeCoverageIgnoreStart
$uri = $this->getBaseUri() . $request->getUri();
$method = $request->getMethod();
$options = $this->_createOptions($request);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $options['timeout']);
$handler = curl_init();
curl_setopt($handler, CURLOPT_URL, $uri);
curl_setopt($handler, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handler, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($handler, CURLOPT_TIMEOUT, $options['timeout']);
if (!isset($options['headers']['Content-Type'])) {
$options['headers']['Content-Type'] = 'text/xml; charset=utf-8';
}
if (!isset($options['headers']['Content-Type'])) {
$options['headers']['Content-Type'] = 'text/xml; charset=utf-8';
}
if (count($options['headers'])) {
$arr = array();
foreach ($options['headers'] as $k => $v) {
$arr[] = $k . ": " . $v;
$headers = array();
foreach ($options['headers'] as $key => $value) {
$headers[] = $key . ": " . $value;
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $arr);
curl_setopt($handler, CURLOPT_HTTPHEADER, $headers);
}
if ($method == Client\Request::METHOD_POST) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request->getRawData());
$httpResponse = curl_exec($ch);
curl_setopt($handler, CURLOPT_POST, true);
curl_setopt($handler, CURLOPT_POSTFIELDS, $request->getRawData());
$httpResponse = curl_exec($handler);
} else if ($method == Client\Request::METHOD_GET) {
curl_setopt($ch, CURLOPT_HTTPGET, true);
$httpResponse = curl_exec($ch);
curl_setopt($handler, CURLOPT_HTTPGET, true);
$httpResponse = curl_exec($handler);
} else if ($method == Client\Request::METHOD_HEAD) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
$httpResponse = curl_exec($ch);
curl_setopt($handler, CURLOPT_CUSTOMREQUEST, 'HEAD');
$httpResponse = curl_exec($handler);
} else {
throw new \Solarium\Exception("unsupported method: $method");
}
$headers = array(); $data = '';
if ($httpResponse !== false) {
$data = $httpResponse;
$info = curl_getinfo($ch);
$headers = array();
$headers[] = 'HTTP/1.1 ' . $info['http_code']. ' OK';
}
return array($data, $headers);
return $handler;
// @codeCoverageIgnoreEnd
}
/**
* Create http request options from request.
*
* @param Solarium\Client\Request $request
* @param \Solarium\Client\Request $request
* @return array
*/
protected function _createOptions($request)
......@@ -168,7 +190,7 @@ class Curl extends Adapter
/**
* Check result of a request
*
* @throws Solarium\Client\HttpException
* @throws \Solarium\Client\HttpException
* @param string $data
* @param array $headers
* @return void
......
......@@ -98,6 +98,11 @@ class Client extends Solarium\Configurable
*/
const QUERYTYPE_TERMS = 'terms';
/**
* Querytype suggester
*/
const QUERYTYPE_SUGGESTER = 'suggester';
/**
* Default options
*
......@@ -148,6 +153,11 @@ class Client extends Solarium\Configurable
'requestbuilder' => 'Solarium\Client\RequestBuilder\Terms',
'responseparser' => 'Solarium\Client\ResponseParser\Terms'
),
self::QUERYTYPE_SUGGESTER => array(
'query' => 'Solarium\Query\Suggester',
'requestbuilder' => 'Solarium\Client\RequestBuilder\Suggester',
'responseparser' => 'Solarium\Client\ResponseParser\Suggester'
),
);
/**
......@@ -159,6 +169,7 @@ class Client extends Solarium\Configurable
'loadbalancer' => 'Solarium\Plugin\Loadbalancer\Loadbalancer',
'postbigrequest' => 'Solarium\Plugin\PostBigRequest',
'customizerequest' => 'Solarium\Plugin\CustomizeRequest\CustomizeRequest',
'parallelexecution' => 'Solarium\Plugin\ParallelExecution',
);
/**
......@@ -223,7 +234,7 @@ class Client extends Solarium\Configurable
* immediately, bypassing the lazy loading.
*
* @param string|Solarium\Client\Adapter $adapter
* @return Solarium\Client Provides fluent interface
* @return \Solarium\Client\Client Provides fluent interface
*/
public function setAdapter($adapter)
{
......@@ -266,7 +277,7 @@ class Client extends Solarium\Configurable
* calling {@see _createAdapter()}
*
* @param boolean $autoload
* @return Solarium\Client\Adapter
* @return Solarium\Client\Adapter\Adapter
*/
public function getAdapter($autoload = true)
{
......@@ -457,7 +468,7 @@ class Client extends Solarium\Configurable
* @param bool $resultOverride
* @return void|mixed
*/
public function triggerEvent($event, $params, $resultOverride = false)
public function triggerEvent($event, $params = array(), $resultOverride = false)
{
// Add namespacing
$event = 'event'.$event;
......@@ -697,6 +708,20 @@ class Client extends Solarium\Configurable
return $this->execute($query);
}
/**
* Execute a suggester 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 Solarium\Query\Suggester $query
* @return Solarium\Result\Suggester
*/
public function suggester($query)
{
return $this->execute($query);
}
/**
* Create a query instance
*
......@@ -799,4 +824,15 @@ class Client extends Solarium\Configurable
{
return $this->createQuery(self::QUERYTYPE_TERMS, $options);
}
/**
* Create a suggester query instance
*
* @param mixed $options
* @return Solarium\Query\Suggester
*/
public function createSuggester($options = null)
{
return $this->createQuery(self::QUERYTYPE_SUGGESTER, $options);
}
}
......@@ -390,4 +390,25 @@ class Request extends \Solarium\Configurable
return $queryString;
}
/**
* Magic method enables a object to be transformed to a string
*
* Get a summary showing significant variables in the object
* note: uri resource is decoded for readability
*
* @return string
*/
public function __toString()
{
$output = __CLASS__ . '::toString' . "\n"
. 'method: ' . $this->getMethod() . "\n"
. 'header: ' . print_r($this->getHeaders(), 1) //don't add newline when using print_r
. 'resource: ' . $this->getUri() . "\n"
. 'resource urldecoded: ' . urldecode($this->getUri()) . "\n"
. 'raw data: ' . $this->getRawData() . "\n";
return $output;
}
}
\ No newline at end of file
......@@ -58,10 +58,7 @@ class Analysis extends \Solarium\Client\RequestBuilder\RequestBuilder
*/
public function build($query)
{
$request = new \Solarium\Client\Request;
$request->setHandler($query->getHandler());
$request->addParam('wt', 'json');
$request = parent::build($query);
$request->addParam('analysis.query', $query->getQuery());
$request->addParam('analysis.showmatch', $query->getShowMatch());
......
......@@ -59,10 +59,8 @@ class Ping extends RequestBuilder
*/
public function build($query)
{
$request = new Client\Request;
$request->setHandler($query->getHandler());
$request = parent::build($query);
$request->setMethod(Client\Request::METHOD_GET);
$request->addParam('wt', 'json');
return $request;
}
......
......@@ -50,6 +50,22 @@ namespace Solarium\Client\RequestBuilder;
abstract class RequestBuilder
{
/**
* Build request for a select query
*
* @param \Solarium\Query\Query $query
* @return \Solarium_Client\Request
*/
public function build($query)
{
$request = new \Solarium\Client\Request;
$request->setHandler($query->getHandler());
$request->addParams($query->getParams());
$request->addParam('wt', 'json');
return $request;
}
/**
* Render a param with localParams
*
......
......@@ -57,7 +57,7 @@ class Debug
* @param Solarium\Client\Request $request
* @return Solarium\Client\Request
*/
public function build($component, $request)
public function buildComponent($component, $request)
{
$request->addParam('debugQuery', 'true');
$request->addParam('debug.explain.structured', 'true');
......
......@@ -57,7 +57,7 @@ class DisMax
* @param Solarium\Client\Request $request
* @return Solarium\Client\Request
*/
public function build($component, $request)
public function buildComponent($component, $request)
{
// enable dismax
$request->addParam('defType', $component->getQueryParser());
......
......@@ -57,7 +57,7 @@ class DistributedSearch
* @param Solarium\Client\Request $request
* @return Solarium\Client\Request
*/
public function build($component, $request)
public function buildComponent($component, $request)
{
// add shard fields to request
$shards = array_values($component->getShards());
......
......@@ -58,7 +58,7 @@ class FacetSet extends \Solarium\Client\RequestBuilder\RequestBuilder
* @param Solarium\Client\Request $request
* @return Solarium\Client\Request
*/
public function build($component, $request)
public function buildComponent($component, $request)
{
$facets = $component->getFacets();
if (count($facets) !== 0) {
......
......@@ -57,7 +57,7 @@ class Grouping
* @param Solarium\Client\Request $request
* @return Solarium\Client\Request
*/
public function build($component, $request)
public function buildComponent($component, $request)
{
// enable grouping
$request->addParam('group', 'true');
......
......@@ -57,7 +57,7 @@ class Highlighting
* @param Solarium\Client\Request $request
* @return Solarium\Client\Request
*/
public function build(
public function buildComponent(
\Solarium\Query\Select\Component\Highlighting\Highlighting $component,
\Solarium\Client\Request $request)
{
......@@ -85,6 +85,8 @@ class Highlighting
$request->addParam('hl.regex.slop', $component->getRegexSlop());
$request->addParam('hl.regex.pattern', $component->getRegexPattern());
$request->addParam('hl.regex.maxAnalyzedChars', $component->getRegexMaxAnalyzedChars());
$request->addParam('hl.q', $component->getQuery());
$request->addParam('hl.phraseLimit', $component->getPhraseLimit());
// set per-field highlighting params
foreach ($component->getFields() as $field) {
......
......@@ -57,7 +57,7 @@ class MoreLikeThis
* @param Solarium\Client\Request $request
* @return Solarium\Client\Request
*/
public function build($component, $request)
public function buildComponent($component, $request)
{
// enable morelikethis
$request->addParam('mlt', 'true');
......
......@@ -57,7 +57,7 @@ class Spellcheck
* @param Solarium\Client\Request $request
* @return Solarium\Client\Request
*/
public function build($component, $request)
public function buildComponent($component, $request)
{
// enable spellcheck
$request->addParam('spellcheck', 'true');
......
......@@ -57,7 +57,7 @@ class Stats
* @param Solarium\Client\Request $request
* @return Solarium\Client\Request
*/
public function build($component, $request)
public function buildComponent($component, $request)
{
// enable stats
$request->addParam('stats', 'true');
......
......@@ -58,15 +58,13 @@ class Select extends \Solarium\Client\RequestBuilder\RequestBuilder
*/
public function build($query)
{
$request = new \Solarium\Client\Request;
$request->setHandler($query->getHandler());
$request = parent::build($query);
// add basic params to request
$request->addParam('q', $query->getQuery());
$request->addParam('start', $query->getStart());
$request->addParam('rows', $query->getRows());
$request->addParam('fl', implode(',', $query->getFields()));
$request->addParam('wt', 'json');
$request->addParam('q.op', $query->getQueryDefaultOperator());
$request->addParam('df', $query->getQueryDefaultField());
......@@ -97,7 +95,7 @@ class Select extends \Solarium\Client\RequestBuilder\RequestBuilder
$componentBuilderClass = $types[$component->getType()]['requestbuilder'];
if (!empty($componentBuilderClass)) {
$componentBuilder = new $componentBuilderClass;
$request = $componentBuilder->build($component, $request);
$request = $componentBuilder->buildComponent($component, $request);
}
}
......
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* @namespace
*/
namespace Solarium\Client\RequestBuilder;
use Solarium\Client;
/**
* Build a Suggester query request
*
* @package Solarium
* @subpackage Client
*/
class Suggester extends RequestBuilder
{
/**
* Build request for a Suggester query
*
* @param Solarium\Query\Suggester $query
* @return Solarium\Client\Request
*/
public function build($query)
{
$request = parent::build($query);
$request->addParam('spellcheck', 'true');
$request->addParam('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());
return $request;
}
}
......@@ -61,10 +61,9 @@ class Terms extends RequestBuilder
*/
public function build($query)
{
$request = new \Solarium\Client\Request;
$request = parent::build($query);
$request->setHandler($query->getHandler());
$request->addParam('terms', true);
$request->addParam('wt', 'json');
$request->addParam('terms.lower', $query->getLowerbound());
$request->addParam('terms.lower.incl', $query->getLowerboundInclude());
$request->addParam('terms.mincount', $query->getMinCount());
......
......@@ -60,10 +60,8 @@ class Update extends RequestBuilder
*/
public function build($query)
{
$request = new Client\Request;
$request->setHandler($query->getHandler());
$request = parent::build($query);
$request->setMethod(Client\Request::METHOD_POST);
$request->addParam('wt', 'json');
$request->setRawData($this->getRawData($query));
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/
*
* @package Solarium
* @subpackage Client
*/
/**
* @namespace
*/
namespace Solarium\Client\ResponseParser;
use Solarium\Client;
/**
* Parse Suggester response data
*
* @package Solarium
* @subpackage Client
*/
class Suggester extends ResponseParser
{
/**
* Get result data for the response
*
* @param Solarium\Result\Terms $result
* @return array
*/
public function parse($result)
{
$data = $result->getData();
$query = $result->getQuery();
$status = null;
$queryTime = null;
if (isset($data['responseHeader'])) {
$status = $data['responseHeader']['status'];
$queryTime = $data['responseHeader']['QTime'];
}
$suggestions = array();
$collation = null;
if (isset($data['spellcheck']['suggestions']) && is_array($data['spellcheck']['suggestions'])) {
$suggestResults = $data['spellcheck']['suggestions'];
$termClass = $query->getOption('termclass');
for ($i = 0; $i < count($suggestResults); $i += 2) {
$term = $suggestResults[$i];
$termData = $suggestResults[$i+1];
if ($term == 'collation'&& $i == count($suggestResults)-2) {
$collation = $termData;
} else {
$suggestions[$term] = new $termClass(
$termData['numFound'],
$termData['startOffset'],
$termData['endOffset'],
$termData['suggestion']
);
}
}
}
return array(
'status' => $status,
'queryTime' => $queryTime,
'results' => $suggestions,
'collation' => $collation,
);
}
}
......@@ -52,7 +52,7 @@ abstract class AbstractPlugin extends \Solarium\Configurable
/**
* Client instance
*
* @var Solarium\Client
* @var \Solarium\Client\Client
*/
protected $_client;
......
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
*/
/**
* @namespace
*/
namespace Solarium\Plugin;
use Solarium\Client;
/**
* ParallelExecution plugin
*
* You can use this plugin to run multiple queries parallel. This functionality depends on the curl adapter so you
* do need to have curl available in your PHP environment.
*
* While query execution is parallel, the results only become available as soon as all requests have finished. So the
* time of the slowest query will be the effective execution time for all queries.
*
* @package Solarium
* @subpackage Plugin
*/
// @codeCoverageIgnoreStart
class ParallelExecution extends AbstractPlugin
{
/**
* Execute queries parallel
*
* Use an array of Solarium_Query objects as input. The keys of the array are important, as they are also used in
* the result array. You can mix all querytypes in the input array.
*
* @param array $queries
* @return array
*/
public function execute($queries)
{
$adapter = $this->_client->setAdapter('Solarium\Client\Adapter\Curl')->getAdapter();
// create handles and add all handles to the multihandle
$multiHandle = curl_multi_init();
$handles = array();
foreach($queries as $key => $query) {
$request = $this->_client->createRequest($query);
$handle = $adapter->createHandle($request);
curl_multi_add_handle($multiHandle, $handle);
$handles[$key] = $handle;
}
// executing multihandle (all requests)
$this->_client->triggerEvent('ParallelExecutionStart');
do {
curl_multi_exec($multiHandle, $running);
} while($running > 0);
$this->_client->triggerEvent('ParallelExecutionEnd');
// get the results
$results = array();
foreach ($handles as $key => $handle) {
try {
curl_multi_remove_handle($multiHandle, $handle);
$response = $adapter->getResponse($handle, curl_multi_getcontent($handle));
$results[$key] = $this->_client->createResult($queries[$key], $response);
} catch(Client\HttpException $e) {
$results[$key] = $e;
}
}
curl_multi_close($multiHandle);
return $results;
}
}
// @codeCoverageIgnoreEnd
\ No newline at end of file
......@@ -66,6 +66,27 @@ class Helper
*/
protected $_assembleParts;
/**
* Counter to keep dereferenced params unique (within a single query instance)
*
* @var int
*/
protected $_derefencedParamsLastKey = 0;
/**
* @var Solarium\Query
*/
protected $_query;
/**
* Constructor
*
* @param Solarium\Query $query
*/
public function __construct($query = null) {
$this->_query = $query;
}
/**
* Escape a term
*
......@@ -115,7 +136,6 @@ class Helper
* Example: rangeQuery('store', '45,-94', '46,-93')
* Returns: store:[45,-94 TO 46,-93]
*
* @static
* @param string $field
* @param string $from
* @param string $to
......@@ -136,7 +156,6 @@ class Helper
*
* Find all entries within the distance of a certain point.
*
* @static
* @param $pointX
* @param $pointY
* @param $field
......@@ -163,7 +182,6 @@ class Helper
* guaranteed to encompass all of the points of interest, but it may also
* include other points that are slightly outside of the required distance.
*
* @static
* @param string $pointX
* @param string $pointY
* @param string $field
......@@ -191,7 +209,6 @@ class Helper
* or combining the distance with the relevancy score,
* such as boosting by the inverse of the distance.
*
* @static
* @param $pointX
* @param $pointY
* @param $field
......@@ -208,15 +225,32 @@ class Helper
/**
* Render a qparser plugin call
*
* @static
* @param string $name
* @param array $params
* @param boolean $dereferenced
* @return string
*/
public function qparser($name, $params = array())
public function qparser($name, $params = array(), $dereferenced = false)
{
if ($dereferenced) {
if(!$this->_query) {
throw new \Solarium\Exception(
'Dereferenced params can only be used in a Solarium_Query_Helper instance retrieved from the query '
. 'by using the getHelper() method, this instance was manually created'
);
}
foreach($params as $paramKey => $paramValue) {
$this->_derefencedParamsLastKey++;
$derefKey = 'deref_' . $this->_derefencedParamsLastKey;
$this->_query->addParam($derefKey, $paramValue);
$params[$paramKey] = '$'.$derefKey;
}
}
$output = '{!'.$name;
foreach ($params AS $key=>$value) {
foreach ($params as $key=>$value) {
$output .= ' ' . $key . '=' . $value;
}
$output .= '}';
......@@ -227,7 +261,6 @@ class Helper
/**
* Render a functionCall
*
* @static
* @param string $name
* @param array $params
* @return string
......@@ -302,4 +335,20 @@ class Helper
return $value;
}
/**
* Render join localparams syntax
*
* @see http://wiki.apache.org/solr/Join
* @since 2.4.0
*
* @param string $from
* @param string $to
* @param boolean $dereferenced
* @return string
*/
public function join($from, $to, $dereferenced = false)
{
return $this->qparser('join', array('from' => $from, 'to' => $to), $dereferenced);
}
}
\ No newline at end of file
......@@ -57,6 +57,13 @@ abstract class Query extends \Solarium\Configurable
*/
protected $_helper;
/**
* Extra query params (e.g. dereferenced params)
*
* @var array
*/
protected $_params = array();
/**
* Get type for this query
*
......@@ -123,10 +130,36 @@ abstract class Query extends \Solarium\Configurable
public function getHelper()
{
if (null === $this->_helper) {
$this->_helper = new Helper;
$this->_helper = new Helper($this);
}
return $this->_helper;
}
/**
* Add extra params to the request
*
* Only intended for internal use, for instance with dereferenced params.
* Therefore the params are limited in functionality. Only add and get
*
* @param string $name
* @param string $value
* @return self Provides fluent interface
*/
public function addParam($name, $value)
{
$this->_params[$name] = $value;
return $this;
}
/**
* Get extra params
*
* @return array
*/
public function getParams()
{
return $this->_params;
}
}
\ No newline at end of file
......@@ -633,4 +633,48 @@ class Highlighting extends \Solarium\Query\Select\Component\Component
return $this->getOption('regexmaxanalyzedchars');
}
/**
* Set highlight query option
*
* Overrides the q parameter for highlighting
*
* @param string $query
* @return Solarium_Query_Select_Component_Highlighting 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 phraselimit option
*
* @param int $maximum
* @return Solarium_Query_Select_Component_Highlighting Provides fluent interface
*/
public function setPhraseLimit($maximum)
{
return $this->_setOption('phraselimit', $maximum);
}
/**
* Get phraselimit option
*
* @return int|null
*/
public function getPhraseLimit()
{
return $this->getOption('phraselimit');
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Query
*/
/**
* @namespace
*/
namespace Solarium\Query;
/**
* Suggester Query
*
* Can be used for an autocomplete feature. See http://wiki.apache.org/solr/Suggester for more info.
*
* @package Solarium
* @subpackage Query
*/
class Suggester extends Query
{
/**
* Get type for this query
*
* @return string
*/
public function getType()
{
return \Solarium\Client\Client::QUERYTYPE_SUGGESTER;
}
/**
* Default options
*
* @var array
*/
protected $_options = array(
'handler' => 'suggest',
'resultclass' => '\Solarium\Result\Suggester\Suggester',
'termclass' => '\Solarium\Result\Suggester\Term',
);
/**
* 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');
}
}
......@@ -42,7 +42,7 @@
namespace Solarium\Query;
/**
* Terns query
* Terms query
*
* A terms query provides access to the indexed terms in a field and the number of documents that match each term.
* This can be useful for doing auto-suggest or other things that operate at the term level instead of the search
......
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* @namespace
*/
namespace Solarium\Result\Suggester;
/**
* Suggester query result
*
* @package Solarium
* @subpackage Result
*/
class Suggester extends \Solarium\Result\QueryType 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;
/**
* 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 results for a specific term
*
* @param string $field
* @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;
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* @namespace
*/
namespace Solarium\Result\Suggester;
/**
* Suggester query term result
*
* @package Solarium
* @subpackage Result
*/
class Term implements \IteratorAggregate, \Countable
{
/**
* @var int
*/
protected $_numFound;
/**
* @var int
*/
protected $_startOffset;
/**
* @var int
*/
protected $_endOffset;
/**
* @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);
}
}
\ No newline at end of file
......@@ -78,8 +78,7 @@ class CurlTest extends \PHPUnit_Framework_TestCase
$response = $mock->execute($request);
$this->assertEquals($body,$response->getBody());
$this->assertEquals($headers,$response->getHeaders());
$this->assertEquals($data, $response);
}
}
\ No newline at end of file
......@@ -42,12 +42,12 @@ class DebugTest extends \PHPUnit_Framework_TestCase
$component = new \Solarium\Query\Select\Component\Debug();
$component->setExplainOther('id:45');
$request = $builder->build($component, $request);
$request = $builder->buildComponent($component, $request);
$this->assertEquals(
array(
'debugQuery' => true,
'debug.explain.structured' => true,
'debugQuery' => 'true',
'debug.explain.structured' => 'true',
'explainOther' => 'id:45',
),
$request->getParams()
......
......@@ -51,7 +51,7 @@ class DisMaxTest extends \PHPUnit_Framework_TestCase
$component->setBoostQuery('cat:1');
$component->setBoostFunctions('functionX(price)');
$request = $builder->build($component, $request);
$request = $builder->buildComponent($component, $request);
$this->assertEquals(
array(
......
......@@ -47,7 +47,7 @@ class DistributedSearchTest extends \PHPUnit_Framework_TestCase
));
$component->setShardRequestHandler('dummy');
$request = $builder->build($component, $request);
$request = $builder->buildComponent($component, $request);
$this->assertEquals(
array(
......
......@@ -59,7 +59,7 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
public function testBuildEmptyFacetSet()
{
$request = $this->_builder->build($this->_component, $this->_request);
$request = $this->_builder->buildComponent($this->_component, $this->_request);
$this->assertEquals(
array(),
......@@ -73,7 +73,7 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$this->_component->addFacet(new \Solarium\Query\Select\Component\Facet\Field(array('key' => 'f1', 'field' => 'owner')));
$this->_component->addFacet(new \Solarium\Query\Select\Component\Facet\Query(array('key' => 'f2', 'query' => 'category:23')));
$this->_component->addFacet(new \Solarium\Query\Select\Component\Facet\MultiQuery(array('key' => 'f3', 'query' => array('f4' => array('query' => 'category:40')))));
$request = $this->_builder->build($this->_component, $this->_request);
$request = $this->_builder->buildComponent($this->_component, $this->_request);
$this->assertEquals(
null,
......@@ -100,7 +100,7 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
)
));
$request = $this->_builder->build($this->_component, $this->_request);
$request = $this->_builder->buildComponent($this->_component, $this->_request);
$this->assertEquals(
null,
......@@ -125,7 +125,7 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
)
));
$request = $this->_builder->build($this->_component, $this->_request);
$request = $this->_builder->buildComponent($this->_component, $this->_request);
$this->assertEquals(
null,
......@@ -145,7 +145,7 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$this->_component->addFacet(new \Solarium\Query\Select\Component\Facet\Field(array('key' => 'f1', 'field' => 'owner')));
$this->_component->addFacet(new \Solarium\Query\Select\Component\Facet\Query(array('key' => 'f2', 'query' => 'category:23')));
$this->_component->addFacet(new \Solarium\Query\Select\Component\Facet\MultiQuery(array('key' => 'f3', 'query' => array('f4' =>array('query' => 'category:40')))));
$request = $this->_builder->build($this->_component, $this->_request);
$request = $this->_builder->buildComponent($this->_component, $this->_request);
$this->assertEquals(
null,
......@@ -162,7 +162,7 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
{
$this->_component->addFacet(new UnknownFacet(array('key' => 'f1', 'field' => 'owner')));
$this->setExpectedException('Solarium\Exception');
$request = $this->_builder->build($this->_component, $this->_request);
$request = $this->_builder->buildComponent($this->_component, $this->_request);
$request->getUri();
}
......
......@@ -50,7 +50,7 @@ class GroupingTest extends \PHPUnit_Framework_TestCase
$component->setCachePercentage(50);
$component->setTruncate(true);
$request = $builder->build($component, $request);
$request = $builder->buildComponent($component, $request);
$this->assertEquals(
array(
......
......@@ -72,8 +72,10 @@ class HighlightingTest extends \PHPUnit_Framework_TestCase
$component->setRegexSlop(1.3);
$component->setRegexPattern('mypattern');
$component->setMaxAnalyzedChars(100);
$component->setQuery('text:myvalue');
$component->setPhraseLimit(40);
$request = $builder->build($component, $request);
$request = $builder->buildComponent($component, $request);
$this->assertEquals(
array(
......@@ -97,6 +99,8 @@ class HighlightingTest extends \PHPUnit_Framework_TestCase
'hl.highlightMultiTerm' => 'true',
'hl.regex.slop' => 1.3,
'hl.regex.pattern' => 'mypattern',
'hl.q' => 'text:myvalue',
'hl.phraseLimit' => 40,
'f.fieldB.hl.snippets' => 3,
'f.fieldB.hl.fragsize' => 25,
'f.fieldB.hl.mergeContiguous' => 'true',
......
......@@ -51,7 +51,7 @@ class MoreLikeThisTest extends \PHPUnit_Framework_TestCase
$component->setQueryFields('description');
$component->setCount(6);
$request = $builder->build($component, $request);
$request = $builder->buildComponent($component, $request);
$this->assertEquals(
array(
......
......@@ -54,7 +54,7 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
$component->setCollateExtendedResults(true);
$component->setAccuracy(.2);
$request = $builder->build($component, $request);
$request = $builder->buildComponent($component, $request);
$this->assertEquals(
array(
......
......@@ -44,7 +44,7 @@ class StatsTest extends \PHPUnit_Framework_TestCase
$component->createField('fieldB');
$component->addFacets(array('facetA', 'facetB'));
$request = $builder->build($component, $request);
$request = $builder->buildComponent($component, $request);
$this->assertEquals(
array(
......
......@@ -69,7 +69,7 @@ class SelectTest extends \PHPUnit_Framework_TestCase
);
$this->assertEquals(
'select?q=*:*&start=0&rows=10&fl=*,score&wt=json',
'select?wt=json&q=*:*&start=0&rows=10&fl=*,score',
urldecode($request->getUri())
);
}
......@@ -86,7 +86,7 @@ class SelectTest extends \PHPUnit_Framework_TestCase
);
$this->assertEquals(
'select?q=*:*&start=0&rows=10&fl=*,score&wt=json&sort=id asc,name desc',
'select?wt=json&q=*:*&start=0&rows=10&fl=*,score&sort=id asc,name desc',
urldecode($request->getUri())
);
}
......@@ -103,7 +103,7 @@ class SelectTest extends \PHPUnit_Framework_TestCase
);
$this->assertEquals(
'select?q=*:*&start=0&rows=10&fl=*,score&wt=json&q.op=AND&df=mydefault',
'select?wt=json&q=*:*&start=0&rows=10&fl=*,score&q.op=AND&df=mydefault',
urldecode($request->getUri())
);
}
......@@ -122,7 +122,7 @@ class SelectTest extends \PHPUnit_Framework_TestCase
);
$this->assertEquals(
'select?q=*:*&start=0&rows=10&fl=*,score&wt=json&sort=id asc,name desc&fq=published:true&fq={!tag=t1,t2}category:23',
'select?wt=json&q=*:*&start=0&rows=10&fl=*,score&sort=id asc,name desc&fq=published:true&fq={!tag=t1,t2}category:23',
urldecode($request->getUri())
);
}
......
<?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\Client\RequestBuilder;
class SuggesterTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Solarium\Query\Suggester
*/
protected $_query;
/**
* @var \Solarium\Client\RequestBuilder\Suggester
*/
protected $_builder;
public function setUp()
{
$this->_query = new \Solarium\Query\Suggester;
$this->_builder = new \Solarium\Client\RequestBuilder\Suggester;
}
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',
'q' => 'ap ip',
'spellcheck.dictionary' => 'suggest',
'spellcheck.count' => 13,
'spellcheck.onlyMorePopular' => 'true',
'spellcheck.collate' => 'true',
'wt' => 'json',
),
$request->getParams()
);
$this->assertEquals(
\Solarium\Client\Request::METHOD_GET,
$request->getMethod()
);
}
}
\ No newline at end of file
......@@ -33,7 +33,9 @@ namespace Solarium\Tests\Client;
class RequestBuilderTest extends \PHPUnit_Framework_TestCase
{
/**
* @var TestRequestBuilder
*/
protected $_builder;
public function setup()
......@@ -41,6 +43,19 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
$this->_builder = new TestRequestBuilder;
}
public function testBuild()
{
$query = new \Solarium\Query\Select\Select;
$query->addParam('p1','v1');
$query->addParam('p2','v2');
$request = $this->_builder->build($query);
$this->assertEquals(
'select?p1=v1&p2=v2&wt=json',
urldecode($request->getUri())
);
}
public function testRenderLocalParams()
{
$myParams = array('tag' => 'mytag', 'ex' => array('exclude1','exclude2'));
......
......@@ -441,4 +441,37 @@ class RequestTest extends \PHPUnit_Framework_TestCase
);
}
public function testToString()
{
$options = array(
'method' => \Solarium\Client\Request::METHOD_POST,
'handler' => '/myHandler',
'param' => array(
'param1' => 1,
'param2' => 'test content',
),
'rawdata' => 'post data',
'header' => array(
'myHeader1' => 'X-myHeader1: value1',
'myHeader2' => 'X-myHeader2: value2',
),
);
$this->_request->setOptions($options);
$this->assertEquals(
'Solarium\Client\Request::toString
method: POST
header: Array
(
[0] => X-myHeader1: value1
[1] => X-myHeader2: value2
)
resource: /myHandler?param1=1&param2=test+content
resource urldecoded: /myHandler?param1=1&param2=test content
raw data: post data
',
(string)$this->_request
);
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\Client\ResponseParser;
class SuggesterTest 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',
)
),
'collation',
'disk video'
),
),
);
$query = new \Solarium\Query\Suggester();
$resultStub = $this->getMock('\Solarium\Result\Suggester\Suggester', 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 \Solarium\Client\ResponseParser\Suggester;
$result = $parser->parse($resultStub);
$expected = array(
'd' => new \Solarium\Result\Suggester\Term(2,3,7,array('disk','ddr')),
'vid' => new \Solarium\Result\Suggester\Term(1,2,5,array('video'))
);
$this->assertEquals($expected, $result['results']);
$this->assertEquals('disk video', $result['collation']);
}
}
......@@ -658,6 +658,18 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$observer->terms($query);
}
public function testSuggester()
{
$query = new \Solarium\Query\Suggester();
$observer = $this->getMock('Solarium\Client\Client', array('execute'));
$observer->expects($this->once())
->method('execute')
->with($this->equalTo($query));
$observer->suggester($query);
}
public function testCreateQuery()
{
$options = array('optionA' => 1, 'optionB' => 2);
......@@ -814,6 +826,18 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$observer->createTerms($options);
}
public function testCreateSuggester()
{
$options = array('optionA' => 1, 'optionB' => 2);
$observer = $this->getMock('Solarium\Client\Client', array('createQuery'));
$observer->expects($this->once())
->method('createQuery')
->with($this->equalTo(\Solarium\Client\Client::QUERYTYPE_SUGGESTER), $this->equalTo($options));
$observer->createSuggester($options);
}
public function testTriggerEvent()
{
$eventName = 'Test';
......
......@@ -33,11 +33,12 @@ namespace Solarium\Tests\Query;
class HelperTest extends \PHPUnit_Framework_TestCase
{
protected $_helper;
protected $_helper, $_query;
public function setUp()
{
$this->_helper = new \Solarium\Query\Helper;
$this->_query = new \Solarium\Query\Select\Select;
$this->_helper = new \Solarium\Query\Helper($this->_query);
}
public function testRangeQueryInclusive()
......@@ -106,6 +107,38 @@ class HelperTest extends \PHPUnit_Framework_TestCase
);
}
public function testQparserDereferencedNoQuery()
{
$helper = new \Solarium\Query\Helper();
$this->setExpectedException('Solarium\Exception');
$helper->qparser('join', array('from' => 'manu_id', 'to' => 'id'), true);
}
public function testQparserDereferenced()
{
$this->assertEquals(
'{!join from=$deref_1 to=$deref_2}',
$this->_helper->qparser('join', array('from' => 'manu_id', 'to' => 'id'), true)
);
$this->assertEquals(
array('deref_1' => 'manu_id', 'deref_2' => 'id'),
$this->_query->getParams()
);
// second call, params should have updated counts
$this->assertEquals(
'{!join from=$deref_3 to=$deref_4}',
$this->_helper->qparser('join', array('from' => 'cat_id', 'to' => 'prod_id'), true)
);
// previous params should also still be there
$this->assertEquals(
array('deref_1' => 'manu_id', 'deref_2' => 'id', 'deref_3' => 'cat_id', 'deref_4' => 'prod_id'),
$this->_query->getParams()
);
}
public function testFunctionCallNoParams()
{
$this->assertEquals(
......@@ -199,4 +232,25 @@ class HelperTest extends \PHPUnit_Framework_TestCase
$this->_helper->assemble('cat:%1% AND content:%2%',array('value1'));
}
public function testJoin()
{
$this->assertEquals(
'{!join from=manu_id to=id}',
$this->_helper->join('manu_id', 'id')
);
}
public function testJoinDereferenced()
{
$this->assertEquals(
'{!join from=$deref_1 to=$deref_2}',
$this->_helper->join('manu_id', 'id', true)
);
$this->assertEquals(
array('deref_1' => 'manu_id', 'deref_2' => 'id'),
$this->_query->getParams()
);
}
}
......@@ -73,6 +73,8 @@ class HighlightingTest extends \PHPUnit_Framework_TestCase
'regexslop' => .8,
'regexpattern' => 'myPattern',
'regexmaxanalyzedchars' => 500,
'query' => 'text:myvalue',
'phraselimit' => 35,
);
......@@ -100,6 +102,8 @@ class HighlightingTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($options['regexslop'], $this->_hlt->getRegexSlop());
$this->assertEquals($options['regexpattern'], $this->_hlt->getRegexPattern());
$this->assertEquals($options['regexmaxanalyzedchars'], $this->_hlt->getRegexMaxAnalyzedChars());
$this->assertEquals($options['query'], $this->_hlt->getQuery());
$this->assertEquals($options['phraselimit'], $this->_hlt->getPhraseLimit());
}
public function testGetType()
......@@ -449,4 +453,26 @@ class HighlightingTest extends \PHPUnit_Framework_TestCase
);
}
public function testSetAndGetQuery()
{
$value = 'text:myvalue';
$this->_hlt->setQuery($value);
$this->assertEquals(
$value,
$this->_hlt->getQuery()
);
}
public function testSetAndGetPhraseLimit()
{
$value = 20;
$this->_hlt->setPhraseLimit($value);
$this->assertEquals(
$value,
$this->_hlt->getPhraseLimit()
);
}
}
<?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\Query;
class SuggesterTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Solarium\Query\Suggester
*/
protected $_query;
public function setUp()
{
$this->_query = new \Solarium\Query\Suggester;
}
public function testGetType()
{
$this->assertEquals(\Solarium\Client\Client::QUERYTYPE_SUGGESTER, $this->_query->getType());
}
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()
);
}
}
\ No newline at end of file
......@@ -59,6 +59,19 @@ class QueryTest extends \PHPUnit_Framework_TestCase
);
}
public function testAddAndGetParams()
{
$query = new TestQuery;
$query->addParam('p1','v1');
$query->addParam('p2','v2');
$query->addParam('p2','v3'); //should overwrite previous value
$this->assertEquals(
array('p1' => 'v1', 'p2' => 'v3'),
$query->getParams()
);
}
}
class TestQuery extends \Solarium\Query\Query
......
<?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\Result\Suggester;
class TermTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Solarium\Result\Suggester\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 \Solarium\Result\Suggester\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);
}
}
\ 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.
*/
namespace Solarium\Tests\Result;
class SuggesterTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Solarium\Result\Suggester
*/
protected $_result;
/**
* @var array
*/
protected $_data;
/**
* @var string
*/
protected $_collation;
public function setUp()
{
$this->_data = array(
'term1' => 'data1',
'term2' => 'data2',
);
$this->_collation = 'collation result';
$this->_result = new SuggesterDummy($this->_data, $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 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 SuggesterDummy extends \Solarium\Result\Suggester\Suggester
{
protected $_parsed = true;
public function __construct($results, $collation)
{
$this->_results = $results;
$this->_collation = $collation;
$this->_status = 1;
$this->_queryTime = 12;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment