Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
solarium
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
solarium
Commits
fb830050
Commit
fb830050
authored
Jul 23, 2012
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Various fixes for porting the extract querytype to Solarium 3 (work in progress...)
parent
a7335438
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
156 additions
and
77 deletions
+156
-77
library/Solarium/Core/Client/Adapter/ZendHttp.php
library/Solarium/Core/Client/Adapter/ZendHttp.php
+4
-6
library/Solarium/QueryType/Extract/Query.php
library/Solarium/QueryType/Extract/Query.php
+78
-56
library/Solarium/QueryType/Extract/RequestBuilder.php
library/Solarium/QueryType/Extract/RequestBuilder.php
+18
-12
library/Solarium/QueryType/Extract/Result.php
library/Solarium/QueryType/Extract/Result.php
+49
-0
tests/Solarium/Tests/Core/Client/Adapter/ZendHttpTest.php
tests/Solarium/Tests/Core/Client/Adapter/ZendHttpTest.php
+6
-3
tests/Solarium/Tests/Core/Client/RequestTest.php
tests/Solarium/Tests/Core/Client/RequestTest.php
+1
-0
No files found.
library/Solarium/Core/Client/Adapter/ZendHttp.php
View file @
fb830050
...
...
@@ -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
->
get
QueryAsArray
());
$client
->
setParameterGet
(
$request
->
get
Params
());
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
->
get
QueryAsArray
());
$client
->
setParameterGet
(
$request
->
get
Params
());
$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
->
get
QueryAsArray
());
$client
->
setParameterGet
(
$request
->
get
Params
());
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
->
get
QueryAsArray
()
as
$name
=>
$value
)
{
foreach
(
$request
->
get
Params
()
as
$name
=>
$value
)
{
$client
->
setFileUpload
(
null
,
$name
,
$value
,
'text/plain; charset=utf-8'
);
}
}
...
...
library/Solarium/QueryType/Extract/Query.php
View file @
fb830050
This diff is collapsed.
Click to expand it.
library/Solarium/QueryType/Extract/RequestBuilder.php
View file @
fb830050
...
...
@@ -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
Base
RequestBuilder
{
/**
* 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
Runtime
Exception
(
'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
()));
...
...
library/Solarium/QueryType/Extract/Result.php
0 → 100644
View file @
fb830050
<?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
{
}
tests/Solarium/Tests/Core/Client/Adapter/ZendHttpTest.php
View file @
fb830050
...
...
@@ -89,12 +89,12 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase
public
function
testExecute
()
{
$method
=
Request
::
METHOD_
GE
T
;
$method
=
Request
::
METHOD_
POS
T
;
$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
));
...
...
tests/Solarium/Tests/Core/Client/RequestTest.php
View file @
fb830050
...
...
@@ -488,6 +488,7 @@ authentication: Array
resource: /myHandler?param1=1¶m2=test+content
resource urldecoded: /myHandler?param1=1¶m2=test content
raw data: post data
file upload:
'
,
(
string
)
$this
->
request
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment