Skip to content

Commit

Permalink
Implement getSuggestedSearchText()
Browse files Browse the repository at this point in the history
  • Loading branch information
pspanja committed Apr 17, 2020
1 parent 907f828 commit 2dfc35f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/API/Values/Content/Search/Suggestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,29 @@ public function getSuggestionsByOriginalWord(string $originalWord)

return $this->suggestionsByOriginalWords[$originalWord];
}

/**
* Get suggested search text based on returned spell check suggestions.
*
* @param string $originalSearchText
*
* @return string|null
*/
public function getSuggestedSearchText(string $originalSearchText)
{
$originalWords = $this->getOriginalWords();
$suggestedWords = [];

foreach ($originalWords as $originalWord) {
$suggestedWords[] = $this->getSuggestionsByOriginalWord($originalWord)[0]->suggestedWord;
}

$suggestedSearchText = \str_replace($originalWords, $suggestedWords, $originalSearchText);

if ($originalSearchText === $suggestedSearchText) {
return null;
}

return $suggestedSearchText;
}
}

0 comments on commit 2dfc35f

Please sign in to comment.