private function querySolr(SolrQuery $query, SolrFacetFilterRequest $facetFilterRequest) : SolrResponse { $queryParameters = $query->toArray(); $facetParameters = $facetFilterRequest->toArray(); $response = $this->client->select(array_merge($queryParameters, $facetParameters)); return SolrResponse::fromSolrResponseArray($response, $this->facetFieldTransformationRegistry); }
public function testFacetFieldTransformationIsAppliedToFacetField() { $testRangedAttributeCode = 'foo'; $testNormalAttributeCode = 'bar'; $this->stubFacetFiltersToIncludeInResult->method('getFields')->willReturn([$this->createStubFacetFilterRequestField($testRangedAttributeCode), $this->createStubFacetFilterRequestField($testNormalAttributeCode)]); $testFilterSelection = [$testRangedAttributeCode => ['Value does not matter as it will be transformed.'], $testNormalAttributeCode => ['Does not matter either.']]; $rangeFrom = 'baz'; $rangeTo = 'qux'; $stubFacetFilterRange = $this->createMock(FacetFilterRange::class); $stubFacetFilterRange->method('from')->willReturn($rangeFrom); $stubFacetFilterRange->method('to')->willReturn($rangeTo); $stubRangedTransformation = $this->createMock(FacetFieldTransformation::class); $stubRangedTransformation->method('decode')->willReturn($stubFacetFilterRange); $transformedValue = 'Transformed value'; $stubNormalTransformation = $this->createMock(FacetFieldTransformation::class); $stubNormalTransformation->method('decode')->willReturn($transformedValue); $this->stubFacetFieldTransformationRegistry->method('hasTransformationForCode')->willReturn(true); $this->stubFacetFieldTransformationRegistry->method('getTransformationByCode')->willReturnMap([[$testRangedAttributeCode, $stubRangedTransformation], [$testNormalAttributeCode, $stubNormalTransformation]]); $solrFacetFilterRequest = new SolrFacetFilterRequest($this->stubFacetFiltersToIncludeInResult, $testFilterSelection, $this->stubFacetFieldTransformationRegistry); $expectedArray = ['facet' => 'on', 'facet.mincount' => 1, 'facet.limit' => -1, 'facet.sort' => 'index', 'facet.field' => [$testRangedAttributeCode, $testNormalAttributeCode], 'facet.query' => [], 'fq' => [sprintf('%s:([%s TO %s])', $testRangedAttributeCode, $rangeFrom, $rangeTo), sprintf('%s:("%s")', $testNormalAttributeCode, $transformedValue)]]; $this->assertSame($expectedArray, $solrFacetFilterRequest->toArray()); }