Commit 97b94e14 authored by Bas de Nooijer's avatar Bas de Nooijer

Merge commit 'acfbc18e' into develop (PR #104)

Conflicts:
	library/Solarium/Result/Select/Spellcheck.php
	tests/Solarium/Result/Select/SpellcheckTest.php
parents b56f4406 acfbc18e
...@@ -41,13 +41,16 @@ foreach($spellcheckResult as $suggestion) { ...@@ -41,13 +41,16 @@ foreach($spellcheckResult as $suggestion) {
echo '<hr/>'; echo '<hr/>';
} }
$collation = $spellcheckResult->getCollation(); $collations = $spellcheckResult->getCollations();
echo '<h1>Collation</h1>'; echo '<h1>Collations</h1>';
echo 'Query: '.$collation->getQuery().'<br/>'; foreach($collations as $collation) {
echo 'Hits: '.$collation->getHits().'<br/>'; echo 'Query: '.$collation->getQuery().'<br/>';
echo 'Hits: '.$collation->getHits().'<br/>';
echo '<hr/>';
}
echo 'Corrections:<br/>'; echo 'Corrections:<br/>';
foreach($collation->getCorrections() as $input => $correction) { foreach($collation->getCorrections() as $input => $correction) {
echo $input . ' => ' . $correction .'<br/>'; echo $input . ' => ' . $correction .'<br/>';
} }
htmlFooter(); htmlFooter();
\ No newline at end of file
...@@ -173,4 +173,4 @@ class Solarium_Client_ResponseParser_Select_Component_Spellcheck ...@@ -173,4 +173,4 @@ class Solarium_Client_ResponseParser_Select_Component_Spellcheck
$numFound, $startOffset, $endOffset, $originalFrequency, $word, $frequency $numFound, $startOffset, $endOffset, $originalFrequency, $word, $frequency
); );
} }
} }
\ No newline at end of file
...@@ -70,7 +70,7 @@ class Solarium_Result_Select_Spellcheck implements IteratorAggregate, Countable ...@@ -70,7 +70,7 @@ class Solarium_Result_Select_Spellcheck implements IteratorAggregate, Countable
* Constructor * Constructor
* *
* @param array $suggestions * @param array $suggestions
* @param Solarium_Result_Select_Spellcheck_Collation $collation * @param array $collations
* @param boolean $correctlySpelled * @param boolean $correctlySpelled
* @return void * @return void
*/ */
...@@ -83,7 +83,7 @@ class Solarium_Result_Select_Spellcheck implements IteratorAggregate, Countable ...@@ -83,7 +83,7 @@ class Solarium_Result_Select_Spellcheck implements IteratorAggregate, Countable
/** /**
* Get the collation result * Get the collation result
* *
* @param int $key * @param int $key
* @return Solarium_Result_Select_Spellcheck_Collation * @return Solarium_Result_Select_Spellcheck_Collation
*/ */
...@@ -95,7 +95,7 @@ class Solarium_Result_Select_Spellcheck implements IteratorAggregate, Countable ...@@ -95,7 +95,7 @@ class Solarium_Result_Select_Spellcheck implements IteratorAggregate, Countable
} else { } else {
if ($key === null) { if ($key === null) {
$key = $nrOfCollations - 1; // for backwards compatibility return reset($this->_collations);
} }
return $this->_collations[$key]; return $this->_collations[$key];
...@@ -128,7 +128,7 @@ class Solarium_Result_Select_Spellcheck implements IteratorAggregate, Countable ...@@ -128,7 +128,7 @@ class Solarium_Result_Select_Spellcheck implements IteratorAggregate, Countable
* Get a result by key * Get a result by key
* *
* @param mixed $key * @param mixed $key
* @return Solarium_Result_Select_Highlighting_Suggestion|null * @return Solarium_Result_Select_Spellcheck_Suggestion|null
*/ */
public function getSuggestion($key) public function getSuggestion($key)
{ {
...@@ -168,4 +168,4 @@ class Solarium_Result_Select_Spellcheck implements IteratorAggregate, Countable ...@@ -168,4 +168,4 @@ class Solarium_Result_Select_Spellcheck implements IteratorAggregate, Countable
{ {
return count($this->_suggestions); return count($this->_suggestions);
} }
} }
\ No newline at end of file
...@@ -85,6 +85,21 @@ class Solarium_Client_ResponseParser_Select_Component_SpellcheckTest extends PHP ...@@ -85,6 +85,21 @@ class Solarium_Client_ResponseParser_Select_Component_SpellcheckTest extends PHP
3 => 'ultrasharp' 3 => 'ultrasharp'
), ),
), ),
8 => 'collation',
9 => array (
0 => 'collationQuery',
1 => 'dell ultrasharp new',
2 => 'hits',
3 => 0,
4 => 'misspellingsAndCorrections',
5 => array (
0 => 'delll',
1 => 'dell',
2 => 'ultrashar',
3 => 'ultrasharp'
),
),
) )
) )
); );
...@@ -95,6 +110,9 @@ class Solarium_Client_ResponseParser_Select_Component_SpellcheckTest extends PHP ...@@ -95,6 +110,9 @@ class Solarium_Client_ResponseParser_Select_Component_SpellcheckTest extends PHP
$this->assertEquals(false, $result->getCorrectlySpelled()); $this->assertEquals(false, $result->getCorrectlySpelled());
$this->assertEquals('dell', $suggestions[0]->getWord()); $this->assertEquals('dell', $suggestions[0]->getWord());
$this->assertEquals('dell ultrasharp', $result->getCollation()->getQuery()); $this->assertEquals('dell ultrasharp', $result->getCollation()->getQuery());
$collations = $result->getCollations();
$this->assertEquals('dell ultrasharp', $collations[0]->getQuery());
$this->assertEquals('dell ultrasharp new', $collations[1]->getQuery());
} }
public function testParse() public function testParse()
...@@ -129,6 +147,8 @@ class Solarium_Client_ResponseParser_Select_Component_SpellcheckTest extends PHP ...@@ -129,6 +147,8 @@ class Solarium_Client_ResponseParser_Select_Component_SpellcheckTest extends PHP
5 => false, 5 => false,
6 => 'collation', 6 => 'collation',
7 => 'dell ultrasharp', 7 => 'dell ultrasharp',
8 => 'collation',
9 => 'dell ultrasharp new',
) )
) )
); );
...@@ -139,6 +159,10 @@ class Solarium_Client_ResponseParser_Select_Component_SpellcheckTest extends PHP ...@@ -139,6 +159,10 @@ class Solarium_Client_ResponseParser_Select_Component_SpellcheckTest extends PHP
$this->assertEquals(false, $result->getCorrectlySpelled()); $this->assertEquals(false, $result->getCorrectlySpelled());
$this->assertEquals('dell', $suggestions[0]->getWord()); $this->assertEquals('dell', $suggestions[0]->getWord());
$this->assertEquals('dell ultrasharp', $result->getCollation()->getQuery()); $this->assertEquals('dell ultrasharp', $result->getCollation()->getQuery());
$collations = $result->getCollations();
$this->assertEquals('dell ultrasharp', $collations[0]->getQuery());
$this->assertEquals('dell ultrasharp new', $collations[1]->getQuery());
} }
public function testParseNoData() public function testParseNoData()
......
...@@ -37,7 +37,7 @@ class Solarium_Result_Select_SpellcheckTest extends PHPUnit_Framework_TestCase ...@@ -37,7 +37,7 @@ class Solarium_Result_Select_SpellcheckTest extends PHPUnit_Framework_TestCase
*/ */
protected $_result; protected $_result;
protected $_suggestions, $_collation, $_correctlySpelled; protected $_suggestions, $_collations, $_correctlySpelled;
public function setUp() public function setUp()
{ {
...@@ -45,15 +45,19 @@ class Solarium_Result_Select_SpellcheckTest extends PHPUnit_Framework_TestCase ...@@ -45,15 +45,19 @@ class Solarium_Result_Select_SpellcheckTest extends PHPUnit_Framework_TestCase
'key1' => 'content1', 'key1' => 'content1',
'key2' => 'content2', 'key2' => 'content2',
); );
$this->_collation = 'dummy1'; $this->_collations = array(
'dummy1',
'dummy2',
);
$this->_correctlySpelled = false; $this->_correctlySpelled = false;
$this->_result = new Solarium_Result_Select_Spellcheck($this->_suggestions, array($this->_collation), $this->_correctlySpelled); $this->_result = new Solarium_Result_Select_Spellcheck($this->_suggestions, $this->_collations, $this->_correctlySpelled);
} }
public function testGetCollation() public function testGetCollation()
{ {
$this->assertEquals($this->_collation, $this->_result->getCollation()); $this->assertEquals($this->_collations, $this->_result->getCollations());
$this->assertEquals(reset($this->_collations), $this->_result->getCollation());
} }
public function testGetCorrectlySpelled() public function testGetCorrectlySpelled()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment