mdiyakov /
DoctrineSolrBundle
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Mdiyakov\DoctrineSolrBundle\Query\Suggest\Solarium; |
||
| 4 | |||
| 5 | use Solarium\Core\Query\ResponseParser as ResponseParserAbstract; |
||
| 6 | use Solarium\Core\Query\ResponseParserInterface as ResponseParserInterface; |
||
| 7 | use Solarium\QueryType\Suggester\Result\Result; |
||
| 8 | |||
| 9 | class ResponseParser extends ResponseParserAbstract implements ResponseParserInterface |
||
|
0 ignored issues
–
show
Deprecated Code
introduced
by
Loading history...
|
|||
| 10 | { |
||
| 11 | /** |
||
| 12 | * Get result data for the response |
||
| 13 | * |
||
| 14 | * @param Result $result |
||
| 15 | * @return array |
||
| 16 | */ |
||
| 17 | public function parse($result) |
||
| 18 | { |
||
| 19 | $data = $result->getData(); |
||
| 20 | $query = $result->getQuery(); |
||
| 21 | $suggestions = array(); |
||
| 22 | |||
| 23 | if (isset($data['suggest']) && is_array($data['suggest'])) { |
||
| 24 | |||
| 25 | $suggestResults = $data['suggest']; |
||
| 26 | $termClass = $query->getOption('termclass'); |
||
| 27 | foreach ($suggestResults as $dictionary => $termData) { |
||
| 28 | |||
| 29 | foreach ($termData as $term => $suggestionData) { |
||
| 30 | $suggestions[$dictionary][$term] = $this->createTerm($termClass, $suggestionData); |
||
| 31 | } |
||
| 32 | } |
||
| 33 | } |
||
| 34 | |||
| 35 | return $this->addHeaderInfo( |
||
| 36 | $data, |
||
| 37 | array( |
||
| 38 | 'results' => $suggestions, |
||
| 39 | ) |
||
| 40 | ); |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param $termClass |
||
| 45 | * @param array $suggestionData |
||
| 46 | * @return mixed |
||
| 47 | */ |
||
| 48 | private function createTerm($termClass, array $suggestionData) |
||
| 49 | { |
||
| 50 | return new $termClass( |
||
| 51 | $suggestionData['numFound'], |
||
| 52 | $suggestionData['suggestions'] |
||
| 53 | ); |
||
| 54 | } |
||
| 55 | } |