Skip to content

A like filter resolves to the incorrect query type causing an exception in development mode #2430

@speller

Description

@speller

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

  1. 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 path field has the following definition: <field name="path" type="keyword" />.
  • This creates a Smile\ElasticsuiteCore\Index\Mapping\Field object with the default analyzer set to standard.
  • 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::prepareFieldCondition this loses the chance to switch the $queryType value from QueryInterface::TYPE_TERMS to QueryInterface::TYPE_MATCH.
  • Due to the query type set to TYPE_TERMS, it then tries to instantiate a Smile\ElasticsuiteCore\Search\Request\Query\Terms object through the Magento\Framework\ObjectManager\Factory\AbstractFactory and passes the following parameters to it:
    Array
    (
      [field] => path 
      [queryText] => 1/2/%
    )
  • As the Query\Terms' constructor doesn't have the $queryText argument, and the supplied array doesn't have the values key, the Magento\Framework\ObjectManager\Factory\AbstractFactory::getResolvedArgument() throws the Missing required argument $values of Smile\ElasticsuiteCore\Search\Request\Query\Terms exception.

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions