Commit 127cca23 authored by Bas de Nooijer's avatar Bas de Nooijer

Merge commit 'ee4c4390' into 2.5

parents f7c55cf4 ee4c4390
...@@ -161,16 +161,19 @@ class Solarium_Client_ResponseParser_Select_Component_Spellcheck ...@@ -161,16 +161,19 @@ class Solarium_Client_ResponseParser_Select_Component_Spellcheck
$endOffset = (isset($value['endOffset'])) ? $value['endOffset'] : null; $endOffset = (isset($value['endOffset'])) ? $value['endOffset'] : null;
$originalFrequency = (isset($value['origFreq'])) ? $value['origFreq'] : null; $originalFrequency = (isset($value['origFreq'])) ? $value['origFreq'] : null;
if (is_string($value['suggestion'][0])) { $words = array();
$word = $value['suggestion'][0]; foreach($value['suggestion'] as $suggestion) {
$frequency = null; if (is_string($suggestion)) {
} else { $suggestion = array(
$word = $value['suggestion'][0]['word']; 'word' => $suggestion,
$frequency = $value['suggestion'][0]['freq']; 'freq' => null,
);
}
$words[] = $suggestion;
} }
return new Solarium_Result_Select_Spellcheck_Suggestion( return new Solarium_Result_Select_Spellcheck_Suggestion(
$numFound, $startOffset, $endOffset, $originalFrequency, $word, $frequency $numFound, $startOffset, $endOffset, $originalFrequency, $words
); );
} }
} }
\ No newline at end of file
...@@ -52,17 +52,15 @@ class Solarium_Result_Select_Spellcheck_Suggestion ...@@ -52,17 +52,15 @@ class Solarium_Result_Select_Spellcheck_Suggestion
* @param int $startOffset * @param int $startOffset
* @param int $endOffset * @param int $endOffset
* @param int $originalFrequency * @param int $originalFrequency
* @param string $word * @param array $words
* @param int $frequency
*/ */
public function __construct($numFound, $startOffset, $endOffset, $originalFrequency, $word, $frequency) public function __construct($numFound, $startOffset, $endOffset, $originalFrequency, $words)
{ {
$this->_numFound = $numFound; $this->_numFound = $numFound;
$this->_startOffset = $startOffset; $this->_startOffset = $startOffset;
$this->_endOffset = $endOffset; $this->_endOffset = $endOffset;
$this->_originalFrequency = $originalFrequency; $this->_originalFrequency = $originalFrequency;
$this->_word = $word; $this->_words = $words;
$this->_frequency = $frequency;
} }
/** /**
...@@ -108,13 +106,28 @@ class Solarium_Result_Select_Spellcheck_Suggestion ...@@ -108,13 +106,28 @@ class Solarium_Result_Select_Spellcheck_Suggestion
} }
/** /**
* Get word * Get first word
* *
* @return string * @return string|null
*/ */
public function getWord() public function getWord()
{ {
return $this->_word; $word = reset($this->_words);
if (isset($word['word'])) {
return $word['word'];
} else {
return $word;
}
}
/**
* Get all words (and frequencies)
*
* @return array
*/
public function getWords()
{
return $this->_words;
} }
/** /**
...@@ -126,7 +139,11 @@ class Solarium_Result_Select_Spellcheck_Suggestion ...@@ -126,7 +139,11 @@ class Solarium_Result_Select_Spellcheck_Suggestion
*/ */
public function getFrequency() public function getFrequency()
{ {
return $this->_frequency; $word = reset($this->_words);
if (isset($word['freq'])) {
return $word['freq'];
} else {
return null;
}
} }
}
}
\ No newline at end of file
...@@ -45,11 +45,19 @@ class Solarium_Result_Select_Spellcheck_SuggestionTest extends PHPUnit_Framework ...@@ -45,11 +45,19 @@ class Solarium_Result_Select_Spellcheck_SuggestionTest extends PHPUnit_Framework
$this->_startOffset = 2; $this->_startOffset = 2;
$this->_endOffset = 3; $this->_endOffset = 3;
$this->_originalFrequency = 4; $this->_originalFrequency = 4;
$this->_word = 'dummyword'; $this->_words = array(
$this->_frequency = 5; array(
'word' => 'dummyword',
'freq' => 5
),
array(
'word' => 'secondword',
'freq' => 1
)
);
$this->_result = new Solarium_Result_Select_Spellcheck_Suggestion( $this->_result = new Solarium_Result_Select_Spellcheck_Suggestion(
$this->_numFound, $this->_startOffset, $this->_endOffset, $this->_originalFrequency, $this->_word, $this->_frequency $this->_numFound, $this->_startOffset, $this->_endOffset, $this->_originalFrequency, $this->_words
); );
} }
...@@ -75,12 +83,17 @@ class Solarium_Result_Select_Spellcheck_SuggestionTest extends PHPUnit_Framework ...@@ -75,12 +83,17 @@ class Solarium_Result_Select_Spellcheck_SuggestionTest extends PHPUnit_Framework
public function testGetWord() public function testGetWord()
{ {
$this->assertEquals($this->_word, $this->_result->getWord()); $this->assertEquals($this->_words[0]['word'], $this->_result->getWord());
} }
public function testGetFrequency() public function testGetFrequency()
{ {
$this->assertEquals($this->_frequency, $this->_result->getFrequency()); $this->assertEquals($this->_words[0]['freq'], $this->_result->getFrequency());
}
public function testGetWords()
{
$this->assertEquals($this->_words, $this->_result->getWords());
} }
} }
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