Commit fb830050 authored by Bas de Nooijer's avatar Bas de Nooijer

Various fixes for porting the extract querytype to Solarium 3 (work in progress...)

parent a7335438
......@@ -174,7 +174,7 @@ class ZendHttp extends Configurable implements AdapterInterface
switch ($request->getMethod()) {
case Request::METHOD_GET:
$client->setMethod(\Zend_Http_Client::GET);
$client->setParameterGet($request->getQueryAsArray());
$client->setParameterGet($request->getParams());
break;
case Request::METHOD_POST:
$client->setMethod(\Zend_Http_Client::POST);
......@@ -182,24 +182,22 @@ class ZendHttp extends Configurable implements AdapterInterface
if ($request->getFileUpload()) {
$this->prepareFileUpload($client, $request);
} else {
$client->setParameterGet($request->getQueryAsArray());
$client->setParameterGet($request->getParams());
$client->setRawData($request->getRawData());
$request->addHeader('Content-Type: text/xml; charset=UTF-8');
}
break;
case Request::METHOD_HEAD:
$client->setMethod(\Zend_Http_Client::HEAD);
$client->setParameterGet($request->getQueryAsArray());
$client->setParameterGet($request->getParams());
break;
default:
throw new OutOfBoundsException('Unsupported method: ' . $request->getMethod());
break;
}
$client->setMethod($request->getMethod());
$client->setUri($endpoint->getBaseUri() . $request->getUri());
$client->setHeaders($request->getHeaders());
$client->setRawData($request->getRawData());
$this->timeout = $endpoint->getTimeout();
$response = $client->request();
......@@ -271,7 +269,7 @@ class ZendHttp extends Configurable implements AdapterInterface
$client->setFileUpload('content', 'content', $content, 'application/octet-stream; charset=binary');
// set query params as "multipart/form-data" fields
foreach ($request->getQueryAsArray() as $name => $value) {
foreach ($request->getParams() as $name => $value) {
$client->setFileUpload(null, $name, $value, 'text/plain; charset=utf-8');
}
}
......
......@@ -38,27 +38,35 @@
* @subpackage Client
*/
/**
* @namespace
*/
namespace Solarium\QueryType\Extract;
use Solarium\Core\Query\QueryInterface;
use Solarium\Core\Query\RequestBuilder as BaseRequestBuilder;
use Solarium\Core\Client\Request;
use Solarium\Exception\RuntimeException;
/**
* Build an extract request
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_RequestBuilder_Extract extends Solarium_Client_RequestBuilder
class RequestBuilder extends BaseRequestBuilder
{
/**
* Build the request
*
* @param Solarium_Query_Extract $query
* @return Solarium_Client_Request
* @param Query $query
* @return Request
*/
public function build($query)
public function build(QueryInterface $query)
{
$request = parent::build($query);
$request->setMethod(Solarium_Client_Request::METHOD_POST);
// common options
$request->setMethod(Request::METHOD_POST);
// add common options to request
$request->addParam('commit', $query->getCommit());
$request->addParam('commitWithin', $query->getCommitWithin());
......@@ -70,11 +78,10 @@ class Solarium_Client_RequestBuilder_Extract extends Solarium_Client_RequestBuil
$request->addParam('fmap.' . $fromField, $toField);
}
// document
// add document settings to request
if (($doc = $query->getDocument()) != null) {
if ($doc->getBoost() !== null) {
throw new Solarium_Exception('Extract does not support document-level boosts, use field boosts instead.');
throw new RuntimeException('Extract does not support document-level boosts, use field boosts instead.');
}
// literal.*
......@@ -91,8 +98,7 @@ class Solarium_Client_RequestBuilder_Extract extends Solarium_Client_RequestBuil
}
}
// file
// add file to request
$request->setFileUpload($query->getFile());
$request->addParam('resource.name', basename($query->getFile()));
......
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\QueryType\Extract;
use Solarium\QueryType\Update\Result as UpdateResult;
/**
* An extract result is similar to an update result, but we do want to return a query specific result class instead of
* an update query result class.
*/
class Result extends UpdateResult
{
}
......@@ -89,12 +89,12 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase
public function testExecute()
{
$method = Request::METHOD_GET;
$method = Request::METHOD_POST;
$rawData = 'xyz';
$responseData = 'abc';
$handler = 'myhandler';
$headers = array(
'Content-Type: application/x-www-form-urlencoded'
'X-test: 123'
);
$request = new Request();
......@@ -116,7 +116,10 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase
->with($this->equalTo('http://127.0.0.1:8983/solr/myhandler?'));
$mock->expects($this->once())
->method('setHeaders')
->with($this->equalTo($headers));
->with($this->equalTo(array(
'X-test: 123',
'Content-Type: text/xml; charset=UTF-8',
)));
$mock->expects($this->once())
->method('setRawData')
->with($this->equalTo($rawData));
......
......@@ -488,6 +488,7 @@ authentication: Array
resource: /myHandler?param1=1&param2=test+content
resource urldecoded: /myHandler?param1=1&param2=test content
raw data: post data
file upload:
',
(string) $this->request
);
......
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