Skip to content

Commit

Permalink
Update support for formatted values in Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispenny committed Nov 3, 2024
1 parent 20d23c9 commit 0d3ee4e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Processors/SuggestionsProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Exception;
use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Discoverer\Service\Results\Field;
use SilverStripe\Discoverer\Service\Results\Suggestions;

class SuggestionsProcessor
Expand All @@ -19,7 +20,14 @@ public function getProcessedSuggestions(Suggestions $suggestions, array $respons
// Check that we have all critical fields in our Elastic response
$this->validateResponse($response);

$suggestions->setSuggestions($response['results'] ?? []);
$results = $response['results'] ?? [];

foreach ($results as $result) {
$suggestions->addSuggestion(Field::create(
$result['raw'] ?? null,
$result['snippet'] ?? null,
));
}
}

private function validateResponse(array $response): void
Expand Down

0 comments on commit 0d3ee4e

Please sign in to comment.