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

Merge branch 'develop' of github.com:solariumphp/solarium into develop

parents e1b758f8 b473ccaa
...@@ -104,14 +104,8 @@ class Spellcheck extends ResponseParserAbstract implements ComponentParserInterf ...@@ -104,14 +104,8 @@ class Spellcheck extends ResponseParserAbstract implements ComponentParserInterf
if (isset($data['spellcheck']['collations']) && if (isset($data['spellcheck']['collations']) &&
is_array($data['spellcheck']['collations']) is_array($data['spellcheck']['collations'])
) { ) {
foreach ($data['spellcheck']['collations'] as $collationResult) { foreach ($this->convertToKeyValueArray($data['spellcheck']['collations']) as $collationResult) {
if (is_array($collationResult)) { $collations = array_merge($collations, $this->parseCollation($query, $collationResult ));
$collation = array();
foreach ($collationResult as $key => $value) {
$collation = array_merge($collation, array($key, $value));
}
$collations = array_merge($collations, $this->parseCollation($query, $collation ));
}
} }
} }
......
...@@ -47,7 +47,8 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase ...@@ -47,7 +47,8 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
public function testParseExtended() public function testParseExtended()
{ {
$data = array( $data = array();
$data['solr4'] = array(
'spellcheck' => array( 'spellcheck' => array(
'suggestions' => array( 'suggestions' => array(
'delll', 'delll',
...@@ -123,24 +124,106 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase ...@@ -123,24 +124,106 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
) )
); );
$result = $this->parser->parse($this->query, null, $data); $data['solr5'] = array(
'spellcheck' => array(
$suggestions = $result->getSuggestions(); 'suggestions' => array(
$this->assertEquals(false, $result->getCorrectlySpelled()); 'delll',
$this->assertEquals('dell', $suggestions[0]->getWord()); array (
$this->assertEquals('ultrasharp', $suggestions[1]->getWord()); 'numFound' => 1,
$this->assertEquals(6, $suggestions[1]->getStartOffset()); 'startOffset' => 0,
$this->assertEquals('ultrasharp', $suggestions[2]->getWord()); 'endOffset' => 5,
$this->assertEquals(16, $suggestions[2]->getStartOffset()); 'origFreq' => 0,
$this->assertEquals('dell ultrasharp', $result->getCollation()->getQuery()); 'suggestion' => array (
$collations = $result->getCollations(); 0 => array (
$this->assertEquals('dell ultrasharp', $collations[0]->getQuery()); 'word' => 'dell',
$this->assertEquals('dell ultrasharp new', $collations[1]->getQuery()); 'freq' => 1,
),
),
),
'ultrashar',
array (
'numFound' => 1,
'startOffset' => 6,
'endOffset' => 15,
'origFreq' => 0,
'suggestion' => array (
0 => array (
'word' => 'ultrasharp',
'freq' => 1,
),
),
),
'ultrashar',
array (
'numFound' => 1,
'startOffset' => 16,
'endOffset' => 25,
'origFreq' => 0,
'suggestion' => array (
0 => array (
'word' => 'ultrasharp',
'freq' => 1,
),
),
),
),
'correctlySpelled',
false,
'collations' => array(
'collation',
array (
0 => 'collationQuery',
1 => 'dell ultrasharp',
2 => 'hits',
3 => 0,
4 => 'misspellingsAndCorrections',
5 => array (
0 => 'delll',
1 => 'dell',
2 => 'ultrashar',
3 => 'ultrasharp',
),
),
'collation',
array (
0 => 'collationQuery',
1 => 'dell ultrasharp new',
2 => 'hits',
3 => 0,
4 => 'misspellingsAndCorrections',
5 => array (
0 => 'delll',
1 => 'dell',
2 => 'ultrashar',
3 => 'ultrasharp',
),
),
)
)
);
foreach ($data as $testData) {
$result = $this->parser->parse($this->query, null, $testData);
$suggestions = $result->getSuggestions();
$this->assertEquals(false, $result->getCorrectlySpelled());
$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());
$collations = $result->getCollations();
$this->assertEquals('dell ultrasharp', $collations[0]->getQuery());
$this->assertEquals('dell ultrasharp new', $collations[1]->getQuery());
}
} }
public function testParse() public function testParse()
{ {
$data = array( $data = array();
$data['solr4'] = array(
'spellcheck' => array( 'spellcheck' => array(
'suggestions' => array( 'suggestions' => array(
0 => 'delll', 0 => 'delll',
...@@ -176,21 +259,62 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase ...@@ -176,21 +259,62 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
) )
); );
$result = $this->parser->parse($this->query, null, $data); $data['solr5'] = array(
'spellcheck' => array(
'suggestions' => array(
0 => 'delll',
1 => array (
'numFound' => 1,
'startOffset' => 0,
'endOffset' => 5,
'origFreq' => 0,
'suggestion' => array (
0 => 'dell',
),
),
2 => 'ultrashar',
3 => array (
'numFound' => 1,
'startOffset' => 6,
'endOffset' => 15,
'origFreq' => 0,
'suggestion' => array (
0 => array (
'word' => 'ultrasharp',
'freq' => 1,
),
),
),
),
'correctlySpelled',
false,
'collations' => array(
'collation',
'dell ultrasharp',
'collation',
'dell ultrasharp new',
)
)
);
foreach ($data as $testData) {
$suggestions = $result->getSuggestions(); $result = $this->parser->parse($this->query, null, $testData);
$this->assertEquals(false, $result->getCorrectlySpelled());
$this->assertEquals('dell', $suggestions[0]->getWord());
$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());
$suggestions = $result->getSuggestions();
$this->assertEquals(false, $result->getCorrectlySpelled());
$this->assertEquals('dell', $suggestions[0]->getWord());
$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 testParseSingleCollation() public function testParseSingleCollation()
{ {
$data = array( $data = array();
$data['solr4'] = array(
'spellcheck' => array( 'spellcheck' => array(
'suggestions' => array( 'suggestions' => array(
0 => 'delll', 0 => 'delll',
...@@ -228,12 +352,55 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase ...@@ -228,12 +352,55 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
) )
); );
$result = $this->parser->parse($this->query, null, $data); $data['solr5'] = array(
$collations = $result->getCollations(); 'spellcheck' => array(
$this->assertEquals('dell ultrasharp', $collations[0]->getQuery()); 'suggestions' => array(
0 => 'delll',
1 => array (
'numFound' => 1,
'startOffset' => 0,
'endOffset' => 5,
'origFreq' => 0,
'suggestion' => array (
0 => 'dell',
),
),
2 => 'ultrashar',
3 => array (
'numFound' => 1,
'startOffset' => 6,
'endOffset' => 15,
'origFreq' => 0,
'suggestion' => array (
0 => array (
'word' => 'ultrasharp',
'freq' => 2,
),
1 => array (
'word' => 'ultrasharpy',
'freq' => 1,
),
),
),
),
'correctlySpelled',
false,
'collations' => array(
'collation',
'dell ultrasharp'
)
)
);
foreach ($data as $testData) {
$result = $this->parser->parse($this->query, null, $testData);
$collations = $result->getCollations();
$this->assertEquals('dell ultrasharp', $collations[0]->getQuery());
$words = $result->getSuggestion(1)->getWords(); $words = $result->getSuggestion(1)->getWords();
$this->assertEquals(array('word' => 'ultrasharpy', 'freq' => 1), $words[1]); $this->assertEquals(array('word' => 'ultrasharpy', 'freq' => 1), $words[1]);
}
} }
public function testParseNoData() public function testParseNoData()
......
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