/** * @return mixed[] */ private function getSolrQueryArrayRepresentation() : array { $fieldsQueryString = $this->convertCriteriaIntoSolrQueryString($this->criteria); $contextQueryString = $this->convertContextIntoQueryString($this->queryOptions->getContext()); $queryString = sprintf('(%s) AND %s', $fieldsQueryString, $contextQueryString); $rowsPerPage = $this->queryOptions->getRowsPerPage(); $offset = $this->queryOptions->getPageNumber() * $rowsPerPage; $sortOrderString = $this->getSortOrderString($this->queryOptions->getSortBy()); return ['q' => $queryString, 'rows' => $rowsPerPage, 'start' => $offset, 'sort' => $sortOrderString]; }
public function query(SearchCriteria $criteria, QueryOptions $queryOptions) : SearchEngineResponse { $query = new SolrQuery($criteria, $queryOptions); $facetFiltersToIncludeInResult = $queryOptions->getFacetFiltersToIncludeInResult(); $filterSelection = $queryOptions->getFilterSelection(); $facetFilterRequest = new SolrFacetFilterRequest($facetFiltersToIncludeInResult, $filterSelection, $this->facetFieldTransformationRegistry); $response = $this->querySolr($query, $facetFilterRequest); $totalNumberOfResults = $response->getTotalNumberOfResults(); $matchingProductIds = $response->getMatchingProductIds(); $facetFieldsCollection = $this->getFacetFieldCollectionFromSolrResponse($response, $query, $filterSelection, $facetFiltersToIncludeInResult); return new SearchEngineResponse($facetFieldsCollection, $totalNumberOfResults, ...$matchingProductIds); }
private function createTestQueryOptions(SortBy $sortOrderConfig) : QueryOptions { $filterSelection = []; $facetFiltersToIncludeInResult = new FacetFiltersToIncludeInResult(); $rowsPerPage = 100; $pageNumber = 0; return QueryOptions::create($filterSelection, $this->createTestContext(), $facetFiltersToIncludeInResult, $rowsPerPage, $pageNumber, $sortOrderConfig); }
public function testArrayRepresentationOfSolrQueryIsMemoized() { $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); $stubSortOrderConfig = $this->createMock(SortBy::class); $this->stubQueryOptions->method('getSortBy')->willReturn($stubSortOrderConfig); $resultA = $this->solrQuery->toArray(); $resultB = $this->solrQuery->toArray(); $this->assertSame($resultA, $resultB); }