/** * Add a facet result for a range facet * * @param Query $query * @param QueryFacetRange $facet * @param array $data * @return ResultFacetRange */ protected function facetRange($query, $facet, $data) { $key = $facet->getKey(); if (isset($data['facet_counts']['facet_ranges'][$key])) { $data = $data['facet_counts']['facet_ranges'][$key]; $before = isset($data['before']) ? $data['before'] : null; $after = isset($data['after']) ? $data['after'] : null; $between = isset($data['between']) ? $data['between'] : null; $start = isset($data['start']) ? $data['start'] : null; $end = isset($data['end']) ? $data['end'] : null; $gap = isset($data['gap']) ? $data['gap'] : null; if ($query->getResponseWriter() == $query::WT_JSON) { $data['counts'] = $this->convertToKeyValueArray($data['counts']); } return new ResultFacetRange($data['counts'], $before, $after, $between, $start, $end, $gap); } }
/** * Parse collation data into a result object * * @param Query $queryObject * @param array $values * @return Collation[] */ protected function parseCollation($queryObject, $values) { $collations = array(); if (is_string($values)) { $collations[] = new Collation($values, null, array()); } elseif (is_array($values) && isset($values[0]) && is_string($values[0]) && $values[0] !== 'collationQuery') { foreach ($values as $value) { $collations[] = new Collation($value, null, array()); } } else { if ($queryObject->getResponseWriter() == $queryObject::WT_JSON) { if (is_array(current($values))) { foreach ($values as $key => $value) { $values[$key] = $this->convertToKeyValueArray($value); } } else { $values = array($this->convertToKeyValueArray($values)); } } foreach ($values as $collationValue) { $query = null; $hits = null; $correctionResult = null; foreach ($collationValue as $key => $value) { switch ($key) { case 'collationQuery': $query = $value; break; case 'hits': $hits = $value; break; case 'misspellingsAndCorrections': $correctionResult = $value; break; } } $corrections = array(); if ($correctionResult !== null) { if ($queryObject->getResponseWriter() == $queryObject::WT_JSON) { $correctionResult = $this->convertToKeyValueArray($correctionResult); } foreach ($correctionResult as $input => $correction) { $corrections[$input] = $correction; } } $collations[] = new Collation($query, $hits, $corrections); } } return $collations; }