Esempio n. 1
0
 /**
  * Parse result data into result objects.
  *
  * @param Query             $query
  * @param GroupingComponent $grouping
  * @param array             $data
  *
  * @return Result
  */
 public function parse($query, $grouping, $data)
 {
     $groups = array();
     if (isset($data['grouped'])) {
         // parse field groups
         $valueResultClass = $grouping->getOption('resultvaluegroupclass');
         $documentClass = $query->getOption('documentclass');
         foreach ($grouping->getFields() as $field) {
             if (isset($data['grouped'][$field])) {
                 $result = $data['grouped'][$field];
                 $matches = isset($result['matches']) ? $result['matches'] : null;
                 $groupCount = isset($result['ngroups']) ? $result['ngroups'] : null;
                 $valueGroups = array();
                 foreach ($result['groups'] as $valueGroupResult) {
                     $value = isset($valueGroupResult['groupValue']) ? $valueGroupResult['groupValue'] : null;
                     $numFound = isset($valueGroupResult['doclist']['numFound']) ? $valueGroupResult['doclist']['numFound'] : null;
                     $start = isset($valueGroupResult['doclist']['start']) ? $valueGroupResult['doclist']['start'] : null;
                     $maxScore = isset($valueGroupResult['doclist']['maxScore']) ? $valueGroupResult['doclist']['maxScore'] : null;
                     // create document instances
                     $documents = array();
                     if (isset($valueGroupResult['doclist']['docs']) && is_array($valueGroupResult['doclist']['docs'])) {
                         foreach ($valueGroupResult['doclist']['docs'] as $doc) {
                             $documents[] = new $documentClass($doc);
                         }
                     }
                     $valueGroups[] = new $valueResultClass($value, $numFound, $start, $documents, $maxScore, $query);
                 }
                 $groups[$field] = new FieldGroup($matches, $groupCount, $valueGroups);
             }
         }
         // parse query groups
         $groupResultClass = $grouping->getOption('resultquerygroupclass');
         foreach ($grouping->getQueries() as $groupQuery) {
             if (isset($data['grouped'][$groupQuery])) {
                 $result = $data['grouped'][$groupQuery];
                 // get statistics
                 $matches = isset($result['matches']) ? $result['matches'] : null;
                 $numFound = isset($result['doclist']['numFound']) ? $result['doclist']['numFound'] : null;
                 $start = isset($result['doclist']['start']) ? $result['doclist']['start'] : null;
                 $maxScore = isset($result['doclist']['maxScore']) ? $result['doclist']['maxScore'] : null;
                 // create document instances
                 $documentClass = $query->getOption('documentclass');
                 $documents = array();
                 if (isset($result['doclist']['docs']) && is_array($result['doclist']['docs'])) {
                     foreach ($result['doclist']['docs'] as $doc) {
                         $documents[] = new $documentClass($doc);
                     }
                 }
                 // create a group result object
                 $group = new $groupResultClass($matches, $numFound, $start, $maxScore, $documents, $query);
                 $groups[$groupQuery] = $group;
             }
         }
     }
     return new Result($groups);
 }
 /**
  * Parse result data into result objects
  *
  * @param  Query                 $query
  * @param  MoreLikeThisComponent $moreLikeThis
  * @param  array                 $data
  * @return MoreLikeThis
  */
 public function parse($query, $moreLikeThis, $data)
 {
     $results = array();
     if (isset($data['moreLikeThis'])) {
         $documentClass = $query->getOption('documentclass');
         $searchResults = $data['moreLikeThis'];
         foreach ($searchResults as $key => $result) {
             // create document instances
             $docs = array();
             foreach ($result['docs'] as $fields) {
                 $docs[] = new $documentClass($fields);
             }
             $results[$key] = new Result($result['numFound'], $result['maxScore'], $docs);
         }
     }
     return new MoreLikeThisResult($results);
 }