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
## 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
......
......@@ -21,6 +21,9 @@
"zendframework/zendframework1": "~1.12",
"satooshi/php-coveralls": "~1.0"
},
"suggest": {
"minimalcode/search": "Query builder compatible with Solarium, allows simplified solr-query handling"
},
"extra": {
"branch-alias": {
"dev-develop": "3.3.x-dev"
......
......@@ -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)
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
require(__DIR__.'/init.php');
use Solarium\Core\Event\Events;
......@@ -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
require(__DIR__.'/init.php');
use Solarium\Client;
......@@ -297,4 +299,4 @@ Extending Solarium classes
You can extend any class in Solarium, there is no use of 'private' or 'final'. However, Solarium does have several built-in class mappings for factory methods. Most important are the querytype mapping in Solarium\\Client and the component mapping in Solarium\\QueryType\\Select\\Query\\Query. In some cases you might need to alter this mappings for your classes to be used.
Other than that, there are no special issues to be expected. You can extend Solarium classes like any other PHP class.
If your use case can be solved using plugins that is probably the safest choice, as by extending classes you gain access to non-public methods in the API. These are subject to change in future releases, where the public API is not (except for major releases).
\ No newline at end of file
If your use case can be solved using plugins that is probably the safest choice, as by extending classes you gain access to non-public methods in the API. These are subject to change in future releases, where the public API is not (except for major releases).
......@@ -28,7 +28,7 @@ See [<https://packagist.org>](https://packagist.org) for other packages.
```json
{
"require": {
"solarium/solarium": "2.4.0"
"solarium/solarium": "3.6.0"
}
}
```
......
......@@ -24,7 +24,9 @@ Options
Examples
--------
Grouping by field: ```php
Grouping by field:
```php
<?php
require(__DIR__.'/init.php');
......@@ -82,7 +84,9 @@ htmlFooter();
```
Grouping by query: ```php
Grouping by query:
```php
<?php
require(__DIR__.'/init.php');
......
......@@ -72,7 +72,7 @@ class Client extends CoreClient
*
* @var string
*/
const VERSION = '3.6.0';
const VERSION = '3.7.0';
/**
* Check for an exact version.
......
......@@ -180,7 +180,7 @@ abstract class AbstractFacet extends Configurable
break;
case 'exclude':
if (!is_array($value)) {
$value = array($value);
$value = explode(',', $value);
}
$this->setExcludes($value);
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
*/
const COMPONENT_DEBUG = 'debug';
/**
* Query component spatial.
*/
const COMPONENT_SPATIAL = 'spatial';
/**
* Default options.
*
......@@ -166,6 +171,7 @@ class Query extends BaseQuery
self::COMPONENT_DISTRIBUTEDSEARCH => 'Solarium\QueryType\Select\Query\Component\DistributedSearch',
self::COMPONENT_STATS => 'Solarium\QueryType\Select\Query\Component\Stats\Stats',
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
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.
*
......@@ -1090,7 +1108,7 @@ class Query extends BaseQuery
break;
case 'tag':
if (!is_array($value)) {
$value = array($value);
$value = explode(',', $value);
}
$this->addTags($value);
break;
......
......@@ -246,9 +246,8 @@ class FacetSet extends RequestBuilder implements ComponentRequestBuilderInterfac
$request->addParam(
'facet.interval',
$this->renderLocalParams(
$field
// key & ex not supported for interval
//,array('key' => $facet->getKey(), 'ex' => $facet->getExcludes())
$field,
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
// parse field groups
$valueResultClass = $grouping->getOption('resultvaluegroupclass');
$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])) {
$result = $data['grouped'][$field];
......
......@@ -141,10 +141,18 @@ class Spellcheck extends ResponseParserAbstract implements ComponentParserInterf
if ($queryObject->getResponseWriter() == $queryObject::WT_JSON) {
if (is_array(current($values))) {
foreach ($values as $key => $value) {
$values[$key] = $this->convertToKeyValueArray($value);
if (array_key_exists('collationQuery', $value)) {
$values[$key] = $value;
} else {
$values[$key] = $this->convertToKeyValueArray($value);
}
}
} else {
$values = array($this->convertToKeyValueArray($values));
if (array_key_exists('collationQuery', $values)) {
$values = array($values);
} else {
$values = array($this->convertToKeyValueArray($values));
}
}
}
......
......@@ -112,7 +112,7 @@ class RequestBuilder extends BaseRequestBuilder
* Build XML for an add command.
*
* @param \Solarium\QueryType\Update\Query\Command\Add $command
* @param UpdateQuery $query
* @param UpdateQuery $query
*
* @return string
*/
......@@ -131,13 +131,7 @@ class RequestBuilder extends BaseRequestBuilder
foreach ($doc->getFields() as $name => $value) {
$boost = $doc->getFieldBoost($name);
$modifier = $doc->getFieldModifier($name);
if (is_array($value)) {
foreach ($value as $multival) {
$xml .= $this->buildFieldXml($name, $boost, $multival, $modifier, $query);
}
} else {
$xml .= $this->buildFieldXml($name, $boost, $value, $modifier, $query);
}
$xml .= $this->buildFieldsXml($name, $boost, $value, $modifier, $query);
}
$version = $doc->getVersion();
......@@ -164,10 +158,10 @@ class RequestBuilder extends BaseRequestBuilder
{
$xml = '<delete>';
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) {
$xml .= '<query>'.htmlspecialchars($query, ENT_NOQUOTES, 'UTF-8').'</query>';
$xml .= '<query>' . htmlspecialchars($query, ENT_NOQUOTES, 'UTF-8') . '</query>';
}
$xml .= '</delete>';
......@@ -225,10 +219,10 @@ class RequestBuilder extends BaseRequestBuilder
*
* Used in the add command
*
* @param string $name
* @param float $boost
* @param mixed $value
* @param string $modifier
* @param string $name
* @param float $boost
* @param mixed $value
* @param string $modifier
* @param UpdateQuery $query
*
* @return string
......@@ -239,7 +233,7 @@ class RequestBuilder extends BaseRequestBuilder
$value = $query->getHelper()->formatDate($value);
}
$xml = '<field name="'.$name.'"';
$xml = '<field name="' . $name . '"';
$xml .= $this->attrib('boost', $boost);
$xml .= $this->attrib('update', $modifier);
if ($value === null) {
......@@ -250,9 +244,42 @@ class RequestBuilder extends BaseRequestBuilder
$value = 'true';
}
$xml .= '>'.htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8');
$xml .= '>' . htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8');
$xml .= '</field>';
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
$this->query->setTags(array('t3', 't4'));
$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 @@
* 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
* this list of 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"
......@@ -69,7 +69,7 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
{
$request = $this->builder->buildComponent($this->component, $this->request);
$this->assertEquals(
static::assertEquals(
array(),
$request->getParams()
);
......@@ -86,12 +86,12 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$request = $this->builder->buildComponent($this->component, $this->request);
$this->assertEquals(
static::assertEquals(
null,
$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',
urldecode($request->getUri())
);
......@@ -114,12 +114,12 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$request = $this->builder->buildComponent($this->component, $this->request);
$this->assertEquals(
static::assertEquals(
null,
$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',
urldecode($request->getUri())
);
......@@ -141,12 +141,12 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$request = $this->builder->buildComponent($this->component, $this->request);
$this->assertEquals(
static::assertEquals(
null,
$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',
urldecode($request->getUri())
......@@ -165,12 +165,12 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$request = $this->builder->buildComponent($this->component, $this->request);
$this->assertEquals(
static::assertEquals(
null,
$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.query={!key=f4}category:40',
urldecode($request->getUri())
......@@ -199,12 +199,12 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$request = $this->builder->buildComponent($this->component, $this->request);
$this->assertEquals(
static::assertEquals(
null,
$request->getRawData()
);
$this->assertEquals(
static::assertEquals(
'?facet=true&facet.pivot={!key=f1 ex=owner}cat,inStock&facet.pivot.mincount=123',
urldecode($request->getUri())
);
......@@ -223,12 +223,12 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$request = $this->builder->buildComponent($this->component, $this->request);
$this->assertEquals(
static::assertEquals(
null,
$request->getRawData()
);
$this->assertEquals(
static::assertEquals(
'?facet=true&facet.pivot={!stats=piv1}cat,inStock',
urldecode($request->getUri())
);
......@@ -250,18 +250,18 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$request = $this->builder->buildComponent($this->component, $this->request);
$this->assertEquals(
static::assertEquals(
null,
$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',
urldecode($request->getUri())
);
}
public function testBuildeWithIntervalFacet()
public function testBuildWithIntervalFacet()
{
$facet = new FacetInterval(
array(
......@@ -275,13 +275,13 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$request = $this->builder->buildComponent($this->component, $this->request);
$this->assertEquals(
static::assertEquals(
null,
$request->getRawData()
);
$this->assertEquals(
'?facet=true&f..facet.interval.set=int1&f..facet.interval.set={!key="one"}int2',
static::assertEquals(
'?facet=true&facet.interval={!key=f1}&f..facet.interval.set=int1&f..facet.interval.set={!key="one"}int2',
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
$this->query = new Query();
$this->grouping = $this->query->getGrouping();
$this->grouping->addField('fieldA');
$this->grouping->setFunction('functionF');
$this->grouping->addQuery('cat:1');
$data = array(
......@@ -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(
'matches' => 40,
'doclist' => array(
......@@ -101,13 +117,15 @@ class GroupingTest extends \PHPUnit_Framework_TestCase
public function testGroupParsing()
{
$this->assertEquals(2, count($this->result->getGroups()));
$this->assertEquals(3, count($this->result->getGroups()));
$fieldGroup = $this->result->getGroup('fieldA');
$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\QueryGroup', get_class($queryGroup));
$this->assertEquals('Solarium\QueryType\Select\Result\Grouping\FieldGroup', get_class($functionGroup));
}
public function testFieldGroupParsing()
......@@ -142,4 +160,20 @@ class GroupingTest extends \PHPUnit_Framework_TestCase
$result = $this->parser->parse($this->query, $this->grouping, array());
$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
'collations' => array(
'collation',
array(
0 => 'collationQuery',
1 => 'dell ultrasharp',
2 => 'hits',
3 => 0,
4 => 'misspellingsAndCorrections',
5 => array(
'collationQuery' => 'dell ultrasharp',
'hits' => 0,
'misspellingsAndCorrections' => array(
0 => 'delll',
1 => 'dell',
2 => 'ultrashar',
......@@ -208,12 +205,9 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
),
'collation',
array(
0 => 'collationQuery',
1 => 'dell ultrasharp new',
2 => 'hits',
3 => 0,
4 => 'misspellingsAndCorrections',
5 => array(
'collationQuery' => 'dell ultrasharp new',
'hits' => 0,
'misspellingsAndCorrections' => array(
0 => 'delll',
1 => 'dell',
2 => 'ultrashar',
......
......@@ -31,15 +31,15 @@
namespace Solarium\Tests\QueryType\Update;
use Solarium\QueryType\Update\Query\Query;
use Solarium\QueryType\Update\RequestBuilder;
use Solarium\Core\Client\Request;
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\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\Document\Document;
use Solarium\QueryType\Update\Query\Query;
use Solarium\QueryType\Update\RequestBuilder;
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')));
$this->assertEquals(
'<add>'.
'<doc>'.
'<field name="id">1</field>'.
'<field name="id">2</field>'.
'<field name="id">3</field>'.
'<field name="text">test &lt; 123 &gt; test</field>'.
'</doc>'.
'<add>' .
'<doc>' .
'<field name="id">1</field>' .
'<field name="id">2</field>' .
'<field name="id">3</field>' .
'<field name="text">test &lt; 123 &gt; test</field>' .
'</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>',
$this->builder->buildAddXml($command)
);
......@@ -189,13 +228,13 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
$command->addDocument($doc);
$this->assertEquals(
'<add>'.
'<doc>'.
'<field name="id">1</field>'.
'<field name="category" update="add">123</field>'.
'<field name="name" boost="2.5" update="set">test</field>'.
'<field name="stock" update="inc">2</field>'.
'</doc>'.
'<add>' .
'<doc>' .
'<field name="id">1</field>' .
'<field name="category" update="add">123</field>' .
'<field name="name" boost="2.5" update="set">test</field>' .
'<field name="stock" update="inc">2</field>' .
'</doc>' .
'</add>',
$this->builder->buildAddXml($command)
);
......@@ -214,14 +253,14 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
$command->addDocument($doc);
$this->assertEquals(
'<add>'.
'<doc>'.
'<field name="id">1</field>'.
'<field name="category" update="add">123</field>'.
'<field name="category" update="add">234</field>'.
'<field name="name" boost="2.3" update="set">test</field>'.
'<field name="stock" update="inc">2</field>'.
'</doc>'.
'<add>' .
'<doc>' .
'<field name="id">1</field>' .
'<field name="category" update="add">123</field>' .
'<field name="category" update="add">234</field>' .
'<field name="name" boost="2.3" update="set">test</field>' .
'<field name="stock" update="inc">2</field>' .
'</doc>' .
'</add>',
$this->builder->buildAddXml($command)
);
......@@ -244,7 +283,9 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
public function testBuildAddXmlWithDateTime()
{
$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(
'<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
$command->addDocument($doc);
$this->assertEquals(
'<add>'.
'<doc>'.
'<field name="employeeId">05991</field>'.
'<field name="skills" update="set" null="true"></field>'.
'</doc>'.
'<add>' .
'<doc>' .
'<field name="employeeId">05991</field>' .
'<field name="skills" update="set" null="true"></field>' .
'</doc>' .
'</add>',
$this->builder->buildAddXml($command)
);
......@@ -366,7 +407,7 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
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(
'<optimize softCommit="true" waitSearcher="false" maxSegments="10"/>',
......@@ -386,7 +427,7 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
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(
'<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