diff --git a/src/module-elasticsuite-catalog/Plugin/Search/RequestMapperPlugin.php b/src/module-elasticsuite-catalog/Plugin/Search/RequestMapperPlugin.php index eee280438..d0b8124d0 100644 --- a/src/module-elasticsuite-catalog/Plugin/Search/RequestMapperPlugin.php +++ b/src/module-elasticsuite-catalog/Plugin/Search/RequestMapperPlugin.php @@ -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()]; diff --git a/src/module-elasticsuite-core/Model/Search/RequestBuilder.php b/src/module-elasticsuite-core/Model/Search/RequestBuilder.php index a0345030e..a63ed37d3 100644 --- a/src/module-elasticsuite-core/Model/Search/RequestBuilder.php +++ b/src/module-elasticsuite-core/Model/Search/RequestBuilder.php @@ -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, []); }