Commit 0acdb283 authored by Bas de Nooijer's avatar Bas de Nooijer Committed by GitHub

Merge pull request #456 from solariumphp/develop

Creating new release
parents 91fe4085 e800d950
# CHANGELOG # CHANGELOG
## 3.7.0 - 2016-10-28
- added: support for nested documents in update query
- added: spatial component for select query
- added: support for keys and excludes in interval facet
- added: support for grouping using a function (group.func)
- bugfix: spellcheck collation parsing for Solr 5+
- improvement: lots of fixes in documentation markup
- added: included suggestion in composer file for a query builder library
## 3.6.0 - 2016-05-03 ## 3.6.0 - 2016-05-03
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
"zendframework/zendframework1": "~1.12", "zendframework/zendframework1": "~1.12",
"satooshi/php-coveralls": "~1.0" "satooshi/php-coveralls": "~1.0"
}, },
"suggest": {
"minimalcode/search": "Query builder compatible with Solarium, allows simplified solr-query handling"
},
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-develop": "3.3.x-dev" "dev-develop": "3.3.x-dev"
......
...@@ -97,7 +97,8 @@ By combining these options you can achieve almost any type of customization with ...@@ -97,7 +97,8 @@ By combining these options you can achieve almost any type of customization with
Solarium uses a separate library (included using Composer) for events. For more info on the Event Dispatcher take a look at [http://symfony.com/doc/2.0/components/event\_dispatcher/introduction.html the docs](http://symfony.com/doc/2.0/components/event_dispatcher/introduction.html_the_docs) Solarium uses a separate library (included using Composer) for events. For more info on the Event Dispatcher take a look at [http://symfony.com/doc/2.0/components/event\_dispatcher/introduction.html the docs](http://symfony.com/doc/2.0/components/event_dispatcher/introduction.html_the_docs)
This example shows all available events and how to use the events to create a very basic debugger: ```php This example shows all available events and how to use the events to create a very basic debugger:
```php
<?php <?php
require(__DIR__.'/init.php'); require(__DIR__.'/init.php');
use Solarium\Core\Event\Events; use Solarium\Core\Event\Events;
...@@ -230,7 +231,8 @@ htmlFooter(); ...@@ -230,7 +231,8 @@ htmlFooter();
``` ```
The second example shows how to replace the built-in select querytype with a custom implementation: ```php The second example shows how to replace the built-in select querytype with a custom implementation:
```php
<?php <?php
require(__DIR__.'/init.php'); require(__DIR__.'/init.php');
use Solarium\Client; use Solarium\Client;
......
...@@ -28,7 +28,7 @@ See [<https://packagist.org>](https://packagist.org) for other packages. ...@@ -28,7 +28,7 @@ See [<https://packagist.org>](https://packagist.org) for other packages.
```json ```json
{ {
"require": { "require": {
"solarium/solarium": "2.4.0" "solarium/solarium": "3.6.0"
} }
} }
``` ```
......
...@@ -24,7 +24,9 @@ Options ...@@ -24,7 +24,9 @@ Options
Examples Examples
-------- --------
Grouping by field: ```php Grouping by field:
```php
<?php <?php
require(__DIR__.'/init.php'); require(__DIR__.'/init.php');
...@@ -82,7 +84,9 @@ htmlFooter(); ...@@ -82,7 +84,9 @@ htmlFooter();
``` ```
Grouping by query: ```php Grouping by query:
```php
<?php <?php
require(__DIR__.'/init.php'); require(__DIR__.'/init.php');
......
...@@ -72,7 +72,7 @@ class Client extends CoreClient ...@@ -72,7 +72,7 @@ class Client extends CoreClient
* *
* @var string * @var string
*/ */
const VERSION = '3.6.0'; const VERSION = '3.7.0';
/** /**
* Check for an exact version. * Check for an exact version.
......
...@@ -180,7 +180,7 @@ abstract class AbstractFacet extends Configurable ...@@ -180,7 +180,7 @@ abstract class AbstractFacet extends Configurable
break; break;
case 'exclude': case 'exclude':
if (!is_array($value)) { if (!is_array($value)) {
$value = array($value); $value = explode(',', $value);
} }
$this->setExcludes($value); $this->setExcludes($value);
unset($this->options['exclude']); unset($this->options['exclude']);
......
<?php
namespace Solarium\QueryType\Select\Query\Component;
use Solarium\QueryType\Select\Query\Query as SelectQuery;
use Solarium\QueryType\Select\RequestBuilder\Component\Spatial as RequestBuilder;
/**
* Spatial component.
*
* @link https://cwiki.apache.org/confluence/display/solr/Spatial+Search
*/
class Spatial extends AbstractComponent
{
/**
* Get component type.
*
* @return string
*/
public function getType()
{
return SelectQuery::COMPONENT_SPATIAL;
}
/**
* Get a requestbuilder for this query.
*
* @return RequestBuilder
*/
public function getRequestBuilder()
{
return new RequestBuilder();
}
/**
* This component has no response parser...
*/
public function getResponseParser()
{
return;
}
/**
* @param string $sfield
*/
public function setField($sfield)
{
$this->setOption('sfield', $sfield);
}
/**
* @param int $distance
*/
public function setDistance($distance)
{
$this->setOption('d', $distance);
}
/**
* @param string $point
*/
public function setPoint($point)
{
$this->setOption('pt', $point);
}
/**
* Get sfield option.
*
* @return string|null
*/
public function getField()
{
return $this->getOption('sfield');
}
/**
* Get d option.
*
* @return int|null
*/
public function getDistance()
{
return $this->getOption('d');
}
/**
* Get pt option.
*
* @return int|null
*/
public function getPoint()
{
return $this->getOption('pt');
}
}
...@@ -127,6 +127,11 @@ class Query extends BaseQuery ...@@ -127,6 +127,11 @@ class Query extends BaseQuery
*/ */
const COMPONENT_DEBUG = 'debug'; const COMPONENT_DEBUG = 'debug';
/**
* Query component spatial.
*/
const COMPONENT_SPATIAL = 'spatial';
/** /**
* Default options. * Default options.
* *
...@@ -166,6 +171,7 @@ class Query extends BaseQuery ...@@ -166,6 +171,7 @@ class Query extends BaseQuery
self::COMPONENT_DISTRIBUTEDSEARCH => 'Solarium\QueryType\Select\Query\Component\DistributedSearch', self::COMPONENT_DISTRIBUTEDSEARCH => 'Solarium\QueryType\Select\Query\Component\DistributedSearch',
self::COMPONENT_STATS => 'Solarium\QueryType\Select\Query\Component\Stats\Stats', self::COMPONENT_STATS => 'Solarium\QueryType\Select\Query\Component\Stats\Stats',
self::COMPONENT_DEBUG => 'Solarium\QueryType\Select\Query\Component\Debug', self::COMPONENT_DEBUG => 'Solarium\QueryType\Select\Query\Component\Debug',
self::COMPONENT_SPATIAL => 'Solarium\QueryType\Select\Query\Component\Spatial',
); );
/** /**
...@@ -1057,6 +1063,18 @@ class Query extends BaseQuery ...@@ -1057,6 +1063,18 @@ class Query extends BaseQuery
return $this->addTags($tags); return $this->addTags($tags);
} }
/**
* Get a Spatial component instance.
*
* This is a convenience method that maps presets to getComponent
*
* @return \Solarium\QueryType\Select\Query\Component\Spatial
*/
public function getSpatial()
{
return $this->getComponent(self::COMPONENT_SPATIAL, true);
}
/** /**
* Initialize options. * Initialize options.
* *
...@@ -1090,7 +1108,7 @@ class Query extends BaseQuery ...@@ -1090,7 +1108,7 @@ class Query extends BaseQuery
break; break;
case 'tag': case 'tag':
if (!is_array($value)) { if (!is_array($value)) {
$value = array($value); $value = explode(',', $value);
} }
$this->addTags($value); $this->addTags($value);
break; break;
......
...@@ -246,9 +246,8 @@ class FacetSet extends RequestBuilder implements ComponentRequestBuilderInterfac ...@@ -246,9 +246,8 @@ class FacetSet extends RequestBuilder implements ComponentRequestBuilderInterfac
$request->addParam( $request->addParam(
'facet.interval', 'facet.interval',
$this->renderLocalParams( $this->renderLocalParams(
$field $field,
// key & ex not supported for interval array('key' => $facet->getKey(), 'ex' => $facet->getExcludes())
//,array('key' => $facet->getKey(), 'ex' => $facet->getExcludes())
) )
); );
......
<?php
namespace Solarium\QueryType\Select\RequestBuilder\Component;
use Solarium\QueryType\Select\Query\Component\Spatial as SpatialComponent;
use Solarium\Core\Client\Request;
/**
* Add select component spatial to the request.
*/
class Spatial implements ComponentRequestBuilderInterface
{
/**
* Add request settings for Spatial.
*
* @param SpatialComponent $component
* @param Request $request
*
* @return Request
*/
public function buildComponent($component, $request)
{
$request->addParam('sfield', $component->getField());
$request->addParam('pt', $component->getPoint());
$request->addParam('d', $component->getDistance());
return $request;
}
}
...@@ -67,7 +67,9 @@ class Grouping implements ComponentParserInterface ...@@ -67,7 +67,9 @@ class Grouping implements ComponentParserInterface
// parse field groups // parse field groups
$valueResultClass = $grouping->getOption('resultvaluegroupclass'); $valueResultClass = $grouping->getOption('resultvaluegroupclass');
$documentClass = $query->getOption('documentclass'); $documentClass = $query->getOption('documentclass');
foreach ($grouping->getFields() as $field) {
// check grouping fields as well as the grouping function (either can be used in the query)
foreach (array_merge($grouping->getFields(), array($grouping->getFunction())) as $field) {
if (isset($data['grouped'][$field])) { if (isset($data['grouped'][$field])) {
$result = $data['grouped'][$field]; $result = $data['grouped'][$field];
......
...@@ -141,12 +141,20 @@ class Spellcheck extends ResponseParserAbstract implements ComponentParserInterf ...@@ -141,12 +141,20 @@ class Spellcheck extends ResponseParserAbstract implements ComponentParserInterf
if ($queryObject->getResponseWriter() == $queryObject::WT_JSON) { if ($queryObject->getResponseWriter() == $queryObject::WT_JSON) {
if (is_array(current($values))) { if (is_array(current($values))) {
foreach ($values as $key => $value) { foreach ($values as $key => $value) {
if (array_key_exists('collationQuery', $value)) {
$values[$key] = $value;
} else {
$values[$key] = $this->convertToKeyValueArray($value); $values[$key] = $this->convertToKeyValueArray($value);
} }
}
} else {
if (array_key_exists('collationQuery', $values)) {
$values = array($values);
} else { } else {
$values = array($this->convertToKeyValueArray($values)); $values = array($this->convertToKeyValueArray($values));
} }
} }
}
foreach ($values as $collationValue) { foreach ($values as $collationValue) {
$query = null; $query = null;
......
...@@ -131,13 +131,7 @@ class RequestBuilder extends BaseRequestBuilder ...@@ -131,13 +131,7 @@ class RequestBuilder extends BaseRequestBuilder
foreach ($doc->getFields() as $name => $value) { foreach ($doc->getFields() as $name => $value) {
$boost = $doc->getFieldBoost($name); $boost = $doc->getFieldBoost($name);
$modifier = $doc->getFieldModifier($name); $modifier = $doc->getFieldModifier($name);
if (is_array($value)) { $xml .= $this->buildFieldsXml($name, $boost, $value, $modifier, $query);
foreach ($value as $multival) {
$xml .= $this->buildFieldXml($name, $boost, $multival, $modifier, $query);
}
} else {
$xml .= $this->buildFieldXml($name, $boost, $value, $modifier, $query);
}
} }
$version = $doc->getVersion(); $version = $doc->getVersion();
...@@ -164,10 +158,10 @@ class RequestBuilder extends BaseRequestBuilder ...@@ -164,10 +158,10 @@ class RequestBuilder extends BaseRequestBuilder
{ {
$xml = '<delete>'; $xml = '<delete>';
foreach ($command->getIds() as $id) { foreach ($command->getIds() as $id) {
$xml .= '<id>'.htmlspecialchars($id, ENT_NOQUOTES, 'UTF-8').'</id>'; $xml .= '<id>' . htmlspecialchars($id, ENT_NOQUOTES, 'UTF-8') . '</id>';
} }
foreach ($command->getQueries() as $query) { foreach ($command->getQueries() as $query) {
$xml .= '<query>'.htmlspecialchars($query, ENT_NOQUOTES, 'UTF-8').'</query>'; $xml .= '<query>' . htmlspecialchars($query, ENT_NOQUOTES, 'UTF-8') . '</query>';
} }
$xml .= '</delete>'; $xml .= '</delete>';
...@@ -239,7 +233,7 @@ class RequestBuilder extends BaseRequestBuilder ...@@ -239,7 +233,7 @@ class RequestBuilder extends BaseRequestBuilder
$value = $query->getHelper()->formatDate($value); $value = $query->getHelper()->formatDate($value);
} }
$xml = '<field name="'.$name.'"'; $xml = '<field name="' . $name . '"';
$xml .= $this->attrib('boost', $boost); $xml .= $this->attrib('boost', $boost);
$xml .= $this->attrib('update', $modifier); $xml .= $this->attrib('update', $modifier);
if ($value === null) { if ($value === null) {
...@@ -250,9 +244,42 @@ class RequestBuilder extends BaseRequestBuilder ...@@ -250,9 +244,42 @@ class RequestBuilder extends BaseRequestBuilder
$value = 'true'; $value = 'true';
} }
$xml .= '>'.htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8'); $xml .= '>' . htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8');
$xml .= '</field>'; $xml .= '</field>';
return $xml; return $xml;
} }
/**
* @param string $key
*
* @param float $boost
* @param mixed $value
* @param string $modifier
* @param UpdateQuery $query
* @return string
*/
private function buildFieldsXml($key, $boost, $value, $modifier, $query)
{
$xml = '';
if (is_array($value)) {
foreach ($value as $multival) {
if (is_array($multival)) {
$xml .= '<doc>';
foreach ($multival as $k => $v) {
$xml .= $this->buildFieldsXml($k, $boost, $v, $modifier, $query);
}
$xml .= '</doc>';
} else {
$xml .= $this->buildFieldXml($key, $boost, $multival, $modifier, $query);
}
}
} else {
$xml .= $this->buildFieldXml($key, $boost, $value, $modifier, $query);
}
return $xml;
}
} }
...@@ -708,4 +708,14 @@ abstract class AbstractQueryTest extends \PHPUnit_Framework_TestCase ...@@ -708,4 +708,14 @@ abstract class AbstractQueryTest extends \PHPUnit_Framework_TestCase
$this->query->setTags(array('t3', 't4')); $this->query->setTags(array('t3', 't4'));
$this->assertEquals(array('t3', 't4'), $this->query->getTags()); $this->assertEquals(array('t3', 't4'), $this->query->getTags());
} }
public function testGetSpatial()
{
$spatial = $this->query->getSpatial();
$this->assertEquals(
'Solarium\QueryType\Select\Query\Component\Spatial',
get_class($spatial)
);
}
} }
<?php
namespace Solarium\Tests\QueryType\Select\Query\Component;
use Solarium\QueryType\Select\Query\Component\Spatial;
use Solarium\QueryType\Select\Query\Query;
class SpatialTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Spatial
*/
protected $spatial;
public function setUp()
{
$this->spatial = new Spatial;
}
public function testConfigMode()
{
$options = array(
'sfield' => 'geo',
'd' => 50,
'pt' => '48.2233,16.3161',
);
$this->spatial->setOptions($options);
$this->assertEquals($options['sfield'], $this->spatial->getField());
$this->assertEquals($options['d'], $this->spatial->getDistance());
$this->assertEquals($options['pt'], $this->spatial->getPoint());
}
public function testGetType()
{
$this->assertEquals(
Query::COMPONENT_SPATIAL,
$this->spatial->getType()
);
}
public function testGetResponseParser()
{
$this->assertEquals(null, $this->spatial->getResponseParser());
}
public function testGetRequestBuilder()
{
$this->assertInstanceOf(
'Solarium\QueryType\Select\RequestBuilder\Component\Spatial',
$this->spatial->getRequestBuilder()
);
}
public function testSetAndGetField()
{
$value = 'geo';
$this->spatial->setField($value);
$this->assertEquals(
$value,
$this->spatial->getField()
);
}
public function testSetAndGetDistance()
{
$value = 'distance';
$this->spatial->setDistance($value);
$this->assertEquals(
$value,
$this->spatial->getDistance()
);
}
public function testSetAndGetPoint()
{
$value = '52,13';
$this->spatial->setPoint($value);
$this->assertEquals(
$value,
$this->spatial->getPoint()
);
}
}
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
...@@ -69,7 +69,7 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase ...@@ -69,7 +69,7 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
{ {
$request = $this->builder->buildComponent($this->component, $this->request); $request = $this->builder->buildComponent($this->component, $this->request);
$this->assertEquals( static::assertEquals(
array(), array(),
$request->getParams() $request->getParams()
); );
...@@ -86,12 +86,12 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase ...@@ -86,12 +86,12 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$request = $this->builder->buildComponent($this->component, $this->request); $request = $this->builder->buildComponent($this->component, $this->request);
$this->assertEquals( static::assertEquals(
null, null,
$request->getRawData() $request->getRawData()
); );
$this->assertEquals( static::assertEquals(
'?facet=true&facet.field={!key=f1}owner&facet.query={!key=f2}category:23&facet.query={!key=f4}category:40', '?facet=true&facet.field={!key=f1}owner&facet.query={!key=f2}category:23&facet.query={!key=f4}category:40',
urldecode($request->getUri()) urldecode($request->getUri())
); );
...@@ -114,12 +114,12 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase ...@@ -114,12 +114,12 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$request = $this->builder->buildComponent($this->component, $this->request); $request = $this->builder->buildComponent($this->component, $this->request);
$this->assertEquals( static::assertEquals(
null, null,
$request->getRawData() $request->getRawData()
); );
$this->assertEquals( static::assertEquals(
'?facet=true&facet.range={!key=f1}price&f.price.facet.range.start=1&f.price.facet.range.end=100&f.price.facet.range.gap=10&f.price.facet.mincount=123&f.price.facet.range.other=all&f.price.facet.range.include=outer', '?facet=true&facet.range={!key=f1}price&f.price.facet.range.start=1&f.price.facet.range.end=100&f.price.facet.range.gap=10&f.price.facet.mincount=123&f.price.facet.range.other=all&f.price.facet.range.include=outer',
urldecode($request->getUri()) urldecode($request->getUri())
); );
...@@ -141,12 +141,12 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase ...@@ -141,12 +141,12 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$request = $this->builder->buildComponent($this->component, $this->request); $request = $this->builder->buildComponent($this->component, $this->request);
$this->assertEquals( static::assertEquals(
null, null,
$request->getRawData() $request->getRawData()
); );
$this->assertEquals( static::assertEquals(
'?facet=true&facet.range={!key=f1}price&f.price.facet.range.start=1&f.price.facet.range.end=100'. '?facet=true&facet.range={!key=f1}price&f.price.facet.range.start=1&f.price.facet.range.end=100'.
'&f.price.facet.range.gap=10', '&f.price.facet.range.gap=10',
urldecode($request->getUri()) urldecode($request->getUri())
...@@ -165,12 +165,12 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase ...@@ -165,12 +165,12 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$request = $this->builder->buildComponent($this->component, $this->request); $request = $this->builder->buildComponent($this->component, $this->request);
$this->assertEquals( static::assertEquals(
null, null,
$request->getRawData() $request->getRawData()
); );
$this->assertEquals( static::assertEquals(
'?facet=true&facet.missing=true&facet.limit=10&facet.field={!key=f1}owner&facet.query={!key=f2}category:23'. '?facet=true&facet.missing=true&facet.limit=10&facet.field={!key=f1}owner&facet.query={!key=f2}category:23'.
'&facet.query={!key=f4}category:40', '&facet.query={!key=f4}category:40',
urldecode($request->getUri()) urldecode($request->getUri())
...@@ -199,12 +199,12 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase ...@@ -199,12 +199,12 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$request = $this->builder->buildComponent($this->component, $this->request); $request = $this->builder->buildComponent($this->component, $this->request);
$this->assertEquals( static::assertEquals(
null, null,
$request->getRawData() $request->getRawData()
); );
$this->assertEquals( static::assertEquals(
'?facet=true&facet.pivot={!key=f1 ex=owner}cat,inStock&facet.pivot.mincount=123', '?facet=true&facet.pivot={!key=f1 ex=owner}cat,inStock&facet.pivot.mincount=123',
urldecode($request->getUri()) urldecode($request->getUri())
); );
...@@ -223,12 +223,12 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase ...@@ -223,12 +223,12 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$request = $this->builder->buildComponent($this->component, $this->request); $request = $this->builder->buildComponent($this->component, $this->request);
$this->assertEquals( static::assertEquals(
null, null,
$request->getRawData() $request->getRawData()
); );
$this->assertEquals( static::assertEquals(
'?facet=true&facet.pivot={!stats=piv1}cat,inStock', '?facet=true&facet.pivot={!stats=piv1}cat,inStock',
urldecode($request->getUri()) urldecode($request->getUri())
); );
...@@ -250,18 +250,18 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase ...@@ -250,18 +250,18 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$request = $this->builder->buildComponent($this->component, $this->request); $request = $this->builder->buildComponent($this->component, $this->request);
$this->assertEquals( static::assertEquals(
null, null,
$request->getRawData() $request->getRawData()
); );
$this->assertEquals( static::assertEquals(
'?facet=true&facet.contains=bar&facet.contains.ignoreCase=false&facet.field={!key=f1}owner&f.owner.facet.contains=foo&f.owner.facet.contains.ignoreCase=true', '?facet=true&facet.contains=bar&facet.contains.ignoreCase=false&facet.field={!key=f1}owner&f.owner.facet.contains=foo&f.owner.facet.contains.ignoreCase=true',
urldecode($request->getUri()) urldecode($request->getUri())
); );
} }
public function testBuildeWithIntervalFacet() public function testBuildWithIntervalFacet()
{ {
$facet = new FacetInterval( $facet = new FacetInterval(
array( array(
...@@ -275,13 +275,13 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase ...@@ -275,13 +275,13 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$request = $this->builder->buildComponent($this->component, $this->request); $request = $this->builder->buildComponent($this->component, $this->request);
$this->assertEquals( static::assertEquals(
null, null,
$request->getRawData() $request->getRawData()
); );
$this->assertEquals( static::assertEquals(
'?facet=true&f..facet.interval.set=int1&f..facet.interval.set={!key="one"}int2', '?facet=true&facet.interval={!key=f1}&f..facet.interval.set=int1&f..facet.interval.set={!key="one"}int2',
urldecode($request->getUri()) urldecode($request->getUri())
); );
} }
......
<?php
namespace Solarium\Tests\QueryType\Select\RequestBuilder\Component;
use Solarium\QueryType\Select\RequestBuilder\Component\Spatial as RequestBuilder;
use Solarium\QueryType\Select\Query\Component\Spatial as Component;
use Solarium\Core\Client\Request;
class SpatialTest extends \PHPUnit_Framework_TestCase
{
public function testBuildComponent()
{
$builder = new RequestBuilder();
$request = new Request();
$component = new Component();
$component->setField('geo');
$component->setDistance(50);
$component->setPoint('48.2233,16.3161');
$request = $builder->buildComponent($component, $request);
$this->assertEquals(
array(
'pt' => '48.2233,16.3161',
'sfield' => 'geo',
'd' => 50,
),
$request->getParams()
);
}
}
...@@ -64,6 +64,7 @@ class GroupingTest extends \PHPUnit_Framework_TestCase ...@@ -64,6 +64,7 @@ class GroupingTest extends \PHPUnit_Framework_TestCase
$this->query = new Query(); $this->query = new Query();
$this->grouping = $this->query->getGrouping(); $this->grouping = $this->query->getGrouping();
$this->grouping->addField('fieldA'); $this->grouping->addField('fieldA');
$this->grouping->setFunction('functionF');
$this->grouping->addQuery('cat:1'); $this->grouping->addQuery('cat:1');
$data = array( $data = array(
...@@ -83,6 +84,21 @@ class GroupingTest extends \PHPUnit_Framework_TestCase ...@@ -83,6 +84,21 @@ class GroupingTest extends \PHPUnit_Framework_TestCase
) )
) )
), ),
'functionF' => array(
'matches' => 8,
'ngroups' => 3,
'groups' => array(
array(
'groupValue' => true,
'doclist' => array(
'numFound' => 5,
'docs' => array(
array('id' => 3, 'name' => 'fun')
)
)
)
)
),
'cat:1' => array( 'cat:1' => array(
'matches' => 40, 'matches' => 40,
'doclist' => array( 'doclist' => array(
...@@ -101,13 +117,15 @@ class GroupingTest extends \PHPUnit_Framework_TestCase ...@@ -101,13 +117,15 @@ class GroupingTest extends \PHPUnit_Framework_TestCase
public function testGroupParsing() public function testGroupParsing()
{ {
$this->assertEquals(2, count($this->result->getGroups())); $this->assertEquals(3, count($this->result->getGroups()));
$fieldGroup = $this->result->getGroup('fieldA'); $fieldGroup = $this->result->getGroup('fieldA');
$queryGroup = $this->result->getGroup('cat:1'); $queryGroup = $this->result->getGroup('cat:1');
$functionGroup = $this->result->getGroup('functionF');
$this->assertEquals('Solarium\QueryType\Select\Result\Grouping\FieldGroup', get_class($fieldGroup)); $this->assertEquals('Solarium\QueryType\Select\Result\Grouping\FieldGroup', get_class($fieldGroup));
$this->assertEquals('Solarium\QueryType\Select\Result\Grouping\QueryGroup', get_class($queryGroup)); $this->assertEquals('Solarium\QueryType\Select\Result\Grouping\QueryGroup', get_class($queryGroup));
$this->assertEquals('Solarium\QueryType\Select\Result\Grouping\FieldGroup', get_class($functionGroup));
} }
public function testFieldGroupParsing() public function testFieldGroupParsing()
...@@ -142,4 +160,20 @@ class GroupingTest extends \PHPUnit_Framework_TestCase ...@@ -142,4 +160,20 @@ class GroupingTest extends \PHPUnit_Framework_TestCase
$result = $this->parser->parse($this->query, $this->grouping, array()); $result = $this->parser->parse($this->query, $this->grouping, array());
$this->assertEquals(array(), $result->getGroups()); $this->assertEquals(array(), $result->getGroups());
} }
public function testFunctionGroupParsing()
{
$fieldGroup = $this->result->getGroup('functionF');
$valueGroups = $fieldGroup->getValueGroups();
$this->assertEquals(8, $fieldGroup->getMatches());
$this->assertEquals(3, $fieldGroup->getNumberOfGroups());
$this->assertEquals(1, count($valueGroups));
$valueGroup = $valueGroups[0];
$this->assertEquals(5, $valueGroup->getNumFound());
$docs = $valueGroup->getDocuments();
$this->assertEquals('fun', $docs[0]->name);
}
} }
...@@ -194,12 +194,9 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase ...@@ -194,12 +194,9 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
'collations' => array( 'collations' => array(
'collation', 'collation',
array( array(
0 => 'collationQuery', 'collationQuery' => 'dell ultrasharp',
1 => 'dell ultrasharp', 'hits' => 0,
2 => 'hits', 'misspellingsAndCorrections' => array(
3 => 0,
4 => 'misspellingsAndCorrections',
5 => array(
0 => 'delll', 0 => 'delll',
1 => 'dell', 1 => 'dell',
2 => 'ultrashar', 2 => 'ultrashar',
...@@ -208,12 +205,9 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase ...@@ -208,12 +205,9 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
), ),
'collation', 'collation',
array( array(
0 => 'collationQuery', 'collationQuery' => 'dell ultrasharp new',
1 => 'dell ultrasharp new', 'hits' => 0,
2 => 'hits', 'misspellingsAndCorrections' => array(
3 => 0,
4 => 'misspellingsAndCorrections',
5 => array(
0 => 'delll', 0 => 'delll',
1 => 'dell', 1 => 'dell',
2 => 'ultrashar', 2 => 'ultrashar',
......
...@@ -31,15 +31,15 @@ ...@@ -31,15 +31,15 @@
namespace Solarium\Tests\QueryType\Update; namespace Solarium\Tests\QueryType\Update;
use Solarium\QueryType\Update\Query\Query;
use Solarium\QueryType\Update\RequestBuilder;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
use Solarium\QueryType\Update\Query\Command\Add as AddCommand; use Solarium\QueryType\Update\Query\Command\Add as AddCommand;
use Solarium\QueryType\Update\Query\Command\Commit as CommitCommand;
use Solarium\QueryType\Update\Query\Command\Delete as DeleteCommand; use Solarium\QueryType\Update\Query\Command\Delete as DeleteCommand;
use Solarium\QueryType\Update\Query\Command\Optimize as OptimizeCommand; use Solarium\QueryType\Update\Query\Command\Optimize as OptimizeCommand;
use Solarium\QueryType\Update\Query\Command\Commit as CommitCommand;
use Solarium\QueryType\Update\Query\Command\Rollback as RollbackCommand; use Solarium\QueryType\Update\Query\Command\Rollback as RollbackCommand;
use Solarium\QueryType\Update\Query\Document\Document; use Solarium\QueryType\Update\Query\Document\Document;
use Solarium\QueryType\Update\Query\Query;
use Solarium\QueryType\Update\RequestBuilder;
class RequestBuilderTest extends \PHPUnit_Framework_TestCase class RequestBuilderTest extends \PHPUnit_Framework_TestCase
{ {
...@@ -127,13 +127,52 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase ...@@ -127,13 +127,52 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
$command->addDocument(new Document(array('id' => array(1, 2, 3), 'text' => 'test < 123 > test'))); $command->addDocument(new Document(array('id' => array(1, 2, 3), 'text' => 'test < 123 > test')));
$this->assertEquals( $this->assertEquals(
'<add>'. '<add>' .
'<doc>'. '<doc>' .
'<field name="id">1</field>'. '<field name="id">1</field>' .
'<field name="id">2</field>'. '<field name="id">2</field>' .
'<field name="id">3</field>'. '<field name="id">3</field>' .
'<field name="text">test &lt; 123 &gt; test</field>'. '<field name="text">test &lt; 123 &gt; test</field>' .
'</doc>'. '</doc>' .
'</add>',
$this->builder->buildAddXml($command)
);
}
public function testBuildAddXmlWithNestedDocuments()
{
$command = new AddCommand;
$command->addDocument(
new Document(
array(
'id' => array(
array(
'nested_id' => 42,
'customer_ids' => array(
15,
16
)
),
2,
'foo'
),
'text' => 'test < 123 > test'
)
)
);
$this->assertEquals(
'<add>' .
'<doc>' .
'<doc>' .
'<field name="nested_id">42</field>' .
'<field name="customer_ids">15</field>' .
'<field name="customer_ids">16</field>' .
'</doc>' .
'<field name="id">2</field>' .
'<field name="id">foo</field>' .
'<field name="text">test &lt; 123 &gt; test</field>' .
'</doc>' .
'</add>', '</add>',
$this->builder->buildAddXml($command) $this->builder->buildAddXml($command)
); );
...@@ -189,13 +228,13 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase ...@@ -189,13 +228,13 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
$command->addDocument($doc); $command->addDocument($doc);
$this->assertEquals( $this->assertEquals(
'<add>'. '<add>' .
'<doc>'. '<doc>' .
'<field name="id">1</field>'. '<field name="id">1</field>' .
'<field name="category" update="add">123</field>'. '<field name="category" update="add">123</field>' .
'<field name="name" boost="2.5" update="set">test</field>'. '<field name="name" boost="2.5" update="set">test</field>' .
'<field name="stock" update="inc">2</field>'. '<field name="stock" update="inc">2</field>' .
'</doc>'. '</doc>' .
'</add>', '</add>',
$this->builder->buildAddXml($command) $this->builder->buildAddXml($command)
); );
...@@ -214,14 +253,14 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase ...@@ -214,14 +253,14 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
$command->addDocument($doc); $command->addDocument($doc);
$this->assertEquals( $this->assertEquals(
'<add>'. '<add>' .
'<doc>'. '<doc>' .
'<field name="id">1</field>'. '<field name="id">1</field>' .
'<field name="category" update="add">123</field>'. '<field name="category" update="add">123</field>' .
'<field name="category" update="add">234</field>'. '<field name="category" update="add">234</field>' .
'<field name="name" boost="2.3" update="set">test</field>'. '<field name="name" boost="2.3" update="set">test</field>' .
'<field name="stock" update="inc">2</field>'. '<field name="stock" update="inc">2</field>' .
'</doc>'. '</doc>' .
'</add>', '</add>',
$this->builder->buildAddXml($command) $this->builder->buildAddXml($command)
); );
...@@ -244,7 +283,9 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase ...@@ -244,7 +283,9 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
public function testBuildAddXmlWithDateTime() public function testBuildAddXmlWithDateTime()
{ {
$command = new AddCommand; $command = new AddCommand;
$command->addDocument(new Document(array('id' => 1, 'datetime' => new \DateTime('2013-01-15 14:41:58')))); $command->addDocument(
new Document(array('id' => 1, 'datetime' => new \DateTime('2013-01-15 14:41:58', new \DateTimeZone('Europe/London'))))
);
$this->assertEquals( $this->assertEquals(
'<add><doc><field name="id">1</field><field name="datetime">2013-01-15T14:41:58Z</field></doc></add>', '<add><doc><field name="id">1</field><field name="datetime">2013-01-15T14:41:58Z</field></doc></add>',
...@@ -262,11 +303,11 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase ...@@ -262,11 +303,11 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
$command->addDocument($doc); $command->addDocument($doc);
$this->assertEquals( $this->assertEquals(
'<add>'. '<add>' .
'<doc>'. '<doc>' .
'<field name="employeeId">05991</field>'. '<field name="employeeId">05991</field>' .
'<field name="skills" update="set" null="true"></field>'. '<field name="skills" update="set" null="true"></field>' .
'</doc>'. '</doc>' .
'</add>', '</add>',
$this->builder->buildAddXml($command) $this->builder->buildAddXml($command)
); );
...@@ -366,7 +407,7 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase ...@@ -366,7 +407,7 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
public function testBuildOptimizeXmlWithParams() public function testBuildOptimizeXmlWithParams()
{ {
$command = new OptimizeCommand(array('softcommit'=>true, 'waitsearcher'=>false, 'maxsegments'=>10)); $command = new OptimizeCommand(array('softcommit' => true, 'waitsearcher' => false, 'maxsegments' => 10));
$this->assertEquals( $this->assertEquals(
'<optimize softCommit="true" waitSearcher="false" maxSegments="10"/>', '<optimize softCommit="true" waitSearcher="false" maxSegments="10"/>',
...@@ -386,7 +427,7 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase ...@@ -386,7 +427,7 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
public function testBuildCommitXmlWithParams() public function testBuildCommitXmlWithParams()
{ {
$command = new CommitCommand(array('softcommit'=>true, 'waitsearcher'=>false, 'expungedeletes'=>true)); $command = new CommitCommand(array('softcommit' => true, 'waitsearcher' => false, 'expungedeletes' => true));
$this->assertEquals( $this->assertEquals(
'<commit softCommit="true" waitSearcher="false" expungeDeletes="true"/>', '<commit softCommit="true" waitSearcher="false" expungeDeletes="true"/>',
......
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