Skip to content

GraphQL "match" filters on custom attributes not working #3740

@aligent-lturner

Description

@aligent-lturner

When attempting to pass a filter on a custom text attribute for the products query, no results are returned. In development mode (without compile di, an exception is thrown).

Preconditions

Magento Version : 2.4.8

ElasticSuite Version : 2.11.15.1

Environment : Both

Third party modules : None related

Steps to reproduce

  1. Create a custom text attribute, and make it filterable in search.
  2. Assign different values to products for the attribute
  3. Attempt to filter by the attribute - e.g.
products(
  filter: {
    my_attribute: {
      match: "some value"
    }
  }

Expected result

  1. Products matching the filter value are returned

Actual result

  1. In production mode, with compiled di, no results are returned
  2. In developer mode, an exception is thrown:
{
  "errors": [
    {
      "message": "Internal server error",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "products"
      ],
      "extensions": {
        "debugMessage": "Missing required argument $values of Smile\\ElasticsuiteCore\\Search\\Request\\Query\\Terms."
      }
    }
  ],
  "data": {
    "products": null
  }
}

Additional Information

This appears to be the same (or very similar to) #2430
I'm not sure, but I believe that the issue is with these lines:

if ($condition['field'] === null || isset($condition['queryText'])) {
$analyzer = $field->getDefaultSearchAnalyzer();
$property = $field->getMappingProperty($analyzer);
if ($property) {
$condition['field'] = $property;
if (isset($condition['queryText'])) {
$queryType = QueryInterface::TYPE_MATCH;
$condition['minimumShouldMatch'] = '100%';
}
}
}

If getMappingProperty returns null, then the check for $condition['queryText'] never happens. It would make sense to me for that if statement to be outside of the check for $property:

        if ($condition['field'] === null || isset($condition['queryText'])) {
            $analyzer = $field->getDefaultSearchAnalyzer();
            $property = $field->getMappingProperty($analyzer);
            if ($property) {
                $condition['field'] = $property;
            }
            if (isset($condition['queryText'])) {
                $queryType = QueryInterface::TYPE_MATCH;
                $condition['minimumShouldMatch'] = '100%';
            }
        }

When I tried this locally, it seemed to work ok, but I'm not sure if there's a better way to fix the issue (e.g. something within the getMappingProperty function.

Metadata

Metadata

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