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
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
...
...
@@ -38,19 +38,28 @@
* @subpackage Query
*/
/**
* @namespace
*/
namespace
Solarium\QueryType\Extract
;
use
Solarium\Core\Query\Query
as
BaseQuery
;
use
Solarium\Core\Client\Client
;
use
Solarium\QueryType\Update\ResponseParser
as
UpdateResponseParser
;
use
Solarium\QueryType\Update\Query\Document
;
/**
* Extract query
*
* Sends a document extract request to Solr, i.e. upload rich document content
* such as PDF, Word or HTML, parse the file contents and add it to the index.
* Sends a document extract request to Solr, i.e. upload rich document content
* such as PDF, Word or HTML, parse the file contents and add it to the index.
*
* The Solr server must have the {@link http://wiki.apache.org/solr/ExtractingRequestHandler
* The Solr server must have the {@link http://wiki.apache.org/solr/ExtractingRequestHandler
* ExtractingRequestHandler} enabled.
*
* @package Solarium
* @subpackage Query
*/
class
Solarium_Query_Extract
extends
Solarium_
Query
class
Query
extends
Base
Query
{
/**
* Default options
...
...
@@ -59,7 +68,8 @@ class Solarium_Query_Extract extends Solarium_Query
*/
protected
$_options
=
array
(
'handler'
=>
'update/extract'
,
'resultclass'
=>
'Solarium_Result_Update'
,
'resultclass'
=>
'Solarium\QueryType\Extract\Result'
,
'omitheader'
=>
true
,
);
/**
...
...
@@ -67,7 +77,7 @@ class Solarium_Query_Extract extends Solarium_Query
*
* @var array
*/
protected
$
_
fieldMappings
=
array
();
protected
$fieldMappings
=
array
();
/**
* Get type for this query
...
...
@@ -76,9 +86,29 @@ class Solarium_Query_Extract extends Solarium_Query
*/
public
function
getType
()
{
return
Solarium_Client
::
QUERYTYPE
_EXTRACT
;
return
Client
::
QUERY
_EXTRACT
;
}
/**
* Get a requestbuilder for this query
*
* @return RequestBuilder
*/
public
function
getRequestBuilder
()
{
return
new
RequestBuilder
;
}
/**
* Get a response parser for this query
*
* @return UpdateResponseParser
*/
public
function
getResponseParser
()
{
return
new
UpdateResponseParser
;
}
/**
* Initialize options
*
...
...
@@ -94,26 +124,24 @@ class Solarium_Query_Extract extends Solarium_Query
}
}
// {{{ Options
/**
* Set the document with literal fields and boost settings
*
* The fields in the document are indexed together with the generated
* The fields in the document are indexed together with the generated
* fields that Solr extracts from the file.
*
* @param
Solarium_Document_ReadWrite
$document
* @return
Solarium_Query_Extract
*
* @param
Document
$document
* @return
self
*/
public
function
setDocument
(
$document
)
{
return
$this
->
_
setOption
(
'document'
,
$document
);
return
$this
->
setOption
(
'document'
,
$document
);
}
/**
* Get the document with literal fields and boost settings
*
* @return
Solarium_Document_ReadWrite
|null
*
* @return
Document
|null
*/
public
function
getDocument
()
{
...
...
@@ -122,18 +150,18 @@ class Solarium_Query_Extract extends Solarium_Query
/**
* Set the file to upload and index
*
*
* @param string $filename
* @return
Solarium_Query_Extract
* @return
self
*/
public
function
setFile
(
$filename
)
{
return
$this
->
_
setOption
(
'file'
,
$filename
);
return
$this
->
setOption
(
'file'
,
$filename
);
}
/**
* Get the file to upload and index
*
*
* @return string|null
*/
public
function
getFile
()
...
...
@@ -145,16 +173,16 @@ class Solarium_Query_Extract extends Solarium_Query
* Set the prefix for fields that are not defined in the schema
*
* @param string $uprefix
* @return
Solarium_Query_Extract
* @return
self
*/
public
function
setUprefix
(
$uprefix
)
{
return
$this
->
_
setOption
(
'uprefix'
,
$uprefix
);
return
$this
->
setOption
(
'uprefix'
,
$uprefix
);
}
/**
* Get the prefix for fields that are not defined in the schema
*
*
* @return string|null
*/
public
function
getUprefix
()
...
...
@@ -163,21 +191,21 @@ class Solarium_Query_Extract extends Solarium_Query
}
/**
* Set the field to use if uprefix is not specified and a field cannot be
* Set the field to use if uprefix is not specified and a field cannot be
* determined
*
* @param string $defaultField
* @return
Solarium_Query_Extract
* @return
self
*/
public
function
setDefaultField
(
$defaultField
)
{
return
$this
->
_
setOption
(
'defaultField'
,
$defaultField
);
return
$this
->
setOption
(
'defaultField'
,
$defaultField
);
}
/**
* Get the field to use if uprefix is not specified and a field cannot be
* Get the field to use if uprefix is not specified and a field cannot be
* determined
*
*
* @return string|null
*/
public
function
getDefaultField
()
...
...
@@ -186,20 +214,20 @@ class Solarium_Query_Extract extends Solarium_Query
}
/**
* Set if all field names should be mapped to lowercase with underscores.
* Set if all field names should be mapped to lowercase with underscores.
* For example, Content-Type would be mapped to content_type.
*
* @param bool $lowerNames
* @return
Solarium_Query_Extract
* @return
self
*/
public
function
setLowernames
(
$lowerNames
)
{
return
$this
->
_
setOption
(
'lowernames'
,
(
bool
)
$lowerNames
);
return
$this
->
setOption
(
'lowernames'
,
(
bool
)
$lowerNames
);
}
/**
* Get if all field names should be mapped to lowercase with underscores
*
*
* @return bool
*/
public
function
getLowernames
()
...
...
@@ -211,16 +239,16 @@ class Solarium_Query_Extract extends Solarium_Query
* Set if the extract should be committed immediately
*
* @param bool $commit
* @return
Solarium_Query_Extract
Provides fluent interface
* @return
self
Provides fluent interface
*/
public
function
setCommit
(
$commit
)
{
return
$this
->
_
setOption
(
'commit'
,
(
bool
)
$commit
);
return
$this
->
setOption
(
'commit'
,
(
bool
)
$commit
);
}
/**
* Get if the extract should be committed immediately
*
*
* @return bool
*/
public
function
getCommit
()
...
...
@@ -232,16 +260,16 @@ class Solarium_Query_Extract extends Solarium_Query
* Set milliseconds until extract update is committed. Since Solr 3.4
*
* @param int $commitWithin
* @return
Solarium_Query_Extract
Provides fluent interface
* @return
self
Provides fluent interface
*/
public
function
setCommitWithin
(
$commitWithin
)
{
return
$this
->
_
setOption
(
'commitWithin'
,
$commitWithin
);
return
$this
->
setOption
(
'commitWithin'
,
$commitWithin
);
}
/**
* Get milliseconds until extract update is committed. Since Solr 3.4
*
*
* @return int
*/
public
function
getCommitWithin
()
...
...
@@ -249,23 +277,19 @@ class Solarium_Query_Extract extends Solarium_Query
return
$this
->
getOption
(
'commitWithin'
);
}
// }}}
// {{{ Field Mappings
/**
* Add a name mapping from one field to another
*
* Example: fmap.content=text will cause the content field normally
* Example: fmap.content=text will cause the content field normally
* generated by Tika to be moved to the "text" field.
*
* @param string $fromField Original field name
* @param mixed|array $toField New field name
* @return
Solarium_Query_Extract
Provides fluent interface
* @return
self
Provides fluent interface
*/
public
function
addFieldMapping
(
$fromField
,
$toField
)
{
$this
->
_
fieldMappings
[
$fromField
]
=
$toField
;
$this
->
fieldMappings
[
$fromField
]
=
$toField
;
return
$this
;
}
...
...
@@ -274,7 +298,7 @@ class Solarium_Query_Extract extends Solarium_Query
* Add multiple field name mappings
*
* @param array $mappings Name mapping in the form [$fromField => $toField, ...]
* @return
Solarium_Query_Extract
Provides fluent interface
* @return
self
Provides fluent interface
*/
public
function
addFieldMappings
(
$mappings
)
{
...
...
@@ -289,12 +313,12 @@ class Solarium_Query_Extract extends Solarium_Query
* Remove a field name mapping
*
* @param string $fromField
* @return
Solarium_Query_Extract
Provides fluent interface
* @return
self
Provides fluent interface
*/
public
function
removeFieldMapping
(
$fromField
)
{
if
(
isset
(
$this
->
_
fieldMappings
[
$fromField
]))
{
unset
(
$this
->
_
fieldMappings
[
$fromField
]);
if
(
isset
(
$this
->
fieldMappings
[
$fromField
]))
{
unset
(
$this
->
fieldMappings
[
$fromField
]);
}
return
$this
;
...
...
@@ -303,11 +327,11 @@ class Solarium_Query_Extract extends Solarium_Query
/**
* Remove all field name mappings
*
* @return
Solarium_Query_Extract
Provides fluent interface
* @return
self
Provides fluent interface
*/
public
function
clearFieldMappings
()
{
$this
->
_
fieldMappings
=
array
();
$this
->
fieldMappings
=
array
();
return
$this
;
}
...
...
@@ -318,14 +342,14 @@ class Solarium_Query_Extract extends Solarium_Query
*/
public
function
getFieldMappings
()
{
return
$this
->
_
fieldMappings
;
return
$this
->
fieldMappings
;
}
/**
* Set many field name mappings. This overwrites any existing fields.
*
* @param array $mappings Name mapping in the form [$fromField => $toField, ...]
* @return
Solarium_Query_Extract
Provides fluent interface
* @return
self
Provides fluent interface
*/
public
function
setFieldMappings
(
$mappings
)
{
...
...
@@ -334,6 +358,4 @@ class Solarium_Query_Extract extends Solarium_Query
return
$this
;
}
// }}}
}
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