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
63b828b7
Commit
63b828b7
authored
Aug 15, 2011
by
Gasol Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apply patch from Issue #15 Add support for MoreLikeThis handler
parent
67423734
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
936 additions
and
0 deletions
+936
-0
library/Solarium/Client.php
library/Solarium/Client.php
+41
-0
library/Solarium/Client/RequestBuilder/MoreLikeThis.php
library/Solarium/Client/RequestBuilder/MoreLikeThis.php
+102
-0
library/Solarium/Query/MoreLikeThis.php
library/Solarium/Query/MoreLikeThis.php
+793
-0
No files found.
library/Solarium/Client.php
View file @
63b828b7
...
...
@@ -71,6 +71,7 @@ class Solarium_Client extends Solarium_Configurable
* Querytype ping
*/
const
QUERYTYPE_PING
=
'ping'
;
const
QUERYTYPE_MORELIKETHIS
=
'mlt'
;
/**
* Default options
...
...
@@ -102,6 +103,11 @@ class Solarium_Client extends Solarium_Configurable
'requestbuilder'
=>
'Solarium_Client_RequestBuilder_Ping'
,
'responseparser'
=>
'Solarium_Client_ResponseParser_Ping'
),
self
::
QUERYTYPE_MORELIKETHIS
=>
array
(
'query'
=>
'Solarium_Query_MoreLikeThis'
,
'requestbuilder'
=>
'Solarium_Client_RequestBuilder_MoreLikeThis'
,
'responseparser'
=>
'Solarium_Client_ResponseParser_MoreLikeThis'
),
);
/**
...
...
@@ -558,6 +564,30 @@ class Solarium_Client extends Solarium_Configurable
return
$this
->
execute
(
$query
);
}
/**
* Execute a MoreLikeThis query
*
* Example usage:
* <code>
* $client = new Solarium_Client;
* $query = $client->createMoreLikeThis();
* $result = $client->moreLikeThis($query);
* </code>
*
* @see Solarium_Query_Select
* @see Solarium_Result_Select
*
* @internal This is a convenience method that forwards the query to the
* execute method, thus allowing for an easy to use and clean API.
*
* @param Solarium_Query_Select $query
* @return Solarium_Result_Select
*/
public
function
moreLikeThis
(
$query
)
{
return
$this
->
execute
(
$query
);
}
/**
* Create a query instance
*
...
...
@@ -595,6 +625,17 @@ class Solarium_Client extends Solarium_Configurable
return
$this
->
createQuery
(
self
::
QUERYTYPE_SELECT
,
$options
);
}
/**
* Create a MoreLikeThis query instance
*
* @param mixed $options
* @return Solarium_Query_Select
*/
public
function
createMoreLikeThis
(
$options
=
null
)
{
return
$this
->
createQuery
(
self
::
QUERYTYPE_MORELIKETHIS
,
$options
);
}
/**
* Create an update query instance
*
...
...
library/Solarium/Client/RequestBuilder/MoreLikeThis.php
0 → 100644
View file @
63b828b7
<?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/
*
* @package Solarium
* @subpackage Client
*/
/**
* Build a MoreLikeThis request
*
* @package Solarium
* @subpackage Client
*/
class
Solarium_Client_RequestBuilder_MoreLikeThis
extends
Solarium_Client_RequestBuilder
{
/**
* Build request for a MoreLikeThis query
*
* @param Solarium_Query_Select $query
* @return Solarium_Client_Request
*/
public
function
build
(
$query
)
{
$request
=
new
Solarium_Client_Request
;
$request
->
setHandler
(
$query
->
getHandler
());
// add basic params to request
$request
->
addParam
(
'q'
,
$query
->
getQuery
());
$request
->
addParam
(
'mlt.match.offset'
,
$query
->
getStart
());
$request
->
addParam
(
'rows'
,
$query
->
getRows
());
$request
->
addParam
(
'mlt.fl'
,
implode
(
','
,
$query
->
getFields
()));
$request
->
addParam
(
'wt'
,
'json'
);
$request
->
addParam
(
'mlt.interestingTerms'
,
$query
->
getInterestingTerms
());
$request
->
addParam
(
'mlt.match.include'
,
$query
->
getMatchInclude
());
// add sort fields to request
$sort
=
array
();
foreach
(
$query
->
getSorts
()
AS
$field
=>
$order
)
{
$sort
[]
=
$field
.
' '
.
$order
;
}
if
(
count
(
$sort
)
!==
0
)
{
$request
->
addParam
(
'sort'
,
implode
(
','
,
$sort
));
}
// add filterqueries to request
$filterQueries
=
$query
->
getFilterQueries
();
if
(
count
(
$filterQueries
)
!==
0
)
{
foreach
(
$filterQueries
AS
$filterQuery
)
{
$fq
=
$this
->
renderLocalParams
(
$filterQuery
->
getQuery
(),
array
(
'tag'
=>
$filterQuery
->
getTags
())
);
$request
->
addParam
(
'fq'
,
$fq
);
}
}
// add components to request
$types
=
$query
->
getComponentTypes
();
foreach
(
$query
->
getComponents
()
as
$component
)
{
$componentBuilderClass
=
$types
[
$component
->
getType
()][
'requestbuilder'
];
if
(
!
empty
(
$componentBuilderClass
))
{
$componentBuilder
=
new
$componentBuilderClass
;
$request
=
$componentBuilder
->
build
(
$component
,
$request
);
}
}
return
$request
;
}
}
\ No newline at end of file
library/Solarium/Query/MoreLikeThis.php
0 → 100644
View file @
63b828b7
This diff is collapsed.
Click to expand it.
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