Commit 0766401c authored by Bas de Nooijer's avatar Bas de Nooijer

Merge branch 'release/3.1.2'

parents 224cb529 c3791415
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
], ],
"require": { "require": {
"php": ">=5.3.2", "php": ">=5.3.2",
"symfony/event-dispatcher": ">=2.1.0,<2.3-dev" "symfony/event-dispatcher": "~2.1"
}, },
"autoload": { "autoload": {
"psr-0": { "Solarium": "library/" } "psr-0": { "Solarium\\": "library/" }
} }
} }
...@@ -70,7 +70,7 @@ class Client extends CoreClient ...@@ -70,7 +70,7 @@ class Client extends CoreClient
* *
* @var string * @var string
*/ */
const VERSION = '3.0.0'; const VERSION = '3.2.0';
/** /**
* Check for an exact version * Check for an exact version
......
...@@ -194,7 +194,7 @@ class ZendHttp extends Configurable implements AdapterInterface ...@@ -194,7 +194,7 @@ class ZendHttp extends Configurable implements AdapterInterface
break; break;
} }
$client->setUri($endpoint->getBaseUri() . $request->getUri()); $client->setUri($endpoint->getBaseUri() . $request->getHandler());
$client->setHeaders($request->getHeaders()); $client->setHeaders($request->getHeaders());
$this->timeout = $endpoint->getTimeout(); $this->timeout = $endpoint->getTimeout();
......
...@@ -81,6 +81,13 @@ class BufferedAdd extends Plugin ...@@ -81,6 +81,13 @@ class BufferedAdd extends Plugin
*/ */
protected $buffer = array(); protected $buffer = array();
/**
* End point to execute updates against.
*
* @var string
*/
protected $endpoint;
/** /**
* Plugin init function * Plugin init function
* *
...@@ -94,6 +101,29 @@ class BufferedAdd extends Plugin ...@@ -94,6 +101,29 @@ class BufferedAdd extends Plugin
$this->updateQuery = $this->client->createUpdate(); $this->updateQuery = $this->client->createUpdate();
} }
/**
* Set the endpoint for the documents
*
* @param string $endpoint The endpoint to set
*
* @return self
*/
public function setEndpoint($endpoint)
{
$this->endpoint = $endpoint;
return $this;
}
/**
* Return the endpoint
*
* @return string
*/
public function getEndPoint()
{
return $this->endpoint;
}
/** /**
* Set buffer size option * Set buffer size option
* *
...@@ -208,7 +238,7 @@ class BufferedAdd extends Plugin ...@@ -208,7 +238,7 @@ class BufferedAdd extends Plugin
$this->client->getEventDispatcher()->dispatch(Events::PRE_FLUSH, $event); $this->client->getEventDispatcher()->dispatch(Events::PRE_FLUSH, $event);
$this->updateQuery->addDocuments($event->getBuffer(), $event->getOverwrite(), $event->getCommitWithin()); $this->updateQuery->addDocuments($event->getBuffer(), $event->getOverwrite(), $event->getCommitWithin());
$result = $this->client->update($this->updateQuery); $result = $this->client->update($this->updateQuery, $this->getEndpoint());
$this->clear(); $this->clear();
$event = new PostFlushEvent($result); $event = new PostFlushEvent($result);
...@@ -235,7 +265,7 @@ class BufferedAdd extends Plugin ...@@ -235,7 +265,7 @@ class BufferedAdd extends Plugin
$this->updateQuery->addDocuments($this->buffer, $event->getOverwrite()); $this->updateQuery->addDocuments($this->buffer, $event->getOverwrite());
$this->updateQuery->addCommit($event->getSoftCommit(), $event->getWaitSearcher(), $event->getExpungeDeletes()); $this->updateQuery->addCommit($event->getSoftCommit(), $event->getWaitSearcher(), $event->getExpungeDeletes());
$result = $this->client->update($this->updateQuery); $result = $this->client->update($this->updateQuery, $this->getEndpoint());
$this->clear(); $this->clear();
$event = new PostCommitEvent($result); $event = new PostCommitEvent($result);
......
...@@ -101,6 +101,7 @@ class RequestBuilder extends BaseRequestBuilder ...@@ -101,6 +101,7 @@ class RequestBuilder extends BaseRequestBuilder
// add file to request // add file to request
$request->setFileUpload($query->getFile()); $request->setFileUpload($query->getFile());
$request->addParam('resource.name', basename($query->getFile())); $request->addParam('resource.name', basename($query->getFile()));
$request->addHeader('Content-Type: multipart/form-data');
return $request; return $request;
} }
......
...@@ -43,7 +43,7 @@ use Solarium\QueryType\Select\RequestBuilder\RequestBuilder; ...@@ -43,7 +43,7 @@ use Solarium\QueryType\Select\RequestBuilder\RequestBuilder;
use Solarium\QueryType\Select\ResponseParser\ResponseParser; use Solarium\QueryType\Select\ResponseParser\ResponseParser;
use Solarium\Exception\InvalidArgumentException; use Solarium\Exception\InvalidArgumentException;
use Solarium\Exception\OutOfBoundsException; use Solarium\Exception\OutOfBoundsException;
use Solarium\QueryType\Select\Query\Component\Component; use Solarium\QueryType\Select\Query\Component\Component as AbstractComponent;
/** /**
* Select Query * Select Query
...@@ -787,7 +787,7 @@ class Query extends BaseQuery ...@@ -787,7 +787,7 @@ class Query extends BaseQuery
/** /**
* Get all registered components * Get all registered components
* *
* @return Component[] * @return AbstractComponent[]
*/ */
public function getComponents() public function getComponents()
{ {
...@@ -835,7 +835,7 @@ class Query extends BaseQuery ...@@ -835,7 +835,7 @@ class Query extends BaseQuery
* This overwrites any existing component registered with the same key. * This overwrites any existing component registered with the same key.
* *
* @param string $key * @param string $key
* @param Component $component * @param AbstractComponent $component
* @return self Provides fluent interface * @return self Provides fluent interface
*/ */
public function setComponent($key, $component) public function setComponent($key, $component)
...@@ -851,7 +851,7 @@ class Query extends BaseQuery ...@@ -851,7 +851,7 @@ class Query extends BaseQuery
* *
* You can remove a component by passing its key or the component instance. * You can remove a component by passing its key or the component instance.
* *
* @param string|Component\Component $component * @param string|AbstractComponent $component
* @return self Provides fluent interface * @return self Provides fluent interface
*/ */
public function removeComponent($component) public function removeComponent($component)
......
...@@ -49,6 +49,7 @@ use Solarium\QueryType\Update\Query\Command\Commit as CommitCommand; ...@@ -49,6 +49,7 @@ 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\Rollback as RollbackCommand; use Solarium\QueryType\Update\Query\Command\Rollback as RollbackCommand;
use Solarium\QueryType\Update\Query\Document\DocumentInterface;
/** /**
* Update query * Update query
...@@ -485,13 +486,13 @@ class Query extends BaseQuery ...@@ -485,13 +486,13 @@ class Query extends BaseQuery
* *
* @param array $fields * @param array $fields
* @param array $boosts * @param array $boosts
* @return Document * @param array $modifiers
* @return DocumentInterface
*/ */
public function createDocument($fields = array(), $boosts = array()) public function createDocument($fields = array(), $boosts = array(), $modifiers = array())
{ {
$class = $this->getDocumentClass(); $class = $this->getDocumentClass();
return new $class($fields, $boosts, $modifiers);
return new $class($fields, $boosts);
} }
} }
...@@ -87,7 +87,57 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase ...@@ -87,7 +87,57 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase
$this->assertThat($zendHttp, $this->isInstanceOf('Zend_Http_Client')); $this->assertThat($zendHttp, $this->isInstanceOf('Zend_Http_Client'));
} }
public function testExecute() public function testExecuteGet()
{
$method = Request::METHOD_GET;
$rawData = 'xyz';
$responseData = 'abc';
$handler = 'myhandler';
$headers = array(
'X-test: 123'
);
$params = array('a' => 1, 'b' => 2);
$request = new Request();
$request->setMethod($method);
$request->setHandler($handler);
$request->setHeaders($headers);
$request->setRawData($rawData);
$request->setParams($params);
$endpoint = new Endpoint();
$response = new \Zend_Http_Response(200, array('status' => 'HTTP 1.1 200 OK'), $responseData);
$mock = $this->getMock('Zend_Http_Client');
$mock->expects($this->once())
->method('setMethod')
->with($this->equalTo($method));
$mock->expects($this->once())
->method('setUri')
->with($this->equalTo('http://127.0.0.1:8983/solr/myhandler'));
$mock->expects($this->once())
->method('setHeaders')
->with($this->equalTo(array(
'X-test: 123',
)));
$mock->expects($this->once())
->method('setParameterGet')
->with($this->equalTo($params));
$mock->expects($this->once())
->method('request')
->will($this->returnValue($response));
$this->adapter->setZendHttp($mock);
$adapterResponse = $this->adapter->execute($request, $endpoint);
$this->assertEquals(
$responseData,
$adapterResponse->getBody()
);
}
public function testExecutePost()
{ {
$method = Request::METHOD_POST; $method = Request::METHOD_POST;
$rawData = 'xyz'; $rawData = 'xyz';
...@@ -96,12 +146,14 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase ...@@ -96,12 +146,14 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase
$headers = array( $headers = array(
'X-test: 123' 'X-test: 123'
); );
$params = array('a' => 1, 'b' => 2);
$request = new Request(); $request = new Request();
$request->setMethod($method); $request->setMethod($method);
$request->setHandler($handler); $request->setHandler($handler);
$request->setHeaders($headers); $request->setHeaders($headers);
$request->setRawData($rawData); $request->setRawData($rawData);
$request->setParams($params);
$endpoint = new Endpoint(); $endpoint = new Endpoint();
...@@ -113,7 +165,7 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase ...@@ -113,7 +165,7 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase
->with($this->equalTo($method)); ->with($this->equalTo($method));
$mock->expects($this->once()) $mock->expects($this->once())
->method('setUri') ->method('setUri')
->with($this->equalTo('http://127.0.0.1:8983/solr/myhandler?')); ->with($this->equalTo('http://127.0.0.1:8983/solr/myhandler'));
$mock->expects($this->once()) $mock->expects($this->once())
->method('setHeaders') ->method('setHeaders')
->with($this->equalTo(array( ->with($this->equalTo(array(
...@@ -123,6 +175,9 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase ...@@ -123,6 +175,9 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('setRawData') ->method('setRawData')
->with($this->equalTo($rawData)); ->with($this->equalTo($rawData));
$mock->expects($this->once())
->method('setParameterGet')
->with($this->equalTo($params));
$mock->expects($this->once()) $mock->expects($this->once())
->method('request') ->method('request')
->will($this->returnValue($response)); ->will($this->returnValue($response));
......
...@@ -34,6 +34,7 @@ use Solarium\QueryType\Update\Query\Document\Document; ...@@ -34,6 +34,7 @@ use Solarium\QueryType\Update\Query\Document\Document;
use Solarium\Plugin\BufferedAdd\Event\AddDocument; use Solarium\Plugin\BufferedAdd\Event\AddDocument;
use Solarium\Plugin\BufferedAdd\BufferedAdd; use Solarium\Plugin\BufferedAdd\BufferedAdd;
use Solarium\Core\Client\Client; use Solarium\Core\Client\Client;
use Solarium\Core\Client\Endpoint;
use Solarium\Plugin\BufferedAdd\Event\Events; use Solarium\Plugin\BufferedAdd\Event\Events;
class BufferedAddTest extends \PHPUnit_Framework_TestCase class BufferedAddTest extends \PHPUnit_Framework_TestCase
...@@ -195,4 +196,12 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase ...@@ -195,4 +196,12 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase
$plugin->addDocument($doc); $plugin->addDocument($doc);
} }
public function testSetAndGetEndpoint()
{
$endpoint = new Endpoint();
$endpoint->setKey('master');
$this->assertEquals($this->plugin, $this->plugin->setEndpoint($endpoint));
$this->assertEquals($endpoint, $this->plugin->getEndPoint());
}
} }
...@@ -471,12 +471,14 @@ class QueryTest extends \PHPUnit_Framework_TestCase ...@@ -471,12 +471,14 @@ class QueryTest extends \PHPUnit_Framework_TestCase
$this->assertThat($doc, $this->isInstanceOf(__NAMESPACE__.'\\MyCustomDoc')); $this->assertThat($doc, $this->isInstanceOf(__NAMESPACE__.'\\MyCustomDoc'));
} }
public function testCreateDocumentWithFieldsAndBoosts() public function testCreateDocumentWithFieldsAndBoostsAndModifiers()
{ {
$fields = array('id' => 1, 'name' => 'testname'); $fields = array('id' => 1, 'name' => 'testname');
$boosts = array('name' => 2.7); $boosts = array('name' => 2.7);
$modifiers = array('name' => 'set');
$doc = $this->query->createDocument($fields, $boosts); $doc = $this->query->createDocument($fields, $boosts, $modifiers);
$doc->setKey('id');
$this->assertThat($doc, $this->isInstanceOf($this->query->getDocumentClass())); $this->assertThat($doc, $this->isInstanceOf($this->query->getDocumentClass()));
...@@ -489,6 +491,11 @@ class QueryTest extends \PHPUnit_Framework_TestCase ...@@ -489,6 +491,11 @@ class QueryTest extends \PHPUnit_Framework_TestCase
2.7, 2.7,
$doc->getFieldBoost('name') $doc->getFieldBoost('name')
); );
$this->assertEquals(
$modifiers['name'],
$doc->getFieldModifier('name')
);
} }
} }
......
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