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

Merge pull request #354 from brunonuss/bugfix/collations_format_changes_in_solr_5.0

Spellchecker: solr 5.0 format changes kills collations
parents 6b540584 24d8dbe5
...@@ -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,7 +124,87 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase ...@@ -123,7 +124,87 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
) )
); );
$result = $this->parser->parse($this->query, null, $data); $data['solr5'] = array(
'spellcheck' => array(
'suggestions' => array(
'delll',
array (
'numFound' => 1,
'startOffset' => 0,
'endOffset' => 5,
'origFreq' => 0,
'suggestion' => array (
0 => array (
'word' => 'dell',
'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(); $suggestions = $result->getSuggestions();
$this->assertEquals(false, $result->getCorrectlySpelled()); $this->assertEquals(false, $result->getCorrectlySpelled());
...@@ -137,10 +218,12 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase ...@@ -137,10 +218,12 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('dell ultrasharp', $collations[0]->getQuery()); $this->assertEquals('dell ultrasharp', $collations[0]->getQuery());
$this->assertEquals('dell ultrasharp new', $collations[1]->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,7 +259,47 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase ...@@ -176,7 +259,47 @@ 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) {
$result = $this->parser->parse($this->query, null, $testData);
$suggestions = $result->getSuggestions(); $suggestions = $result->getSuggestions();
$this->assertEquals(false, $result->getCorrectlySpelled()); $this->assertEquals(false, $result->getCorrectlySpelled());
...@@ -185,12 +308,13 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase ...@@ -185,12 +308,13 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
$collations = $result->getCollations(); $collations = $result->getCollations();
$this->assertEquals('dell ultrasharp', $collations[0]->getQuery()); $this->assertEquals('dell ultrasharp', $collations[0]->getQuery());
$this->assertEquals('dell ultrasharp new', $collations[1]->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,13 +352,56 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase ...@@ -228,13 +352,56 @@ 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' => 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(); $collations = $result->getCollations();
$this->assertEquals('dell ultrasharp', $collations[0]->getQuery()); $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