/**
  * @param string $facetQueryString
  * @param int $count
  * @return SolrFacetQuery
  */
 public static function fromStringAndCount(string $facetQueryString, int $count)
 {
     if (preg_match('/^(?<attributeCode>[^:]+):\\[(?<value>.* TO .*)\\]$/', $facetQueryString, $matches)) {
         return new self(AttributeCode::fromString($matches['attributeCode']), $matches['value'], $count, true);
     }
     if (preg_match('/^(?<attributeCode>[^:]+):\\((?<value>.*)\\)$/', $facetQueryString, $matches)) {
         return new self(AttributeCode::fromString($matches['attributeCode']), $matches['value'], $count, false);
     }
     throw new InvalidFacetQueryFormatException(sprintf('Facet query "%s" format is invalid', $facetQueryString));
 }
 /**
  * @param array[] $rawFacetQueries
  * @return FacetField[]
  */
 private function buildFacetFieldValuesFromRawFacetQueries(array $rawFacetQueries) : array
 {
     return array_map(function ($attributeCodeString) use($rawFacetQueries) {
         $attributeCode = AttributeCode::fromString($attributeCodeString);
         $attributeValueCounts = $rawFacetQueries[$attributeCodeString];
         $facetFieldValues = $this->createFacetFieldValues($attributeValueCounts);
         return new FacetField($attributeCode, ...$facetFieldValues);
     }, array_keys($rawFacetQueries));
 }
 public function testArrayRepresentationOfQueryContainsSortOrderString()
 {
     $this->stubCriteria->expects($this->once())->method('jsonSerialize')->willReturn(['fieldName' => 'foo', 'fieldValue' => 'bar', 'operation' => 'Equal']);
     $stubContext = $this->createMock(Context::class);
     $stubContext->method('getSupportedCodes')->willReturn([]);
     $this->stubQueryOptions->method('getContext')->willReturn($stubContext);
     $sortAttributeCode = AttributeCode::fromString('baz');
     $sortDirection = SortDirection::create(SortDirection::ASC);
     $stubSortOrderConfig = $this->createMock(SortBy::class);
     $stubSortOrderConfig->method('getAttributeCode')->willReturn($sortAttributeCode);
     $stubSortOrderConfig->method('getSelectedDirection')->willReturn($sortDirection);
     $this->stubQueryOptions->method('getSortBy')->willReturn($stubSortOrderConfig);
     $result = $this->solrQuery->toArray();
     $expectedSortOrderString = sprintf('%s%s %s', $sortAttributeCode, SolrQuery::SORTING_SUFFIX, $sortDirection);
     $this->assertArrayHasKey('sort', $result);
     $this->assertSame($expectedSortOrderString, $result['sort']);
 }
 private function createTestSortOrderConfig(string $sortByFieldCode, string $sortDirection) : SortBy
 {
     return new SortBy(AttributeCode::fromString($sortByFieldCode), SortDirection::create($sortDirection));
 }
 public function testSelectedFiltersAreNotReturnedAlongWithFacetQueries()
 {
     $attributeCode = 'foo';
     $attributeValue = 'bar';
     $attributeValueCount = 2;
     $selectedAttributeCode = 'baz';
     $selectedAttributeValue = 'qux';
     $selectedAttributeValueCount = 4;
     $responseArray = ['facet_counts' => ['facet_queries' => [sprintf('%s:(%s)', $attributeCode, $attributeValue) => $attributeValueCount, sprintf('%s:(%s)', $selectedAttributeCode, $selectedAttributeValue) => $selectedAttributeValueCount]]];
     $selectedFilterAttributeCodes = [$selectedAttributeCode];
     $response = SolrResponse::fromSolrResponseArray($responseArray, $this->stubFacetFieldTransformationRegistry);
     $expectedFacetField = new FacetField(AttributeCode::fromString($attributeCode), new FacetFieldValue($attributeValue, $attributeValueCount));
     $this->assertEquals([$expectedFacetField], $response->getNonSelectedFacetFields($selectedFilterAttributeCodes));
 }
 public function testSearchEngineResponseContainsFacetFields()
 {
     $attributeCode = 'foo';
     $attributeValue = 'bar';
     $attributeValueCount = 1;
     $this->mockHttpClient->method('select')->willReturn(['facet_counts' => ['facet_fields' => [$attributeCode => [$attributeValue, $attributeValueCount]]]]);
     $searchCriteria = new SearchCriterionAnything();
     $filterSelection = [$attributeCode => [$attributeValue]];
     $response = $this->searchEngine->query($searchCriteria, $this->createStubQueryOptions($filterSelection));
     $expectedFacetFieldCollection = new FacetFieldCollection(new FacetField(AttributeCode::fromString($attributeCode), new FacetFieldValue($attributeValue, $attributeValueCount)));
     $this->assertEquals($expectedFacetFieldCollection, $response->getFacetFieldCollection());
 }