Commit 43d502ca authored by Bas de Nooijer's avatar Bas de Nooijer

Updated spellcheck responseparser to support PHPS responses

parent 33c31ccd
...@@ -40,11 +40,12 @@ namespace Solarium\QueryType\Select\ResponseParser\Component; ...@@ -40,11 +40,12 @@ namespace Solarium\QueryType\Select\ResponseParser\Component;
use Solarium\QueryType\Select\Query\Query; use Solarium\QueryType\Select\Query\Query;
use Solarium\QueryType\Select\Query\Component\Spellcheck as SpellcheckComponent; use Solarium\QueryType\Select\Query\Component\Spellcheck as SpellcheckComponent;
use Solarium\QueryType\Select\Result\Spellcheck as SpellcheckResult; use Solarium\QueryType\Select\Result\Spellcheck as SpellcheckResult;
use Solarium\Core\Query\ResponseParser as ResponseParserAbstract;
/** /**
* Parse select component Highlighting result from the data * Parse select component Highlighting result from the data
*/ */
class Spellcheck class Spellcheck extends ResponseParserAbstract
{ {
/** /**
...@@ -65,28 +66,26 @@ class Spellcheck ...@@ -65,28 +66,26 @@ class Spellcheck
) { ) {
$spellcheckResults = $data['spellcheck']['suggestions']; $spellcheckResults = $data['spellcheck']['suggestions'];
if ($query->getResponseWriter() == $query::WT_JSON) {
$spellcheckResults = $this->convertToKeyValueArray($spellcheckResults);
}
$suggestions = array(); $suggestions = array();
$correctlySpelled = null; $correctlySpelled = null;
$collations = array(); $collations = array();
$index = 0;
while (isset($spellcheckResults[$index]) && isset($spellcheckResults[$index+1])) {
$key = $spellcheckResults[$index];
$value = $spellcheckResults[$index+1];
foreach ($spellcheckResults as $key => $value) {
switch ($key) { switch ($key) {
case 'correctlySpelled': case 'correctlySpelled':
$correctlySpelled = $value; $correctlySpelled = $value;
break; break;
case 'collation': case 'collation':
$collations[] = $this->parseCollation($value); $collations[] = $this->parseCollation($query, $value);
break; break;
default: default:
$suggestions[] = $this->parseSuggestion($key, $value); $suggestions[] = $this->parseSuggestion($key, $value);
} }
$index +=2;
} }
return new SpellcheckResult\Result($suggestions, $collations, $correctlySpelled); return new SpellcheckResult\Result($suggestions, $collations, $correctlySpelled);
...@@ -98,10 +97,11 @@ class Spellcheck ...@@ -98,10 +97,11 @@ class Spellcheck
/** /**
* Parse collation data into a result object * Parse collation data into a result object
* *
* @param Query $queryObject
* @param array $values * @param array $values
* @return SpellcheckResult\Collation * @return SpellcheckResult\Collation
*/ */
protected function parseCollation($values) protected function parseCollation($queryObject, $values)
{ {
if (is_string($values)) { if (is_string($values)) {
...@@ -113,11 +113,11 @@ class Spellcheck ...@@ -113,11 +113,11 @@ class Spellcheck
$hits = null; $hits = null;
$correctionResult = null; $correctionResult = null;
$index = 0; if ($queryObject->getResponseWriter() == $queryObject::WT_JSON) {
while (isset($values[$index]) && isset($values[$index+1])) { $values = $this->convertToKeyValueArray($values);
$key = $values[$index]; }
$value = $values[$index+1];
foreach($values as $key => $value) {
switch ($key) { switch ($key) {
case 'collationQuery': case 'collationQuery':
$query = $value; $query = $value;
...@@ -129,19 +129,17 @@ class Spellcheck ...@@ -129,19 +129,17 @@ class Spellcheck
$correctionResult = $value; $correctionResult = $value;
break; break;
} }
$index +=2;
} }
$corrections = array(); $corrections = array();
if ($correctionResult !== null) { if ($correctionResult !== null) {
$index = 0;
while (isset($correctionResult[$index]) && isset($correctionResult[$index+1])) {
$input = $correctionResult[$index];
$correction = $correctionResult[$index+1];
if ($queryObject->getResponseWriter() == $queryObject::WT_JSON) {
$correctionResult = $this->convertToKeyValueArray($correctionResult);
}
foreach ($correctionResult as $input => $correction) {
$corrections[$input] = $correction; $corrections[$input] = $correction;
$index += 2;
} }
} }
......
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