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

wip

parent ea0232ea
......@@ -12,7 +12,8 @@ $query->setRows(0);
// add spellcheck settings
$spellcheck = $query->getSpellcheck();
$spellcheck->setQuery('delll ultrashar');
$spellcheck->setQuery('tes');
$spellcheck->setCount(10);
$spellcheck->setBuild(true);
$spellcheck->setCollate(true);
$spellcheck->setExtendedResults(true);
......@@ -35,8 +36,12 @@ foreach($spellcheckResult as $suggestion) {
echo 'StartOffset: '.$suggestion->getStartOffset().'<br/>';
echo 'EndOffset: '.$suggestion->getEndOffset().'<br/>';
echo 'OriginalFrequency: '.$suggestion->getOriginalFrequency().'<br/>';
echo 'Frequency: '.$suggestion->getFrequency().'<br/>';
echo 'Word: '.$suggestion->getWord().'<br/>';
foreach ($suggestion->getWords() as $word) {
echo '-----<br/>';
echo 'Frequency: '.$word['freq'].'<br/>';
echo 'Word: '.$word['word'].'<br/>';
}
echo '<hr/>';
}
......
../build/coverage
\ No newline at end of file
......@@ -182,16 +182,19 @@ class Spellcheck extends ResponseParserAbstract implements ComponentParserInterf
$endOffset = (isset($value['endOffset'])) ? $value['endOffset'] : null;
$originalFrequency = (isset($value['origFreq'])) ? $value['origFreq'] : null;
if (is_string($value['suggestion'][0])) {
$word = $value['suggestion'][0];
$frequency = null;
} else {
$word = $value['suggestion'][0]['word'];
$frequency = $value['suggestion'][0]['freq'];
$words = array();
foreach($value['suggestion'] as $suggestion) {
if (is_string($suggestion)) {
$suggestion = array(
'word' => $suggestion,
'freq' => null,
);
}
$words[] = $suggestion;
}
return new Suggestion(
$numFound, $startOffset, $endOffset, $originalFrequency, $word, $frequency
$numFound, $startOffset, $endOffset, $originalFrequency, $words
);
}
}
......@@ -51,17 +51,15 @@ class Suggestion
* @param int $startOffset
* @param int $endOffset
* @param int $originalFrequency
* @param string $word
* @param int $frequency
* @param array $words
*/
public function __construct($numFound, $startOffset, $endOffset, $originalFrequency, $word, $frequency)
public function __construct($numFound, $startOffset, $endOffset, $originalFrequency, $words)
{
$this->numFound = $numFound;
$this->startOffset = $startOffset;
$this->endOffset = $endOffset;
$this->originalFrequency = $originalFrequency;
$this->word = $word;
$this->frequency = $frequency;
$this->words = $words;
}
/**
......@@ -107,13 +105,28 @@ class Suggestion
}
/**
* Get word
* Get first word
*
* @return string
* @return string|null
*/
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;
}
/**
......@@ -125,7 +138,12 @@ class Suggestion
*/
public function getFrequency()
{
return $this->frequency;
$word = reset($this->words);
if (isset($word['freq'])) {
return $word['freq'];
} else {
return null;
}
}
}
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