-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'fredden/laminas-mail' into 2.4-develop-prs
- Loading branch information
Showing
32 changed files
with
584 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogGraphQl\Model; | ||
|
||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Framework\Stdlib\StringUtils as StdlibString; | ||
use Magento\GraphQl\Model\Query\ContextInterface; | ||
use Magento\Search\Model\Query; | ||
use Magento\Search\Model\QueryFactory; | ||
|
||
/** | ||
* Prepares search query based on search text. | ||
*/ | ||
class QueryProcessor | ||
{ | ||
/** | ||
* @var QueryFactory | ||
*/ | ||
private $queryFactory; | ||
|
||
/** | ||
* @var StdlibString | ||
*/ | ||
private $string; | ||
|
||
/** | ||
* @param QueryFactory $queryFactory | ||
* @param StdlibString $string | ||
*/ | ||
public function __construct( | ||
QueryFactory $queryFactory, | ||
StdlibString $string | ||
) { | ||
$this->queryFactory = $queryFactory; | ||
$this->string = $string; | ||
} | ||
|
||
/** | ||
* Prepare Query object based on search text | ||
* | ||
* @param ContextInterface $context | ||
* @param string $queryText | ||
* @throws NoSuchEntityException | ||
* @return Query | ||
*/ | ||
public function prepare(ContextInterface $context, string $queryText) : Query | ||
{ | ||
$query = $this->queryFactory->create(); | ||
$maxQueryLength = (int) $query->getMaxQueryLength(); | ||
if ($maxQueryLength && $this->string->strlen($queryText) > $maxQueryLength) { | ||
$queryText = $this->string->substr($queryText, 0, $maxQueryLength); | ||
} | ||
$query->setQueryText($queryText); | ||
$store = $context->getExtensionAttributes()->getStore(); | ||
$query->setStoreId($store->getId()); | ||
return $query; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
app/code/Magento/CatalogGraphQl/Model/Resolver/Products/Query/Suggestions.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogGraphQl\Model\Resolver\Products\Query; | ||
|
||
use Magento\AdvancedSearch\Model\SuggestedQueries; | ||
use Magento\GraphQl\Model\Query\ContextInterface; | ||
use Magento\CatalogGraphQl\Model\QueryProcessor; | ||
|
||
/** | ||
* Search suggestions implementations for GraphQL | ||
*/ | ||
class Suggestions | ||
{ | ||
/** | ||
* @var QueryProcessor | ||
*/ | ||
private $queryProcessor; | ||
|
||
/** | ||
* @var SuggestedQueries | ||
*/ | ||
private $suggestedQueries; | ||
|
||
/** | ||
* @param QueryProcessor $queryProcessor | ||
* @param SuggestedQueries $suggestedQueries | ||
*/ | ||
public function __construct( | ||
QueryProcessor $queryProcessor, | ||
SuggestedQueries $suggestedQueries | ||
) { | ||
$this->queryProcessor = $queryProcessor; | ||
$this->suggestedQueries = $suggestedQueries; | ||
} | ||
|
||
/** | ||
* Return search suggestions for the provided query text | ||
* | ||
* @param ContextInterface $context | ||
* @param string $queryText | ||
* @return array | ||
*/ | ||
public function execute(ContextInterface $context, string $queryText) : array | ||
{ | ||
$result = []; | ||
$query = $this->queryProcessor->prepare($context, $queryText); | ||
$suggestionItems = $this->suggestedQueries->getItems($query); | ||
foreach ($suggestionItems as $suggestion) { | ||
$result[] = ['search' => $suggestion->getQueryText()]; | ||
} | ||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.