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
edc49c22
Commit
edc49c22
authored
Aug 21, 2011
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- small bugfixes / improvements
- added unittests
parent
1d2a0deb
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
306 additions
and
2 deletions
+306
-2
library/Solarium/Query/MoreLikeThis.php
library/Solarium/Query/MoreLikeThis.php
+4
-2
library/Solarium/Result/MoreLikeThis.php
library/Solarium/Result/MoreLikeThis.php
+5
-0
tests/Solarium/ClientTest.php
tests/Solarium/ClientTest.php
+24
-0
tests/Solarium/Query/MoreLikeThisTest.php
tests/Solarium/Query/MoreLikeThisTest.php
+180
-0
tests/Solarium/Result/MoreLikeThisTest.php
tests/Solarium/Result/MoreLikeThisTest.php
+93
-0
No files found.
library/Solarium/Query/MoreLikeThis.php
View file @
edc49c22
...
...
@@ -131,11 +131,13 @@ class Solarium_Query_MoreLikeThis extends Solarium_Query_Select
* Set the match.include parameter, which is either 'true' or 'false'.
*
* @see http://wiki.apache.org/solr/MoreLikeThisHandler#Params
*
* @param boolean $include
* @return Solarium_Query_MoreLikeThis Provides fluent interface
*/
public
function
setMatchInclude
(
)
public
function
setMatchInclude
(
$include
)
{
return
$this
->
_setOption
(
'matchinclude'
,
'true'
);
return
$this
->
_setOption
(
'matchinclude'
,
$include
);
}
/**
...
...
library/Solarium/Result/MoreLikeThis.php
View file @
edc49c22
...
...
@@ -64,6 +64,11 @@ class Solarium_Result_MoreLikeThis extends Solarium_Result_Select
*/
protected
$_interestingTerms
;
/**
* MLT match document
*/
protected
$_match
;
/**
* Get MLT interesting terms
*
...
...
tests/Solarium/ClientTest.php
View file @
edc49c22
...
...
@@ -605,6 +605,18 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
$observer
->
update
(
$query
);
}
public
function
testMoreLikeThis
()
{
$query
=
new
Solarium_Query_MoreLikeThis
();
$observer
=
$this
->
getMock
(
'Solarium_Client'
,
array
(
'execute'
));
$observer
->
expects
(
$this
->
once
())
->
method
(
'execute'
)
->
with
(
$this
->
equalTo
(
$query
));
$observer
->
moreLikeThis
(
$query
);
}
public
function
testCreateQuery
()
{
$options
=
array
(
'optionA'
=>
1
,
'optionB'
=>
2
);
...
...
@@ -713,6 +725,18 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
$observer
->
createPing
(
$options
);
}
public
function
testCreateMoreLikeThis
()
{
$options
=
array
(
'optionA'
=>
1
,
'optionB'
=>
2
);
$observer
=
$this
->
getMock
(
'Solarium_Client'
,
array
(
'createQuery'
));
$observer
->
expects
(
$this
->
once
())
->
method
(
'createQuery'
)
->
with
(
$this
->
equalTo
(
Solarium_Client
::
QUERYTYPE_MORELIKETHIS
),
$this
->
equalTo
(
$options
));
$observer
->
createMoreLikeThis
(
$options
);
}
}
class
MyAdapter
extends
Solarium_Client_Adapter_Http
{
...
...
tests/Solarium/Query/MoreLikeThisTest.php
0 → 100644
View file @
edc49c22
<?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_MoreLikeThisTest
extends
Solarium_Query_SelectTest
{
protected
$_query
;
public
function
setUp
()
{
$this
->
_query
=
new
Solarium_Query_MoreLikeThis
;
}
public
function
testGetType
()
{
$this
->
assertEquals
(
Solarium_Client
::
QUERYTYPE_MORELIKETHIS
,
$this
->
_query
->
getType
());
}
public
function
testSetAndGetMatchInclude
()
{
$value
=
true
;
$this
->
_query
->
setMatchInclude
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_query
->
getMatchInclude
()
);
}
public
function
testSetAndGetMltFields
()
{
$value
=
'name,description'
;
$this
->
_query
->
setMltFields
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_query
->
getMltFields
()
);
}
public
function
testSetAndGetInterestingTerms
()
{
$value
=
'test'
;
$this
->
_query
->
setInterestingTerms
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_query
->
getInterestingTerms
()
);
}
public
function
testSetAndGetQueryStream
()
{
$value
=
true
;
$this
->
_query
->
setQueryStream
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_query
->
getQueryStream
()
);
}
public
function
testSetAndGetMinimumTermFrequency
()
{
$value
=
2
;
$this
->
_query
->
setMinimumTermFrequency
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_query
->
getMinimumTermFrequency
()
);
}
public
function
testMinimumDocumentFrequency
()
{
$value
=
4
;
$this
->
_query
->
setMinimumDocumentFrequency
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_query
->
getMinimumDocumentFrequency
()
);
}
public
function
testSetAndGetMinimumWordLength
()
{
$value
=
3
;
$this
->
_query
->
setMinimumWordLength
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_query
->
getMinimumWordLength
()
);
}
public
function
testSetAndGetMaximumWordLength
()
{
$value
=
15
;
$this
->
_query
->
setMaximumWordLength
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_query
->
getMaximumWordLength
()
);
}
public
function
testSetAndGetMaximumQueryTerms
()
{
$value
=
5
;
$this
->
_query
->
setMaximumQueryTerms
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_query
->
getMaximumQueryTerms
()
);
}
public
function
testSetAndGetMaximumNumberOfTokens
()
{
$value
=
5
;
$this
->
_query
->
setMaximumNumberOfTokens
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_query
->
getMaximumNumberOfTokens
()
);
}
public
function
testSetAndGetBoost
()
{
$value
=
true
;
$this
->
_query
->
setBoost
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_query
->
getBoost
()
);
}
public
function
testSetAndGetQueryFields
()
{
$value
=
'content,name'
;
$this
->
_query
->
setQueryFields
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_query
->
getQueryFields
()
);
}
}
\ No newline at end of file
tests/Solarium/Result/MoreLikeThisTest.php
0 → 100644
View file @
edc49c22
<?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_MoreLikeThisTest
extends
PHPUnit_Framework_TestCase
{
public
function
testGetInterestingTerms
()
{
$query
=
new
Solarium_Query_MoreLikeThis
();
$query
->
setInterestingTerms
(
'list'
);
$mock
=
$this
->
getMock
(
'Solarium_Result_MoreLikeThis'
,
array
(
'getQuery'
,
'_parseResponse'
),
array
(),
''
,
false
);
$mock
->
expects
(
$this
->
once
())
->
method
(
'getQuery'
)
->
will
(
$this
->
returnValue
(
$query
));
$mock
->
expects
(
$this
->
once
())
->
method
(
'_parseResponse'
);
$mock
->
getInterestingTerms
();
}
public
function
testGetInterestingTermsException
()
{
$query
=
new
Solarium_Query_MoreLikeThis
();
$query
->
setInterestingTerms
(
'none'
);
$mock
=
$this
->
getMock
(
'Solarium_Result_MoreLikeThis'
,
array
(
'getQuery'
),
array
(),
''
,
false
);
$mock
->
expects
(
$this
->
once
())
->
method
(
'getQuery'
)
->
will
(
$this
->
returnValue
(
$query
));
$this
->
setExpectedException
(
'Solarium_Exception'
);
$mock
->
getInterestingTerms
();
}
public
function
testGetMatch
()
{
$query
=
new
Solarium_Query_MoreLikeThis
();
$query
->
setMatchInclude
(
true
);
$mock
=
$this
->
getMock
(
'Solarium_Result_MoreLikeThis'
,
array
(
'getQuery'
,
'_parseResponse'
),
array
(),
''
,
false
);
$mock
->
expects
(
$this
->
once
())
->
method
(
'getQuery'
)
->
will
(
$this
->
returnValue
(
$query
));
$mock
->
expects
(
$this
->
once
())
->
method
(
'_parseResponse'
);
$mock
->
getMatch
();
}
public
function
testGetMatchException
()
{
$query
=
new
Solarium_Query_MoreLikeThis
();
$query
->
setMatchInclude
(
false
);
$mock
=
$this
->
getMock
(
'Solarium_Result_MoreLikeThis'
,
array
(
'getQuery'
),
array
(),
''
,
false
);
$mock
->
expects
(
$this
->
once
())
->
method
(
'getQuery'
)
->
will
(
$this
->
returnValue
(
$query
));
$this
->
setExpectedException
(
'Solarium_Exception'
);
$mock
->
getMatch
();
}
}
\ No newline at end of file
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