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
31dc7f69
Commit
31dc7f69
authored
Apr 18, 2011
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/component-structure' into develop
parents
a23a3644
e1e34a59
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
1351 additions
and
8 deletions
+1351
-8
library/Solarium/Client/Request/Select.php
library/Solarium/Client/Request/Select.php
+34
-0
library/Solarium/Client/Request/Update.php
library/Solarium/Client/Request/Update.php
+1
-2
library/Solarium/Client/Response/Select.php
library/Solarium/Client/Response/Select.php
+56
-1
library/Solarium/Query/Select.php
library/Solarium/Query/Select.php
+82
-0
library/Solarium/Query/Select/Component.php
library/Solarium/Query/Select/Component.php
+71
-0
library/Solarium/Query/Select/Component/MoreLikeThis.php
library/Solarium/Query/Select/Component/MoreLikeThis.php
+315
-0
library/Solarium/Query/Update.php
library/Solarium/Query/Update.php
+3
-1
library/Solarium/Result/Select.php
library/Solarium/Result/Select.php
+45
-1
library/Solarium/Result/Select/MoreLikeThis.php
library/Solarium/Result/Select/MoreLikeThis.php
+109
-0
library/Solarium/Result/Select/MoreLikeThis/Result.php
library/Solarium/Result/Select/MoreLikeThis/Result.php
+138
-0
tests/Solarium/Client/Request/SelectTest.php
tests/Solarium/Client/Request/SelectTest.php
+31
-0
tests/Solarium/Query/Select/Component/MoreLikeThisTest.php
tests/Solarium/Query/Select/Component/MoreLikeThisTest.php
+152
-0
tests/Solarium/Query/Select/ComponentTest.php
tests/Solarium/Query/Select/ComponentTest.php
+46
-0
tests/Solarium/Query/SelectTest.php
tests/Solarium/Query/SelectTest.php
+59
-1
tests/Solarium/Result/Select/MoreLikeThis/ResultTest.php
tests/Solarium/Result/Select/MoreLikeThis/ResultTest.php
+80
-0
tests/Solarium/Result/Select/MoreLikeThisTest.php
tests/Solarium/Result/Select/MoreLikeThisTest.php
+94
-0
tests/Solarium/Result/SelectTest.php
tests/Solarium/Result/SelectTest.php
+35
-2
No files found.
library/Solarium/Client/Request/Select.php
View file @
31dc7f69
...
@@ -81,6 +81,17 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
...
@@ -81,6 +81,17 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
}
}
}
}
foreach
(
$this
->
_query
->
getComponents
()
as
$component
)
{
switch
(
$component
->
getType
())
{
case
Solarium_Query_Select_Component
::
MORELIKETHIS
:
$this
->
addMoreLikeThis
(
$component
);
break
;
default
:
throw
new
Solarium_Exception
(
'Unknown component type'
);
}
}
$facets
=
$this
->
_query
->
getFacets
();
$facets
=
$this
->
_query
->
getFacets
();
if
(
count
(
$facets
)
!==
0
)
{
if
(
count
(
$facets
)
!==
0
)
{
...
@@ -149,4 +160,27 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
...
@@ -149,4 +160,27 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
);
);
}
}
/**
* Add params for morelikethis
*
* @param Solarium_Query_Select_Component_MoreLikeThis $component
* @return void
*/
public
function
addMoreLikeThis
(
$component
)
{
// enable morelikethis
$this
->
_params
[
'mlt'
]
=
'true'
;
$this
->
addParam
(
'mlt.fl'
,
$component
->
getFields
());
$this
->
addParam
(
'mlt.mintf'
,
$component
->
getMinimumTermFrequency
());
$this
->
addParam
(
'mlt.mindf'
,
$component
->
getMinimumDocumentFrequency
());
$this
->
addParam
(
'mlt.minwl'
,
$component
->
getMinimumWordLength
());
$this
->
addParam
(
'mlt.maxwl'
,
$component
->
getMaximumWordLength
());
$this
->
addParam
(
'mlt.maxqt'
,
$component
->
getMaximumQueryTerms
());
$this
->
addParam
(
'mlt.maxntp'
,
$component
->
getMaximumNumberOfTokens
());
$this
->
addParam
(
'mlt.boost'
,
$component
->
getBoost
());
$this
->
addParam
(
'mlt.qf'
,
$component
->
getQueryFields
());
$this
->
addParam
(
'mlt.count'
,
$component
->
getCount
());
}
}
}
\ No newline at end of file
library/Solarium/Client/Request/Update.php
View file @
31dc7f69
...
@@ -129,8 +129,7 @@ class Solarium_Client_Request_Update extends Solarium_Client_Request
...
@@ -129,8 +129,7 @@ class Solarium_Client_Request_Update extends Solarium_Client_Request
foreach
(
$doc
->
getFields
()
AS
$name
=>
$value
)
{
foreach
(
$doc
->
getFields
()
AS
$name
=>
$value
)
{
$boost
=
$doc
->
getFieldBoost
(
$name
);
$boost
=
$doc
->
getFieldBoost
(
$name
);
if
(
is_array
(
$value
))
if
(
is_array
(
$value
))
{
{
foreach
(
$value
AS
$multival
)
{
foreach
(
$value
AS
$multival
)
{
$xml
.=
$this
->
_buildFieldXml
(
$name
,
$boost
,
$multival
);
$xml
.=
$this
->
_buildFieldXml
(
$name
,
$boost
,
$multival
);
}
}
...
...
library/Solarium/Client/Response/Select.php
View file @
31dc7f69
...
@@ -56,6 +56,13 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
...
@@ -56,6 +56,13 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
*/
*/
protected
$_facets
=
array
();
protected
$_facets
=
array
();
/**
* Component results
*
* @var array
*/
protected
$_components
=
array
();
/**
/**
* Get a result instance for the response
* Get a result instance for the response
*
*
...
@@ -75,6 +82,18 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
...
@@ -75,6 +82,18 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
}
}
}
}
// component results
foreach
(
$this
->
_query
->
getComponents
()
as
$component
)
{
switch
(
$component
->
getType
())
{
case
Solarium_Query_Select_Component
::
MORELIKETHIS
:
$this
->
_addMoreLikeThis
(
$component
);
break
;
default
:
throw
new
Solarium_Exception
(
'Unknown component type'
);
}
}
// create facet results
// create facet results
foreach
(
$this
->
_query
->
getFacets
()
AS
$facet
)
{
foreach
(
$this
->
_query
->
getFacets
()
AS
$facet
)
{
switch
(
$facet
->
getType
())
{
switch
(
$facet
->
getType
())
{
...
@@ -97,7 +116,7 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
...
@@ -97,7 +116,7 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
// create the result instance that combines all data
// create the result instance that combines all data
$resultClass
=
$this
->
_query
->
getOption
(
'resultclass'
);
$resultClass
=
$this
->
_query
->
getOption
(
'resultclass'
);
return
new
$resultClass
(
return
new
$resultClass
(
$status
,
$queryTime
,
$numFound
,
$documents
,
$this
->
_facets
$status
,
$queryTime
,
$numFound
,
$documents
,
$this
->
_facets
,
$this
->
_components
);
);
}
}
...
@@ -143,4 +162,40 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
...
@@ -143,4 +162,40 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
new
Solarium_Result_Select_Facet_Query
(
$value
);
new
Solarium_Result_Select_Facet_Query
(
$value
);
}
}
}
}
/**
* Add morelikethis result
*
* @param Solarium_Query_Select_Component_MoreLikeThis $component
* @return void
*/
protected
function
_addMoreLikeThis
(
$component
)
{
$results
=
array
();
if
(
isset
(
$this
->
_data
[
'moreLikeThis'
]))
{
$documentClass
=
$this
->
_query
->
getOption
(
'documentclass'
);
$searchResults
=
$this
->
_data
[
'moreLikeThis'
];
foreach
(
$searchResults
AS
$key
=>
$result
)
{
// create document instances
$docs
=
array
();
foreach
(
$result
[
'docs'
]
AS
$fields
)
{
$docs
[]
=
new
$documentClass
(
$fields
);
}
$results
[
$key
]
=
new
Solarium_Result_Select_MoreLikeThis_Result
(
$result
[
'numFound'
],
$result
[
'maxScore'
],
$docs
);
}
}
$moreLikeThis
=
new
Solarium_Result_Select_MoreLikeThis
(
$results
);
$this
->
_components
[
$component
->
getType
()]
=
$moreLikeThis
;
}
}
}
\ No newline at end of file
library/Solarium/Query/Select.php
View file @
31dc7f69
...
@@ -97,6 +97,13 @@ class Solarium_Query_Select extends Solarium_Query
...
@@ -97,6 +97,13 @@ class Solarium_Query_Select extends Solarium_Query
*/
*/
protected
$_facets
=
array
();
protected
$_facets
=
array
();
/**
* Search components
*
* @var array
*/
protected
$_components
=
array
();
/**
/**
* Initialize options
* Initialize options
*
*
...
@@ -643,4 +650,79 @@ class Solarium_Query_Select extends Solarium_Query
...
@@ -643,4 +650,79 @@ class Solarium_Query_Select extends Solarium_Query
$this
->
addFacets
(
$facets
);
$this
->
addFacets
(
$facets
);
}
}
/**
* Get all registered components
*
* @return array
*/
public
function
getComponents
()
{
return
$this
->
_components
;
}
/**
* Get a component instance by key
*
* You can optionally supply an autoload class to create a new component
* instance if there is no registered component for the given key yet.
*
* @param string $key Use one of the constants
* @param string $autoload Class to autoload if component needs to be created
* @return object|null
*/
public
function
getComponent
(
$key
,
$autoload
=
null
)
{
if
(
isset
(
$this
->
_components
[
$key
]))
{
return
$this
->
_components
[
$key
];
}
else
{
if
(
$autoload
!==
null
)
{
$component
=
new
$autoload
;
$this
->
setComponent
(
$key
,
$component
);
return
$this
->
_components
[
$key
];
}
return
null
;
}
}
/**
* Set a component instance
*
* This overwrites any existing component registered with the same key.
*
* @param string $key
* @param object|null $value
* @return Solarium_Query_Select Provides fluent interface
*/
public
function
setComponent
(
$key
,
$value
)
{
$this
->
_components
[
$key
]
=
$value
;
return
$this
;
}
/**
* Remove a component instance
*
* @param string $key
* @return Solarium_Query_Select Provides fluent interface
*/
public
function
removeComponent
(
$key
)
{
if
(
isset
(
$this
->
_components
[
$key
]))
{
unset
(
$this
->
_components
[
$key
]);
}
return
$this
;
}
/**
* Get a MoreLikeThis component instance
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Query_Select_Component_MoreLikeThis
*/
public
function
getMoreLikeThis
()
{
return
$this
->
getComponent
(
'MoreLikeThis'
,
'Solarium_Query_Select_Component_MoreLikeThis'
);
}
}
}
\ No newline at end of file
library/Solarium/Query/Select/Component.php
0 → 100644
View file @
31dc7f69
<?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
*
* @package Solarium
* @subpackage Query
*/
/**
* Query component base class
*
* @package Solarium
* @subpackage Query
*/
class
Solarium_Query_Select_Component
extends
Solarium_Configurable
{
/**
* Component types
*/
const
MORELIKETHIS
=
'morelikethis'
;
/**
* Component type
*
* To be implemented in extending classes
*
* @var string
*/
protected
$_type
=
''
;
/**
* Get component type
*
* @return string
*/
public
function
getType
()
{
return
$this
->
_type
;
}
}
\ No newline at end of file
library/Solarium/Query/Select/Component/MoreLikeThis.php
0 → 100644
View file @
31dc7f69
<?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
*
* @package Solarium
* @subpackage Query
*/
/**
* MoreLikeThis component
*
* @link http://wiki.apache.org/solr/MoreLikeThis
*
* @package Solarium
* @subpackage Query
*/
class
Solarium_Query_Select_Component_MoreLikeThis
extends
Solarium_Query_Select_Component
{
/**
* Component type
*
* @var string
*/
protected
$_type
=
self
::
MORELIKETHIS
;
/**
* Default options
*
* @var array
*/
protected
$_options
=
array
(
'fields'
=>
null
,
'minimumtermfrequency'
=>
null
,
'minimumdocumentfrequency'
=>
null
,
'minimumwordlength'
=>
null
,
'maximumwordlength'
=>
null
,
'maximumqueryterms'
=>
null
,
'maximumnumberoftokens'
=>
null
,
'boost'
=>
null
,
'queryfields'
=>
null
,
'count'
=>
null
,
);
/**
* Set fields option
*
* The fields to use for similarity. NOTE: if possible, these should have a
* stored TermVector
*
* Separate multiple fields with commas.
*
* @param string $fields
* @return Solarium_Query_Component_MoreLikeThis Provides fluent interface
*/
public
function
setFields
(
$fields
)
{
return
$this
->
_setOption
(
'fields'
,
$fields
);
}
/**
* Get fields option
*
* @return string|null
*/
public
function
getFields
()
{
return
$this
->
getOption
(
'fields'
);
}
/**
* Set minimumtermfrequency option
*
* Minimum Term Frequency - the frequency below which terms will be ignored
* in the source doc.
*
* @param int $minimum
* @return Solarium_Query_Component_MoreLikeThis Provides fluent interface
*/
public
function
setMinimumTermFrequency
(
$minimum
)
{
return
$this
->
_setOption
(
'minimumtermfrequency'
,
$minimum
);
}
/**
* Get minimumtermfrequency option
*
* @return integer|null
*/
public
function
getMinimumTermFrequency
()
{
return
$this
->
getOption
(
'minimumtermfrequency'
);
}
/**
* Set minimumdocumentfrequency option
*
* Minimum Document Frequency - the frequency at which words will be
* ignored which do not occur in at least this many docs.
*
* @param int $minimum
* @return Solarium_Query_Component_MoreLikeThis Provides fluent interface
*/
public
function
setMinimumDocumentFrequency
(
$minimum
)
{
return
$this
->
_setOption
(
'minimumdocumentfrequency'
,
$minimum
);
}
/**
* Get minimumdocumentfrequency option
*
* @return integer|null
*/
public
function
getMinimumDocumentFrequency
()
{
return
$this
->
getOption
(
'minimumdocumentfrequency'
);
}
/**
* Set minimumwordlength option
*
* Minimum word length below which words will be ignored.
*
* @param int $minimum
* @return Solarium_Query_Component_MoreLikeThis Provides fluent interface
*/
public
function
setMinimumWordLength
(
$minimum
)
{
return
$this
->
_setOption
(
'minimumwordlength'
,
$minimum
);
}
/**
* Get minimumwordlength option
*
* @return integer|null
*/
public
function
getMinimumWordLength
()
{
return
$this
->
getOption
(
'minimumwordlength'
);
}
/**
* Set maximumwordlength option
*
* Maximum word length above which words will be ignored.
*
* @param int $maximum
* @return Solarium_Query_Component_MoreLikeThis Provides fluent interface
*/
public
function
setMaximumWordLength
(
$maximum
)
{
return
$this
->
_setOption
(
'maximumwordlength'
,
$maximum
);
}
/**
* Get maximumwordlength option
*
* @return integer|null
*/
public
function
getMaximumWordLength
()
{
return
$this
->
getOption
(
'maximumwordlength'
);
}
/**
* Set maximumqueryterms option
*
* Maximum number of query terms that will be included in any generated
* query.
*
* @param int $maximum
* @return Solarium_Query_Component_MoreLikeThis Provides fluent interface
*/
public
function
setMaximumQueryTerms
(
$maximum
)
{
return
$this
->
_setOption
(
'maximumqueryterms'
,
$maximum
);
}
/**
* Get maximumqueryterms option
*
* @return integer|null
*/
public
function
getMaximumQueryTerms
()
{
return
$this
->
getOption
(
'maximumqueryterms'
);
}
/**
* Set maximumnumberoftokens option
*
* Maximum number of tokens to parse in each example doc field that is not
* stored with TermVector support.
*
* @param int $maximum
* @return Solarium_Query_Component_MoreLikeThis Provides fluent interface
*/
public
function
setMaximumNumberOfTokens
(
$maximum
)
{
return
$this
->
_setOption
(
'maximumnumberoftokens'
,
$maximum
);
}
/**
* Get maximumnumberoftokens option
*
* @return integer|null
*/
public
function
getMaximumNumberOfTokens
()
{
return
$this
->
getOption
(
'maximumnumberoftokens'
);
}
/**
* Set boost option
*
* If true the query will be boosted by the interesting term relevance.
*
* @param boolean $boost
* @return Solarium_Query_Component_MoreLikeThis Provides fluent interface
*/
public
function
setBoost
(
$boost
)
{
return
$this
->
_setOption
(
'boost'
,
$boost
);
}
/**
* Get boost option
*
* @return boolean|null
*/
public
function
getBoost
()
{
return
$this
->
getOption
(
'boost'
);
}
/**
* Set queryfields option
*
* Query fields and their boosts using the same format as that used in
* DisMaxQParserPlugin. These fields must also be specified in fields.
*
* Separate multiple fields with commas.
*
* @param string $queryFields
* @return Solarium_Query_Component_MoreLikeThis Provides fluent interface
*/
public
function
setQueryFields
(
$queryFields
)
{
return
$this
->
_setOption
(
'queryfields'
,
$queryFields
);
}
/**
* Get queryfields option
*
* @return string|null
*/
public
function
getQueryFields
()
{
return
$this
->
getOption
(
'queryfields'
);
}
/**
* Set count option
*
* The number of similar documents to return for each result
*
* @param int $count
* @return Solarium_Query_Component_MoreLikeThis Provides fluent interface
*/
public
function
setCount
(
$count
)
{
return
$this
->
_setOption
(
'count'
,
$count
);
}
/**
* Get count option
*
* @return int|null
*/
public
function
getCount
()
{
return
$this
->
getOption
(
'count'
);
}
}
\ No newline at end of file
library/Solarium/Query/Update.php
View file @
31dc7f69
...
@@ -94,7 +94,9 @@ class Solarium_Query_Update extends Solarium_Query
...
@@ -94,7 +94,9 @@ class Solarium_Query_Update extends Solarium_Query
$command
=
new
Solarium_Query_Update_Command_Rollback
(
$value
);
$command
=
new
Solarium_Query_Update_Command_Rollback
(
$value
);
break
;
break
;
case
'add'
:
case
'add'
:
throw
new
Solarium_Exception
(
"Adding documents is not supported in configuration, use the API for this"
);
throw
new
Solarium_Exception
(
"Adding documents is not supported in configuration, use the API for this"
);
}
}
$this
->
add
(
$key
,
$command
);
$this
->
add
(
$key
,
$command
);
...
...
library/Solarium/Result/Select.php
View file @
31dc7f69
...
@@ -85,6 +85,11 @@ class Solarium_Result_Select extends Solarium_Result_Query
...
@@ -85,6 +85,11 @@ class Solarium_Result_Select extends Solarium_Result_Query
*/
*/
protected
$_facets
;
protected
$_facets
;
/**
* Component results
*/
protected
$_components
;
/**
/**
* Constructor
* Constructor
*
*
...
@@ -96,16 +101,18 @@ class Solarium_Result_Select extends Solarium_Result_Query
...
@@ -96,16 +101,18 @@ class Solarium_Result_Select extends Solarium_Result_Query
* @param int $numFound
* @param int $numFound
* @param array $documents
* @param array $documents
* @param array $facets
* @param array $facets
* @param array $components
* @return void
* @return void
*/
*/
public
function
__construct
(
$status
,
$queryTime
,
$numFound
,
$documents
,
public
function
__construct
(
$status
,
$queryTime
,
$numFound
,
$documents
,
$facets
)
$facets
,
$components
)
{
{
$this
->
_status
=
$status
;
$this
->
_status
=
$status
;
$this
->
_queryTime
=
$queryTime
;
$this
->
_queryTime
=
$queryTime
;
$this
->
_numFound
=
$numFound
;
$this
->
_numFound
=
$numFound
;
$this
->
_documents
=
$documents
;
$this
->
_documents
=
$documents
;
$this
->
_facets
=
$facets
;
$this
->
_facets
=
$facets
;
$this
->
_components
=
$components
;
}
}
/**
/**
...
@@ -175,4 +182,41 @@ class Solarium_Result_Select extends Solarium_Result_Query
...
@@ -175,4 +182,41 @@ class Solarium_Result_Select extends Solarium_Result_Query
{
{
return
count
(
$this
->
_documents
);
return
count
(
$this
->
_documents
);
}
}
/**
* Get all component results
*
* @return array
*/
public
function
getComponents
()
{
return
$this
->
_components
;
}
/**
* Get a component result by key
*
* @param string $key
* @return Solarium_Result_Select_Component
*/
public
function
getComponent
(
$key
)
{
if
(
isset
(
$this
->
_components
[
$key
]))
{
return
$this
->
_components
[
$key
];
}
else
{
return
null
;
}
}
/**
* Get morelikethis component result
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Result_Select_Component_MoreLikeThis
*/
public
function
getMoreLikeThis
()
{
return
$this
->
getComponent
(
Solarium_Query_Select_Component
::
MORELIKETHIS
);
}
}
}
\ No newline at end of file
library/Solarium/Result/Select/MoreLikeThis.php
0 → 100644
View file @
31dc7f69
<?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
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component morelikethis result
*
* @package Solarium
* @subpackage Result
*/
class
Solarium_Result_Select_MoreLikeThis
implements
IteratorAggregate
,
Countable
{
/**
* Result array
*
* @var array
*/
protected
$_results
;
/**
* Constructor
*
* @param array $results
* @return void
*/
public
function
__construct
(
$results
)
{
$this
->
_results
=
$results
;
}
/**
* Get a result by key
*
* @param mixed $key
* @return Solarium_Result_Select_MoreLikeThis_Result|null
*/
public
function
getResult
(
$key
)
{
if
(
isset
(
$this
->
_results
[
$key
]))
{
return
$this
->
_results
[
$key
];
}
else
{
return
null
;
}
}
/**
* Get all results
*
* @return array
*/
public
function
getResults
()
{
return
$this
->
_results
;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public
function
getIterator
()
{
return
new
ArrayIterator
(
$this
->
_results
);
}
/**
* Countable implementation
*
* @return int
*/
public
function
count
()
{
return
count
(
$this
->
_results
);
}
}
\ No newline at end of file
library/Solarium/Result/Select/MoreLikeThis/Result.php
0 → 100644
View file @
31dc7f69
<?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
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component morelikethis result item
*
* @package Solarium
* @subpackage Result
*/
class
Solarium_Result_Select_MoreLikeThis_Result
implements
IteratorAggregate
,
Countable
{
/**
* Document instances array
*
* @var array
*/
protected
$_documents
;
/**
* Solr numFound
*
* This is NOT the number of MLT documents fetched from Solr!
*
* @var int
*/
protected
$_numFound
;
/**
* Maximum score in this MLT set
*
* @var float
*/
protected
$_maximumScore
;
/**
* Constructor
*
* @param int $numFound
* @param float $maxScore
* @param array $documents
* @return void
*/
public
function
__construct
(
$numFound
,
$maxScore
,
$documents
)
{
$this
->
_numFound
=
$numFound
;
$this
->
_maximumScore
=
$maxScore
;
$this
->
_documents
=
$documents
;
}
/**
* get Solr numFound
*
* Returns the number of MLT documents found by Solr (this is NOT the
* number of documents fetched from Solr!)
*
* @return int
*/
public
function
getNumFound
()
{
return
$this
->
_numFound
;
}
/**
* Get maximum score in the MLT document set
*
* @return float
*/
public
function
getMaximumScore
()
{
return
$this
->
_maximumScore
;
}
/**
* Get all documents
*
* @return array
*/
public
function
getDocuments
()
{
return
$this
->
_documents
;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public
function
getIterator
()
{
return
new
ArrayIterator
(
$this
->
_documents
);
}
/**
* Countable implementation
*
* @return int
*/
public
function
count
()
{
return
count
(
$this
->
_documents
);
}
}
\ No newline at end of file
tests/Solarium/Client/Request/SelectTest.php
View file @
31dc7f69
...
@@ -32,6 +32,9 @@
...
@@ -32,6 +32,9 @@
class
Solarium_Client_Request_SelectTest
extends
PHPUnit_Framework_TestCase
class
Solarium_Client_Request_SelectTest
extends
PHPUnit_Framework_TestCase
{
{
/**
* @var Solarium_Query_Select
*/
protected
$_query
;
protected
$_query
;
protected
$_options
=
array
(
protected
$_options
=
array
(
...
@@ -130,6 +133,34 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
...
@@ -130,6 +133,34 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
$request
=
new
Solarium_Client_Request_Select
(
$this
->
_options
,
$this
->
_query
);
$request
=
new
Solarium_Client_Request_Select
(
$this
->
_options
,
$this
->
_query
);
$request
->
getUri
();
$request
->
getUri
();
}
}
public
function
testSelectUrlWithMoreLikeThis
()
{
$mlt
=
$this
->
_query
->
getMoreLikeThis
();
$mlt
->
setFields
(
'description,name'
);
$mlt
->
setMinimumTermFrequency
(
1
);
$mlt
->
setMinimumDocumentFrequency
(
3
);
$mlt
->
setMinimumWordLength
(
2
);
$mlt
->
setMaximumWordLength
(
15
);
$mlt
->
setMaximumQueryTerms
(
4
);
$mlt
->
setMaximumNumberOfTokens
(
5
);
$mlt
->
setBoost
(
true
);
$mlt
->
setQueryFields
(
'description'
);
$mlt
->
setCount
(
6
);
$request
=
new
Solarium_Client_Request_Select
(
$this
->
_options
,
$this
->
_query
);
$this
->
assertEquals
(
null
,
$request
->
getRawData
()
);
$this
->
assertEquals
(
'http://127.0.0.1:80/solr/select?q=*:*&start=0&rows=10&fl=*,score&wt=json&mlt=true&mlt.fl=description,name&mlt.mintf=1&mlt.mindf=3&mlt.minwl=2&mlt.maxwl=15&mlt.maxqt=4&mlt.maxntp=5&mlt.boost=1&mlt.qf=description&mlt.count=6'
,
urldecode
(
$request
->
getUri
())
);
}
}
}
class
UnknownFacet
extends
Solarium_Query_Select_Facet_Field
{
class
UnknownFacet
extends
Solarium_Query_Select_Facet_Field
{
...
...
tests/Solarium/Query/Select/Component/MoreLikeThisTest.php
0 → 100644
View file @
31dc7f69
<?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.
*/
class
Solarium_Query_Select_Component_moreLikeThisTest
extends
PHPUnit_Framework_TestCase
{
protected
$_mlt
;
public
function
setUp
()
{
$this
->
_mlt
=
new
Solarium_Query_Select_Component_MoreLikeThis
;
}
public
function
testSetAndGetFields
()
{
$value
=
'name,description'
;
$this
->
_mlt
->
setFields
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_mlt
->
getFields
()
);
}
public
function
testSetAndGetMinimumTermFrequency
()
{
$value
=
2
;
$this
->
_mlt
->
setMinimumTermFrequency
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_mlt
->
getMinimumTermFrequency
()
);
}
public
function
testMinimumDocumentFrequency
()
{
$value
=
4
;
$this
->
_mlt
->
setMinimumDocumentFrequency
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_mlt
->
getMinimumDocumentFrequency
()
);
}
public
function
testSetAndGetMinimumWordLength
()
{
$value
=
3
;
$this
->
_mlt
->
setMinimumWordLength
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_mlt
->
getMinimumWordLength
()
);
}
public
function
testSetAndGetMaximumWordLength
()
{
$value
=
15
;
$this
->
_mlt
->
setMaximumWordLength
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_mlt
->
getMaximumWordLength
()
);
}
public
function
testSetAndGetMaximumQueryTerms
()
{
$value
=
5
;
$this
->
_mlt
->
setMaximumQueryTerms
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_mlt
->
getMaximumQueryTerms
()
);
}
public
function
testSetAndGetMaximumNumberOfTokens
()
{
$value
=
5
;
$this
->
_mlt
->
setMaximumNumberOfTokens
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_mlt
->
getMaximumNumberOfTokens
()
);
}
public
function
testSetAndGetBoost
()
{
$value
=
true
;
$this
->
_mlt
->
setBoost
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_mlt
->
getBoost
()
);
}
public
function
testSetAndGetQueryFields
()
{
$value
=
'content,name'
;
$this
->
_mlt
->
setQueryFields
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_mlt
->
getQueryFields
()
);
}
public
function
testSetAndGetCount
()
{
$value
=
8
;
$this
->
_mlt
->
setCount
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_mlt
->
getCount
()
);
}
}
tests/Solarium/Query/Select/ComponentTest.php
0 → 100644
View file @
31dc7f69
<?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.
*/
class
Solarium_Query_Select_ComponentTest
extends
PHPUnit_Framework_TestCase
{
public
function
testGetType
()
{
$component
=
new
TestComponent
();
$this
->
assertEquals
(
'testtype'
,
$component
->
getType
());
}
}
class
TestComponent
extends
Solarium_Query_Select_Component
{
protected
$_type
=
'testtype'
;
}
\ No newline at end of file
tests/Solarium/Query/SelectTest.php
View file @
31dc7f69
...
@@ -541,4 +541,62 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
...
@@ -541,4 +541,62 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
$facets
[
'category13'
]
->
getQuery
()
$facets
[
'category13'
]
->
getQuery
()
);
);
}
}
}
public
function
testSetAndGetComponents
()
{
$mlt
=
new
Solarium_Query_Select_Component_MoreLikeThis
;
$this
->
_query
->
setComponent
(
'mlt'
,
$mlt
);
$this
->
assertEquals
(
array
(
'mlt'
=>
$mlt
),
$this
->
_query
->
getComponents
()
);
}
public
function
testSetAndGetComponent
()
{
$mlt
=
new
Solarium_Query_Select_Component_MoreLikeThis
;
$this
->
_query
->
setComponent
(
'mlt'
,
$mlt
);
$this
->
assertEquals
(
$mlt
,
$this
->
_query
->
getComponent
(
'mlt'
)
);
}
public
function
testGetInvalidComponent
()
{
$this
->
assertEquals
(
null
,
$this
->
_query
->
getComponent
(
'invalid'
)
);
}
public
function
testRemoveComponent
()
{
$mlt
=
new
Solarium_Query_Select_Component_MoreLikeThis
;
$this
->
_query
->
setComponent
(
'mlt'
,
$mlt
);
$this
->
assertEquals
(
array
(
'mlt'
=>
$mlt
),
$this
->
_query
->
getComponents
()
);
$this
->
_query
->
removeComponent
(
'mlt'
);
$this
->
assertEquals
(
array
(),
$this
->
_query
->
getComponents
()
);
}
public
function
testGetMoreLikeThis
()
{
$mlt
=
$this
->
_query
->
getMoreLikeThis
();
$this
->
assertEquals
(
'Solarium_Query_Select_Component_MoreLikeThis'
,
get_class
(
$mlt
)
);
}
}
\ No newline at end of file
tests/Solarium/Result/Select/MoreLikeThis/ResultTest.php
0 → 100644
View file @
31dc7f69
<?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.
*/
class
Solarium_Result_Select_MoreLikeThis_ResultTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_MoreLikeThis_Result
*/
protected
$_mltResult
;
public
function
setUp
()
{
$this
->
_docs
=
array
(
new
Solarium_Document_ReadOnly
(
array
(
'id'
=>
1
,
'name'
=>
'test1'
)),
new
Solarium_Document_ReadOnly
(
array
(
'id'
=>
2
,
'name'
=>
'test2'
)),
);
$this
->
_mltResult
=
new
Solarium_Result_Select_MoreLikeThis_Result
(
2
,
5.13
,
$this
->
_docs
);
}
public
function
testGetNumFound
()
{
$this
->
assertEquals
(
2
,
$this
->
_mltResult
->
getNumFound
());
}
public
function
testGetMaximumScore
()
{
$this
->
assertEquals
(
5.13
,
$this
->
_mltResult
->
getMaximumScore
());
}
public
function
testGetDocuments
()
{
$this
->
assertEquals
(
$this
->
_docs
,
$this
->
_mltResult
->
getDocuments
());
}
public
function
testIterator
()
{
$docs
=
array
();
foreach
(
$this
->
_mltResult
AS
$key
=>
$doc
)
{
$docs
[
$key
]
=
$doc
;
}
$this
->
assertEquals
(
$this
->
_docs
,
$docs
);
}
public
function
testCount
()
{
$this
->
assertEquals
(
count
(
$this
->
_docs
),
count
(
$this
->
_mltResult
));
}
}
tests/Solarium/Result/Select/MoreLikeThisTest.php
0 → 100644
View file @
31dc7f69
<?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.
*/
class
Solarium_Result_Select_MoreLikeThisTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_MoreLikeThis
*/
protected
$_mlt
;
protected
$_results
;
public
function
setUp
()
{
$docs
=
array
(
new
Solarium_Document_ReadOnly
(
array
(
'id'
=>
1
,
'name'
=>
'test1'
)),
new
Solarium_Document_ReadOnly
(
array
(
'id'
=>
2
,
'name'
=>
'test2'
)),
);
$this
->
_results
=
array
(
'key1'
=>
new
Solarium_Result_Select_MoreLikeThis_Result
(
2
,
5.13
,
$docs
),
'key2'
=>
new
Solarium_Result_Select_MoreLikeThis_Result
(
2
,
2.3
,
$docs
),
);
$this
->
_mlt
=
new
Solarium_Result_Select_MoreLikeThis
(
$this
->
_results
);
}
public
function
testGetResults
()
{
$this
->
assertEquals
(
$this
->
_results
,
$this
->
_mlt
->
getResults
());
}
public
function
testGetResult
()
{
$this
->
assertEquals
(
$this
->
_results
[
'key1'
],
$this
->
_mlt
->
getResult
(
'key1'
)
);
}
public
function
testGetInvalidResult
()
{
$this
->
assertEquals
(
null
,
$this
->
_mlt
->
getResult
(
'invalid'
)
);
}
public
function
testIterator
()
{
$items
=
array
();
foreach
(
$this
->
_mlt
AS
$key
=>
$item
)
{
$items
[
$key
]
=
$item
;
}
$this
->
assertEquals
(
$this
->
_results
,
$items
);
}
public
function
testCount
()
{
$this
->
assertEquals
(
count
(
$this
->
_results
),
count
(
$this
->
_mlt
));
}
}
tests/Solarium/Result/SelectTest.php
View file @
31dc7f69
...
@@ -47,7 +47,11 @@ class Solarium_Result_SelectTest extends Solarium_Result_QueryTest
...
@@ -47,7 +47,11 @@ class Solarium_Result_SelectTest extends Solarium_Result_QueryTest
'f2'
=>
new
Solarium_Result_Select_Facet_Field
(
array
(
'b'
=>
5
)),
'f2'
=>
new
Solarium_Result_Select_Facet_Field
(
array
(
'b'
=>
5
)),
);
);
$this
->
_result
=
new
Solarium_Result_Select
(
0
,
45
,
100
,
$this
->
_docs
,
$this
->
_facets
);
$this
->
_components
=
array
(
Solarium_Query_Select_Component
::
MORELIKETHIS
=>
new
Solarium_Result_Select_MoreLikeThis
(
array
())
);
$this
->
_result
=
new
Solarium_Result_Select
(
0
,
45
,
100
,
$this
->
_docs
,
$this
->
_facets
,
$this
->
_components
);
}
}
public
function
testGetNumFound
()
public
function
testGetNumFound
()
...
@@ -80,6 +84,35 @@ class Solarium_Result_SelectTest extends Solarium_Result_QueryTest
...
@@ -80,6 +84,35 @@ class Solarium_Result_SelectTest extends Solarium_Result_QueryTest
$this
->
assertEquals
(
3
,
count
(
$this
->
_result
));
$this
->
assertEquals
(
3
,
count
(
$this
->
_result
));
}
}
public
function
testGetComponents
()
{
$this
->
assertEquals
(
$this
->
_components
,
$this
->
_result
->
getComponents
());
}
public
function
testGetComponent
()
{
$this
->
assertEquals
(
$this
->
_components
[
Solarium_Query_Select_Component
::
MORELIKETHIS
],
$this
->
_result
->
getComponent
(
Solarium_Query_Select_Component
::
MORELIKETHIS
)
);
}
public
function
testGetInvalidComponent
()
{
$this
->
assertEquals
(
null
,
$this
->
_result
->
getComponent
(
'invalid'
)
);
}
public
function
testGetMoreLikeThis
()
{
$this
->
assertEquals
(
$this
->
_components
[
Solarium_Query_Select_Component
::
MORELIKETHIS
],
$this
->
_result
->
getMoreLikeThis
()
);
}
public
function
testIterator
()
public
function
testIterator
()
{
{
$docs
=
array
();
$docs
=
array
();
...
@@ -90,5 +123,5 @@ class Solarium_Result_SelectTest extends Solarium_Result_QueryTest
...
@@ -90,5 +123,5 @@ class Solarium_Result_SelectTest extends Solarium_Result_QueryTest
$this
->
assertEquals
(
$this
->
_docs
,
$docs
);
$this
->
assertEquals
(
$this
->
_docs
,
$docs
);
}
}
}
}
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