Equals (EQ) operator works as Contains operator for text fields when sending GraphQL queries


Description

When requesting an item with a text field using the Equals (EQ) operator, it works as the Contains operator for text fields. The issue is related to the Edge (Preview) schema and the fact that all text fields in the Solr index are tokenized by default.

This issue affects Sitecore XP and SitecoreAI.

Solution for Sitecore XP

To resolve the issue, take the following steps:

  1. Download and install the cumulative hotfixes for the Experience Edge Connector module that are available in:
    • For Sitecore XP 10.4 and Sitecore Headless Rendering 22KB1003203
    • For Sitecore XP 10.3 and Sitecore Headless Rendering 21KB1003184
    • For Sitecore XP 10.1 and Sitecore Headless Rendering 18: KB1003204
    The core elements of the fix (including assemblies and core configurations) are included in the module package. These updates allow you to map any search field for custom computed fields that do not use the Standard Tokenizer, such as lowercaseString. Nevertheless, additional configuration from step 2 is required to complete the setup.

  2. Perform the setup as follows:
    1. In the /App_Config/Sitecore/Services.GraphQL folder, find the example configuration file named Sitecore.Services.GraphQL.EdgeContent.SearchFieldMapping.config.example.
    2. Rename this file to Sitecore.Services.GraphQL.EdgeContent.SearchFieldMapping.config.
    3. Find the _customname field inside the file, which is the same as _name, but untokenized. This serves as an example for your configuration. To add new fields, follow the same pattern: create new computed fields and add them to the setFieldMapping node in the configuration file.
    4. Rebuild the index after making all the changes.
    Note: The _name can still be used in your search queries. However, it will be internally mapped to _customname.

Solution for SitecoreAI

To resolve the issue, take the following steps:

  1. Create a configuration patch file based on the following code sample. This configuration allow you to map any search field for custom computed fields that do not use the Standard Tokenizer, such as lowercaseString. Note that additional configuration from step 2 given below is required to complete the setup.
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
        <sitecore>
            <contentSearch>
                <indexConfigurations>
                    <defaultSolrIndexConfiguration>
                        <documentOptions type="Sitecore.ContentSearch.SolrProvider.SolrDocumentBuilderOptions, Sitecore.ContentSearch.SolrProvider">
                            <fields hint="raw:AddComputedIndexField">
                                <field fieldName="_customName" returnType="lowercaseString" type="Sitecore.Services.GraphQL.EdgeSchema.ComputedFields.CustomNameComputedField, Sitecore.Services.GraphQL.EdgeSchema" />
                            </fields>
                        </documentOptions>
                    </defaultSolrIndexConfiguration>
                </indexConfigurations>
            </contentSearch>
            <api>
                <GraphQL>
                    <setFieldMapping type="Sitecore.Services.GraphQL.EdgeSchema.Services.SearchQueryFieldMapping.FieldMapping, Sitecore.Services.GraphQL.EdgeSchema">
                        <fieldMapping hint="list:AddFieldMapping">
                            <fieldMappingModel fieldName="_name" type="Sitecore.Services.GraphQL.EdgeSchema.Services.SearchQueryFieldMapping.FieldMappingModel, Sitecore.Services.GraphQL.EdgeSchema">
                                <fieldName>_name</fieldName>
                                <mappingField>_customname</mappingField>
                            </fieldMappingModel>
                        </fieldMapping>
                    </setFieldMapping>
                </GraphQL>
            </api>
        </sitecore>
    </configuration>
  2. Perform the setup as follows:
    1. Find the _customname field inside the the sample, which is the same as _name but untokenized. This serves as an example for your configuration. To add new fields, follow the same pattern: create new computed fields and add them to the setFieldMapping node in the configuration file.
    2. Rebuild the index after making all the changes.

    Note: The _name field can still be used in search queries. However, it will be internally mapped to _customname.