-
Notifications
You must be signed in to change notification settings - Fork 351
Description
Preconditions
Magento Version : 2.4.3
ElasticSuite Version : 2.10.9
Environment : Developer
Third party modules : many but doesn't seem to be involved in the bug.
Steps to reproduce
- Development mode.
- Remove generated DI files.
- Code:
$categoryCollectionFactory = $objectManager->create('Smile\ElasticsuiteCatalog\Model\ResourceModel\Category\Fulltext\CollectionFactory')
$categoryCollection = $categoryCollectionFactory->create();
$categoryCollection->addFieldToFilter('path', ['like' => '1/2/%']);
return $categoryCollection->getFirstItem();Expected result
- A search result.
Actual result
Exception
Missing required argument $values of Smile\ElasticsuiteCore\Search\Request\Query\Terms.
vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:264
The issue evolves in the following way:
- The
pathfield has the following definition:<field name="path" type="keyword" />. - This creates a
Smile\ElasticsuiteCore\Index\Mapping\Fieldobject with the default analyzer set tostandard. - The
Field::checkAnalyzer()method returns false (can't get the idea of this method). - It leads to returning null from the
Field::getMappingProperty()method. - In the
Smile\ElasticsuiteCore\Search\Request\Query\Filter\QueryBuilder::prepareFieldConditionthis loses the chance to switch the$queryTypevalue fromQueryInterface::TYPE_TERMStoQueryInterface::TYPE_MATCH. - Due to the query type set to
TYPE_TERMS, it then tries to instantiate aSmile\ElasticsuiteCore\Search\Request\Query\Termsobject through theMagento\Framework\ObjectManager\Factory\AbstractFactoryand passes the following parameters to it:Array ( [field] => path [queryText] => 1/2/% )
- As the
Query\Terms' constructor doesn't have the$queryTextargument, and the supplied array doesn't have thevalueskey, theMagento\Framework\ObjectManager\Factory\AbstractFactory::getResolvedArgument()throws theMissing required argument $values of Smile\ElasticsuiteCore\Search\Request\Query\Termsexception.
I suppose that ElasticSuite should set the query type to TYPE_MATCH in the Smile\ElasticsuiteCore\Search\Request\Query\Filter\QueryBuilder::prepareFieldCondition to pick the proper class Smile\ElasticsuiteCore\Search\Request\Query\MatchQuery which contains the $queryText constructor argument.
This exception doesn't happen when the DI container is compiled because Magento substitutes a null value to the Terms query class $values argument in that case. This leads to that it uses the Terms query object for the path field with the null query value which is wrong and doesn't reflect the intended filtering behavior.