Skip to content

Commit

Permalink
Fixes #1660 Search terms positions sorting on REST and GraphQL
Browse files Browse the repository at this point in the history
when no sort order is provided and using the quick_search_container/in a search context.
  • Loading branch information
rbayet committed Jan 16, 2020
1 parent 80a2d3f commit e14d739
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ public function afterGetSortOrders(
$result['position'] = ['direction' => SortOrderInterface::SORT_ASC];
}

if ($containerConfiguration->getName() == "quick_search_container" && empty($result)) {
$searchQuery = $this->searchContext->getCurrentSearchQuery();
if ($searchQuery->getId()) {
$result['search_query.position'] = [
'direction' => SortOrderInterface::SORT_ASC,
'nestedFilter' => ['search_query.query_id' => $searchQuery->getId()],
];
}
}

foreach ($result as $sortField => $sortParams) {
if ($sortField == 'price') {
$sortParams['nestedFilter'] = ['price.customer_group_id' => $this->customerSession->getCustomerGroupId()];
Expand Down
4 changes: 2 additions & 2 deletions src/module-elasticsuite-core/Model/Search/RequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ public function getRequest(\Magento\Framework\Api\Search\SearchCriteriaInterface

$queryText = $this->getFulltextFilter($searchCriteria);

$this->updateSearchContext($storeId, $queryText);

$sortOrders = $this->requestMapper->getSortOrders($containerConfiguration, $searchCriteria);
$filters = $this->requestMapper->getFilters($containerConfiguration, $searchCriteria);

$this->updateSearchContext($storeId, $queryText);

return $this->searchRequestBuilder->create($storeId, $containerName, $from, $size, $queryText, $sortOrders, $filters, []);
}

Expand Down

0 comments on commit e14d739

Please sign in to comment.