private function encodeFilterRange(FacetFieldTransformationRegistry $transformationRegistry) : string { if (!$transformationRegistry->hasTransformationForCode((string) $this->attributeCode)) { throw new NoFacetFieldTransformationRegisteredException(sprintf('No facet field transformation is registered for "%s" attribute.', $this->attributeCode)); } $transformation = $transformationRegistry->getTransformationByCode((string) $this->attributeCode); $boundaries = explode(' TO ', $this->value); $facetFilterRange = FacetFilterRange::create($this->getRangeBoundaryValue($boundaries[0]), $this->getRangeBoundaryValue($boundaries[1])); return $transformation->encode($facetFilterRange); }
/** * @param string $filterCode * @param string[] $filterValues * @return string */ private function getFormattedFacetQueryValues(string $filterCode, array $filterValues) : string { if ($this->facetFieldTransformationRegistry->hasTransformationForCode($filterCode)) { $transformation = $this->facetFieldTransformationRegistry->getTransformationByCode($filterCode); $formattedValues = array_map(function (string $filterValue) use($transformation) { $facetValue = $transformation->decode($filterValue); if ($facetValue instanceof FacetFilterRange) { $from = $this->escapeQueryChars($facetValue->from()); $to = $this->escapeQueryChars($facetValue->to()); return sprintf('[%s TO %s]', $from, $to); } return sprintf('"%s"', $this->escapeQueryChars($facetValue)); }, $filterValues); return sprintf('%s:(%s)', $this->escapeQueryChars($filterCode), implode(' OR ', $formattedValues)); } $escapedFilterValues = array_map([$this, 'escapeQueryChars'], $filterValues); return sprintf('%s:("%s")', $this->escapeQueryChars($filterCode), implode('" OR "', $escapedFilterValues)); }