Commit abef42ce authored by Bas de Nooijer's avatar Bas de Nooijer

Merge pull request #241 from adrienbrault/fix-multiple-spellcheck

Fix Spellcheck response parser with multiple suggestions
parents ba0bcaec f56b4ec2
...@@ -86,9 +86,15 @@ class Spellcheck extends ResponseParserAbstract implements ComponentParserInterf ...@@ -86,9 +86,15 @@ class Spellcheck extends ResponseParserAbstract implements ComponentParserInterf
$collations = $this->parseCollation($query, $value); $collations = $this->parseCollation($query, $value);
break; break;
default: default:
if (array_key_exists(0, $value)) {
foreach ($value as $currentValue) {
$suggestions[] = $this->parseSuggestion($key, $currentValue);
}
} else {
$suggestions[] = $this->parseSuggestion($key, $value); $suggestions[] = $this->parseSuggestion($key, $value);
} }
} }
}
return new SpellcheckResult\Result($suggestions, $collations, $correctlySpelled); return new SpellcheckResult\Result($suggestions, $collations, $correctlySpelled);
} else { } else {
......
...@@ -50,8 +50,8 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase ...@@ -50,8 +50,8 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
$data = array( $data = array(
'spellcheck' => array( 'spellcheck' => array(
'suggestions' => array( 'suggestions' => array(
0 => 'delll', 'delll',
1 => array ( array (
'numFound' => 1, 'numFound' => 1,
'startOffset' => 0, 'startOffset' => 0,
'endOffset' => 5, 'endOffset' => 5,
...@@ -63,8 +63,8 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase ...@@ -63,8 +63,8 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
), ),
), ),
), ),
2 => 'ultrashar', 'ultrashar',
3 => array ( array (
'numFound' => 1, 'numFound' => 1,
'startOffset' => 6, 'startOffset' => 6,
'endOffset' => 15, 'endOffset' => 15,
...@@ -76,10 +76,23 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase ...@@ -76,10 +76,23 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
), ),
), ),
), ),
4 => 'correctlySpelled', 'ultrashar',
5 => false, array (
6 => 'collation', 'numFound' => 1,
7 => array ( 'startOffset' => 16,
'endOffset' => 25,
'origFreq' => 0,
'suggestion' => array (
0 => array (
'word' => 'ultrasharp',
'freq' => 1,
),
),
),
'correctlySpelled',
false,
'collation',
array (
0 => 'collationQuery', 0 => 'collationQuery',
1 => 'dell ultrasharp', 1 => 'dell ultrasharp',
2 => 'hits', 2 => 'hits',
...@@ -92,8 +105,8 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase ...@@ -92,8 +105,8 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
3 => 'ultrasharp', 3 => 'ultrasharp',
), ),
), ),
8 => 'collation', 'collation',
9 => array ( array (
0 => 'collationQuery', 0 => 'collationQuery',
1 => 'dell ultrasharp new', 1 => 'dell ultrasharp new',
2 => 'hits', 2 => 'hits',
...@@ -115,6 +128,10 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase ...@@ -115,6 +128,10 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
$suggestions = $result->getSuggestions(); $suggestions = $result->getSuggestions();
$this->assertEquals(false, $result->getCorrectlySpelled()); $this->assertEquals(false, $result->getCorrectlySpelled());
$this->assertEquals('dell', $suggestions[0]->getWord()); $this->assertEquals('dell', $suggestions[0]->getWord());
$this->assertEquals('ultrasharp', $suggestions[1]->getWord());
$this->assertEquals(6, $suggestions[1]->getStartOffset());
$this->assertEquals('ultrasharp', $suggestions[2]->getWord());
$this->assertEquals(16, $suggestions[2]->getStartOffset());
$this->assertEquals('dell ultrasharp', $result->getCollation()->getQuery()); $this->assertEquals('dell ultrasharp', $result->getCollation()->getQuery());
$collations = $result->getCollations(); $collations = $result->getCollations();
$this->assertEquals('dell ultrasharp', $collations[0]->getQuery()); $this->assertEquals('dell ultrasharp', $collations[0]->getQuery());
......
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