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
c620d93b
Unverified
Commit
c620d93b
authored
Jan 05, 2018
by
Markus Kalkbrenner
Committed by
GitHub
Jan 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
completed sugester component and improved tests (#542)
parent
84b4ed17
Changes
19
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
680 additions
and
19 deletions
+680
-19
library/Component/RequestBuilder/Suggester.php
library/Component/RequestBuilder/Suggester.php
+67
-0
library/Component/ResponseParser/Spellcheck.php
library/Component/ResponseParser/Spellcheck.php
+3
-4
library/Component/ResponseParser/Suggester.php
library/Component/ResponseParser/Suggester.php
+98
-0
library/Component/Result/Suggester/Result.php
library/Component/Result/Suggester/Result.php
+94
-0
library/Component/Suggester.php
library/Component/Suggester.php
+2
-2
tests/Component/DebugTest.php
tests/Component/DebugTest.php
+3
-2
tests/Component/MoreLikeThisTest.php
tests/Component/MoreLikeThisTest.php
+3
-2
tests/Component/RequestBuilder/DebugTest.php
tests/Component/RequestBuilder/DebugTest.php
+1
-1
tests/Component/RequestBuilder/MoreLikeThisTest.php
tests/Component/RequestBuilder/MoreLikeThisTest.php
+1
-1
tests/Component/RequestBuilder/SpellcheckTest.php
tests/Component/RequestBuilder/SpellcheckTest.php
+1
-1
tests/Component/RequestBuilder/SuggesterTest.php
tests/Component/RequestBuilder/SuggesterTest.php
+68
-0
tests/Component/ResponseParser/DebugTest.php
tests/Component/ResponseParser/DebugTest.php
+1
-1
tests/Component/ResponseParser/MoreLikeThisTest.php
tests/Component/ResponseParser/MoreLikeThisTest.php
+1
-1
tests/Component/ResponseParser/SpellcheckTest.php
tests/Component/ResponseParser/SpellcheckTest.php
+1
-1
tests/Component/ResponseParser/SuggesterTest.php
tests/Component/ResponseParser/SuggesterTest.php
+131
-0
tests/Component/Result/Suggester/ResultTest.php
tests/Component/Result/Suggester/ResultTest.php
+57
-0
tests/Component/SpatialTest.php
tests/Component/SpatialTest.php
+1
-1
tests/Component/SpellcheckTest.php
tests/Component/SpellcheckTest.php
+3
-2
tests/Component/SuggesterTest.php
tests/Component/SuggesterTest.php
+144
-0
No files found.
library/Component/RequestBuilder/Suggester.php
0 → 100644
View file @
c620d93b
<?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
Solarium\Component\RequestBuilder
;
use
Solarium\Component\Suggester
as
SuggesterComponent
;
use
Solarium\Core\Client\Request
;
/**
* Add select component Spellcheck to the request.
*/
class
Suggester
implements
ComponentRequestBuilderInterface
{
/**
* Add request settings for Spellcheck.
*
* @param SuggesterComponent $component
* @param Request $request
*
* @return Request
*/
public
function
buildComponent
(
$component
,
$request
)
{
$request
->
addParam
(
'suggest'
,
'true'
);
$request
->
addParam
(
'suggest.dictionary'
,
$component
->
getDictionary
());
$request
->
addParam
(
'suggest.q'
,
$component
->
getQuery
());
$request
->
addParam
(
'suggest.count'
,
$component
->
getCount
());
$request
->
addParam
(
'suggest.cfq'
,
$component
->
getContextFilterQuery
());
$request
->
addParam
(
'suggest.build'
,
$component
->
getBuild
());
$request
->
addParam
(
'suggest.reload'
,
$component
->
getReload
());
return
$request
;
}
}
library/Component/ResponseParser/Spellcheck.php
View file @
c620d93b
...
@@ -42,7 +42,6 @@ namespace Solarium\Component\ResponseParser;
...
@@ -42,7 +42,6 @@ namespace Solarium\Component\ResponseParser;
use
Solarium\Core\Query\AbstractQuery
;
use
Solarium\Core\Query\AbstractQuery
;
use
Solarium\Component\Spellcheck
as
SpellcheckComponent
;
use
Solarium\Component\Spellcheck
as
SpellcheckComponent
;
use
Solarium\Component\Result\Spellcheck
as
SpellcheckResult
;
use
Solarium\Component\Result\Spellcheck\Result
;
use
Solarium\Component\Result\Spellcheck\Result
;
use
Solarium\Component\Result\Spellcheck\Collation
;
use
Solarium\Component\Result\Spellcheck\Collation
;
use
Solarium\Component\Result\Spellcheck\Suggestion
;
use
Solarium\Component\Result\Spellcheck\Suggestion
;
...
@@ -114,10 +113,10 @@ class Spellcheck extends ResponseParserAbstract implements ComponentParserInterf
...
@@ -114,10 +113,10 @@ class Spellcheck extends ResponseParserAbstract implements ComponentParserInterf
$correctlySpelled
=
$data
[
'spellcheck'
][
'correctlySpelled'
];
$correctlySpelled
=
$data
[
'spellcheck'
][
'correctlySpelled'
];
}
}
return
new
SpellcheckResult\Result
(
$suggestions
,
$collations
,
$correctlySpelled
);
return
new
Result
(
$suggestions
,
$collations
,
$correctlySpelled
);
}
else
{
return
;
}
}
return
null
;
}
}
/**
/**
...
...
library/Component/ResponseParser/Suggester.php
0 → 100644
View file @
c620d93b
<?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\Component\ResponseParser
;
use
Solarium\Core\Query\AbstractQuery
;
use
Solarium\Component\Suggester
as
SuggesterComponent
;
use
Solarium\Component\Result\Suggester\Result
;
use
Solarium\Core\Query\AbstractResponseParser
;
use
Solarium\QueryType\Suggester\Result\Dictionary
;
use
Solarium\QueryType\Suggester\Result\Term
;
/**
* Parse select component Highlighting result from the data.
*/
class
Suggester
extends
AbstractResponseParser
implements
ComponentParserInterface
{
/**
* Parse result data into result objects.
*
* @param AbstractQuery $query
* @param SuggesterComponent $suggester
* @param array $data
*
* @return Result|null
*/
public
function
parse
(
$query
,
$suggester
,
$data
)
{
$dictionaries
=
[];
$allSuggestions
=
[];
if
(
isset
(
$data
[
'suggest'
])
&&
is_array
(
$data
[
'suggest'
]))
{
foreach
(
$data
[
'suggest'
]
as
$dictionary
=>
$dictionaryResults
)
{
$terms
=
[];
foreach
(
$dictionaryResults
as
$term
=>
$termData
)
{
$allSuggestions
[]
=
$this
->
createTerm
(
$termData
);
$terms
[
$term
]
=
$this
->
createTerm
(
$termData
);
}
$dictionaries
[
$dictionary
]
=
$this
->
createDictionary
(
$terms
);
}
return
new
Result
(
$dictionaries
,
$allSuggestions
);
}
return
null
;
}
private
function
createDictionary
(
array
$terms
)
{
return
new
Dictionary
(
$terms
);
}
private
function
createTerm
(
array
$termData
)
{
return
new
Term
(
$termData
[
'numFound'
],
$termData
[
'suggestions'
]
);
}
}
library/Component/Result/Suggester/Result.php
0 → 100644
View file @
c620d93b
<?php
namespace
Solarium\Component\Result\Suggester
;
use
Solarium\QueryType\Suggester\Result\Dictionary
;
/**
* Component suggester result.
*/
class
Result
implements
\IteratorAggregate
,
\Countable
{
/**
* Suggester results.
*
* @var array
*/
protected
$results
;
/**
* Suggester flat results.
*
* @var array
*/
protected
$all
;
/**
* Constructor.
*
* @param array $results
* @param array $all
*/
public
function
__construct
(
$results
,
$all
)
{
$this
->
results
=
$results
;
$this
->
all
=
$all
;
}
/**
* Get all results.
*
* @return array
*/
public
function
getResults
()
{
return
$this
->
results
;
}
/**
* Get flat results.
*
* @return array
*/
public
function
getAll
()
{
return
$this
->
all
;
}
/**
* Get results for a specific dictionary.
*
* @param string $dictionary
*
* @return Dictionary|null
*/
public
function
getDictionary
(
$dictionary
)
{
if
(
isset
(
$this
->
results
[
$dictionary
]))
{
return
$this
->
results
[
$dictionary
];
}
else
{
return
null
;
}
}
/**
* IteratorAggregate implementation.
*
* @return \ArrayIterator
*/
public
function
getIterator
()
{
return
new
\ArrayIterator
(
$this
->
results
);
}
/**
* Countable implementation.
*
* @return int
*/
public
function
count
()
{
return
count
(
$this
->
results
);
}
}
library/Component/Suggester.php
View file @
c620d93b
...
@@ -40,8 +40,8 @@
...
@@ -40,8 +40,8 @@
namespace
Solarium\Component
;
namespace
Solarium\Component
;
use
Solarium\Component\RequestBuilder\S
pellcheck
as
RequestBuilder
;
use
Solarium\Component\RequestBuilder\S
uggester
as
RequestBuilder
;
use
Solarium\Component\ResponseParser\S
pellcheck
as
ResponseParser
;
use
Solarium\Component\ResponseParser\S
uggester
as
ResponseParser
;
use
Solarium\QueryType\Suggester\QueryTrait
;
use
Solarium\QueryType\Suggester\QueryTrait
;
/**
/**
...
...
tests/
QueryType/Select/Query/
Component/DebugTest.php
→
tests/Component/DebugTest.php
View file @
c620d93b
...
@@ -29,8 +29,9 @@
...
@@ -29,8 +29,9 @@
* policies, either expressed or implied, of the copyright holder.
* policies, either expressed or implied, of the copyright holder.
*/
*/
namespace
Solarium\Tests\
QueryType\Select\Query\
Component
;
namespace
Solarium\Tests\Component
;
use
Solarium\Component\AbstractComponentAwareQuery
;
use
Solarium\Component\Debug
;
use
Solarium\Component\Debug
;
use
Solarium\QueryType\Select\Query\Query
;
use
Solarium\QueryType\Select\Query\Query
;
...
@@ -60,7 +61,7 @@ class DebugTest extends \PHPUnit_Framework_TestCase
...
@@ -60,7 +61,7 @@ class DebugTest extends \PHPUnit_Framework_TestCase
public
function
testGetType
()
public
function
testGetType
()
{
{
$this
->
assertEquals
(
$this
->
assertEquals
(
Query
::
COMPONENT_DEBUG
,
AbstractComponentAware
Query
::
COMPONENT_DEBUG
,
$this
->
debug
->
getType
()
$this
->
debug
->
getType
()
);
);
}
}
...
...
tests/
QueryType/Select/Query/
Component/MoreLikeThisTest.php
→
tests/Component/MoreLikeThisTest.php
View file @
c620d93b
...
@@ -29,8 +29,9 @@
...
@@ -29,8 +29,9 @@
* policies, either expressed or implied, of the copyright holder.
* policies, either expressed or implied, of the copyright holder.
*/
*/
namespace
Solarium\Tests\
QueryType\Select\Query\
Component
;
namespace
Solarium\Tests\Component
;
use
Solarium\Component\AbstractComponentAwareQuery
;
use
Solarium\Component\MoreLikeThis
;
use
Solarium\Component\MoreLikeThis
;
use
Solarium\QueryType\Select\Query\Query
;
use
Solarium\QueryType\Select\Query\Query
;
...
@@ -76,7 +77,7 @@ class MoreLikeThisTest extends \PHPUnit_Framework_TestCase
...
@@ -76,7 +77,7 @@ class MoreLikeThisTest extends \PHPUnit_Framework_TestCase
public
function
testGetType
()
public
function
testGetType
()
{
{
$this
->
assertEquals
(
Query
::
COMPONENT_MORELIKETHIS
,
$this
->
mlt
->
getType
());
$this
->
assertEquals
(
AbstractComponentAware
Query
::
COMPONENT_MORELIKETHIS
,
$this
->
mlt
->
getType
());
}
}
public
function
testGetResponseParser
()
public
function
testGetResponseParser
()
...
...
tests/
QueryType/Select/RequestBuilder/Component
/DebugTest.php
→
tests/
Component/RequestBuilder
/DebugTest.php
View file @
c620d93b
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
* policies, either expressed or implied, of the copyright holder.
* policies, either expressed or implied, of the copyright holder.
*/
*/
namespace
Solarium\Tests\
QueryType\Select\RequestBuilder\Component
;
namespace
Solarium\Tests\
Component\RequestBuilder
;
use
Solarium\Component\RequestBuilder\Debug
as
RequestBuilder
;
use
Solarium\Component\RequestBuilder\Debug
as
RequestBuilder
;
use
Solarium\Component\Debug
as
Component
;
use
Solarium\Component\Debug
as
Component
;
...
...
tests/
QueryType/Select/RequestBuilder/Component
/MoreLikeThisTest.php
→
tests/
Component/RequestBuilder
/MoreLikeThisTest.php
View file @
c620d93b
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
* policies, either expressed or implied, of the copyright holder.
* policies, either expressed or implied, of the copyright holder.
*/
*/
namespace
Solarium\Tests\
QueryType\Select\RequestBuilder\Component
;
namespace
Solarium\Tests\
Component\RequestBuilder
;
use
Solarium\Component\RequestBuilder\MoreLikeThis
as
RequestBuilder
;
use
Solarium\Component\RequestBuilder\MoreLikeThis
as
RequestBuilder
;
use
Solarium\Component\MoreLikeThis
as
Component
;
use
Solarium\Component\MoreLikeThis
as
Component
;
...
...
tests/
QueryType/Select/RequestBuilder/Component
/SpellcheckTest.php
→
tests/
Component/RequestBuilder
/SpellcheckTest.php
View file @
c620d93b
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
* policies, either expressed or implied, of the copyright holder.
* policies, either expressed or implied, of the copyright holder.
*/
*/
namespace
Solarium\Tests\
QueryType\Select\RequestBuilder\Component
;
namespace
Solarium\Tests\
Component\RequestBuilder
;
use
Solarium\Component\RequestBuilder\Spellcheck
as
RequestBuilder
;
use
Solarium\Component\RequestBuilder\Spellcheck
as
RequestBuilder
;
use
Solarium\Component\Spellcheck
as
Component
;
use
Solarium\Component\Spellcheck
as
Component
;
...
...
tests/Component/RequestBuilder/SuggesterTest.php
0 → 100644
View file @
c620d93b
<?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.
*/
namespace
Solarium\Tests\Component\RequestBuilder
;
use
Solarium\Component\RequestBuilder\Suggester
as
RequestBuilder
;
use
Solarium\Component\Suggester
as
Component
;
use
Solarium\Core\Client\Request
;
class
SuggesterTest
extends
\PHPUnit_Framework_TestCase
{
public
function
testBuildComponent
()
{
$builder
=
new
RequestBuilder
();
$request
=
new
Request
();
$component
=
new
Component
();
$component
->
setDictionary
(
'suggest'
);
$component
->
setQuery
(
'ap ip'
);
$component
->
setCount
(
13
);
$component
->
setContextFilterQuery
(
'foo bar'
);
$component
->
setBuild
(
'true'
);
$component
->
setReload
(
'false'
);
$request
=
$builder
->
buildComponent
(
$component
,
$request
);
$this
->
assertEquals
(
array
(
'suggest'
=>
'true'
,
'suggest.dictionary'
=>
'suggest'
,
'suggest.q'
=>
'ap ip'
,
'suggest.count'
=>
13
,
'suggest.cfq'
=>
'foo bar'
,
'suggest.build'
=>
'true'
,
'suggest.reload'
=>
'false'
,
),
$request
->
getParams
()
);
}
}
tests/
QueryType/Select/ResponseParser/Component
/DebugTest.php
→
tests/
Component/ResponseParser
/DebugTest.php
View file @
c620d93b
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
* policies, either expressed or implied, of the copyright holder.
* policies, either expressed or implied, of the copyright holder.
*/
*/
namespace
Solarium\Tests\
QueryType\Select\ResponseParser\Component
;
namespace
Solarium\Tests\
Component\ResponseParser
;
use
Solarium\Component\ResponseParser\Debug
as
Parser
;
use
Solarium\Component\ResponseParser\Debug
as
Parser
;
use
Solarium\Component\Result\Debug\Detail
;
use
Solarium\Component\Result\Debug\Detail
;
...
...
tests/
QueryType/Select/ResponseParser/Component
/MoreLikeThisTest.php
→
tests/
Component/ResponseParser
/MoreLikeThisTest.php
View file @
c620d93b
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
* policies, either expressed or implied, of the copyright holder.
* policies, either expressed or implied, of the copyright holder.
*/
*/
namespace
Solarium\Tests\
QueryType\Select\ResponseParser\Component
;
namespace
Solarium\Tests\
Component\ResponseParser
;
use
Solarium\Component\ResponseParser\MoreLikeThis
as
Parser
;
use
Solarium\Component\ResponseParser\MoreLikeThis
as
Parser
;
use
Solarium\QueryType\Select\Query\Query
;
use
Solarium\QueryType\Select\Query\Query
;
...
...
tests/
QueryType/Select/ResponseParser/Component
/SpellcheckTest.php
→
tests/
Component/ResponseParser
/SpellcheckTest.php
View file @
c620d93b
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
* policies, either expressed or implied, of the copyright holder.
* policies, either expressed or implied, of the copyright holder.
*/
*/
namespace
Solarium\Tests\
QueryType\Select\ResponseParser\Component
;
namespace
Solarium\Tests\
Component\ResponseParser
;
use
Solarium\Component\ResponseParser\Spellcheck
as
Parser
;
use
Solarium\Component\ResponseParser\Spellcheck
as
Parser
;
use
Solarium\QueryType\Select\Query\Query
;
use
Solarium\QueryType\Select\Query\Query
;
...
...
tests/Component/ResponseParser/SuggesterTest.php
0 → 100644
View file @
c620d93b
<?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.
*/
namespace
Solarium\Tests\Component\ResponseParser
;
use
Solarium\Component\ResponseParser\Suggester
;
use
Solarium\QueryType\Select\Query\Query
;
use
Solarium\QueryType\Suggester\Result\Dictionary
;
use
Solarium\QueryType\Suggester\Result\Term
;
class
SuggesterTest
extends
\PHPUnit_Framework_TestCase
{
protected
$parser
;
protected
$query
;
public
function
setUp
()
{
$this
->
query
=
new
Query
();
$this
->
parser
=
new
Suggester
();
}
/**
* @dataProvider providerParse
*/
public
function
testParse
(
$data
)
{
$result
=
$this
->
parser
->
parse
(
$this
->
query
,
null
,
$data
);
$expected
=
new
Dictionary
([
'foo'
=>
new
Term
(
2
,
[[
'term'
=>
'foo'
],
[
'term'
=>
'foobar'
]]),
'zoo'
=>
new
Term
(
1
,
[[
'term'
=>
'zoo keeper'
]]),
]);
$this
->
assertEquals
(
$expected
,
$result
->
getDictionary
(
'dictionary1'
));
$expected
=
new
Dictionary
([
'free'
=>
new
Term
(
2
,
[[
'term'
=>
'free beer'
],
[
'term'
=>
'free software'
]]),
]);
$this
->
assertEquals
(
$expected
,
$result
->
getDictionary
(
'dictionary2'
));
$allExpected
=
array
(
new
Term
(
2
,
[[
'term'
=>
'foo'
],
[
'term'
=>
'foobar'
]]),
new
Term
(
1
,
[[
'term'
=>
'zoo keeper'
]]),
new
Term
(
2
,
[[
'term'
=>
'free beer'
],
[
'term'
=>
'free software'
]]),
);
$this
->
assertEquals
(
$allExpected
,
$result
->
getAll
());
}
public
function
providerParse
()
{
return
array
(
0
=>
array
(
'data'
=>
array
(
'suggest'
=>
array
(
'dictionary1'
=>
array
(
'foo'
=>
array
(
'numFound'
=>
2
,
'suggestions'
=>
array
(
array
(
'term'
=>
'foo'
,
),
array
(
'term'
=>
'foobar'
,
),
),
),
'zoo'
=>
array
(
'numFound'
=>
1
,
'suggestions'
=>
array
(
array
(
'term'
=>
'zoo keeper'
,
),
),
),
),
'dictionary2'
=>
array
(
'free'
=>
array
(
'numFound'
=>
2
,
'suggestions'
=>
array
(
array
(
'term'
=>
'free beer'
,
),
array
(
'term'
=>
'free software'
,
),
),
),
),
),
),
),
);
}
public
function
testParseNoData
()
{
$result
=
$this
->
parser
->
parse
(
$this
->
query
,
null
,
array
());
$this
->
assertEquals
(
null
,
$result
);
}
}
tests/Component/Result/Suggester/ResultTest.php
0 → 100644
View file @
c620d93b
<?php
namespace
Solarium\Tests\Component\Result\Suggester
;
use
Solarium\Component\Result\Suggester\Result
;
use
Solarium\QueryType\Suggester\Result\Dictionary
;
use
Solarium\QueryType\Suggester\Result\Term
;
class
ResultTest
extends
\PHPUnit_Framework_TestCase
{
/**
* @var Result
*/
protected
$result
;
public
function
setUp
()
{
$this
->
docs
=
array
(
'dictionary1'
=>
new
Dictionary
([
'foo'
=>
new
Term
(
2
,
[[
'term'
=>
'foo'
],
[
'term'
=>
'foobar'
]]),
'zoo'
=>
new
Term
(
1
,
[[
'term'
=>
'zoo keeper'
]]),
]),
'dictionary2'
=>
new
Dictionary
([
'free'
=>
new
Term
(
2
,
[[
'term'
=>
'free beer'
],
[
'term'
=>
'free software'
]]),
]),
);
$all
=
array
(
new
Term
(
2
,
[[
'term'
=>
'foo'
],
[
'term'
=>
'foobar'
]]),
new
Term
(
1
,
[[
'term'
=>
'zoo keeper'
]]),
new
Term
(
2
,
[[
'term'
=>
'free beer'
],
[
'term'
=>
'free software'
]]),
);
$this
->
result
=
new
Result
(
$this
->
docs
,
$all
);
}
public
function
testGetDictionary
()
{
$this
->
assertEquals
(
$this
->
docs
[
'dictionary1'
],
$this
->
result
->
getDictionary
(
'dictionary1'
));
}
public
function
testIterator
()
{
$docs
=
array
();
foreach
(
$this
->
result
as
$key
=>
$doc
)
{
$docs
[
$key
]
=
$doc
;
}
$this
->
assertEquals
(
$this
->
docs
,
$docs
);
}
public
function
testCount
()
{
$this
->
assertEquals
(
count
(
$this
->
docs
),
count
(
$this
->
result
));
}
}
tests/
QueryType/Select/Query/
Component/SpatialTest.php
→
tests/Component/SpatialTest.php
View file @
c620d93b
<?php
<?php
namespace
Solarium\Tests\
QueryType\Select\Query\
Component
;
namespace
Solarium\Tests\Component
;
use
Solarium\Component\Spatial
;
use
Solarium\Component\Spatial
;
use
Solarium\QueryType\Select\Query\Query
;
use
Solarium\QueryType\Select\Query\Query
;
...
...
tests/
QueryType/Select/Query/
Component/SpellcheckTest.php
→
tests/Component/SpellcheckTest.php
View file @
c620d93b
...
@@ -29,8 +29,9 @@
...
@@ -29,8 +29,9 @@
* policies, either expressed or implied, of the copyright holder.
* policies, either expressed or implied, of the copyright holder.
*/
*/
namespace
Solarium\Tests\
QueryType\Select\Query\
Component
;
namespace
Solarium\Tests\Component
;
use
Solarium\Component\AbstractComponentAwareQuery
;
use
Solarium\Component\Spellcheck
;
use
Solarium\Component\Spellcheck
;
use
Solarium\QueryType\Select\Query\Query
;
use
Solarium\QueryType\Select\Query\Query
;
...
@@ -49,7 +50,7 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
...
@@ -49,7 +50,7 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
public
function
testGetType
()
public
function
testGetType
()
{
{
$this
->
assertEquals
(
Query
::
COMPONENT_SPELLCHECK
,
$this
->
spellCheck
->
getType
());
$this
->
assertEquals
(
AbstractComponentAware
Query
::
COMPONENT_SPELLCHECK
,
$this
->
spellCheck
->
getType
());
}
}
public
function
testGetResponseParser
()
public
function
testGetResponseParser
()
...
...
tests/Component/SuggesterTest.php
0 → 100644
View file @
c620d93b
<?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.
*/
namespace
Solarium\Tests\Component
;
use
Solarium\Component\AbstractComponentAwareQuery
;
use
Solarium\Component\Suggester
;
use
Solarium\QueryType\Select\Query\Query
;
class
SuggesterTest
extends
\PHPUnit_Framework_TestCase
{
/**
* @var Spellcheck
*/
protected
$suggester
;
public
function
setUp
()
{
$this
->
suggester
=
new
Suggester
();
$this
->
suggester
->
setQueryInstance
(
new
Query
);
}
public
function
testGetType
()
{
$this
->
assertEquals
(
AbstractComponentAwareQuery
::
COMPONENT_SUGGESTER
,
$this
->
suggester
->
getType
());
}
public
function
testGetResponseParser
()
{
$this
->
assertInstanceOf
(
'Solarium\Component\ResponseParser\Suggester'
,
$this
->
suggester
->
getResponseParser
()
);
}
public
function
testGetRequestBuilder
()
{
$this
->
assertInstanceOf
(
'Solarium\Component\RequestBuilder\Suggester'
,
$this
->
suggester
->
getRequestBuilder
()
);
}
public
function
testSetAndGetQuery
()
{
$value
=
'testquery'
;
$this
->
suggester
->
setQuery
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
suggester
->
getQuery
()
);
}
public
function
testSetAndGetQueryWithBind
()
{
$this
->
suggester
->
setQuery
(
'id:%1%'
,
array
(
678
));
$this
->
assertEquals
(
'id:678'
,
$this
->
suggester
->
getQuery
());
}
public
function
testSetAndGetContextFilterQuery
()
{
$value
=
'context filter query'
;
$this
->
suggester
->
setContextFilterQuery
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
suggester
->
getContextFilterQuery
()
);
}
public
function
testSetAndGetBuild
()
{
$value
=
true
;
$this
->
suggester
->
setBuild
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
suggester
->
getBuild
()
);
}
public
function
testSetAndGetReload
()
{
$value
=
false
;
$this
->
suggester
->
setReload
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
suggester
->
getReload
()
);
}
public
function
testSetAndGetDictionary
()
{
$value
=
'myDictionary'
;
$this
->
suggester
->
setDictionary
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
suggester
->
getDictionary
()
);
}
public
function
testSetAndGetCount
()
{
$value
=
11
;
$this
->
suggester
->
setCount
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
suggester
->
getCount
()
);
}
}
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