0

I have a sxa search component with multiple facets. In one of the facets, there is an entry that has a filter value of "Corporate / M & A". It yield no result when I choose the facet with that value. enter image description here

I did play around on the filter text value and found out that the issue was the special characters '/' and '&'. Removing those characters yields results.

Is this an expected behavior in sxa search component? Would there be a work around for this scenario?

However. I did tried use the same search text to query directly in Solr and there was no issue. I was able to pull records.

sample solr query: solr_field:"Corporate / M & A" AND _language:"en"

sxa version: Sitecore Experience Accelerator 9.3.0.2589

Thanks in advance.

0

So far I have managed to pinpoint what is causing the issue on not returning search result when a facet value includes "/" and "&" characters.

Decompiling Sitecore.XA.Foundation.Search.dll helped me to see the pipelines used in search and facet filtering.

The culprit was Sitecore.XA.Foundation.Search.Pipelines.EncodeFacetValue.EscapeValue processor.

The processor looks like this:

public class EscapeValue : EncodeFacetValueProcessor
  {
    public override void Process(EncodeFacetValueArgs args)
    {
      args.EncodedValue = Uri.EscapeDataString(args.OriginalValue);
      args.EncodedValue = args.EncodedValue.Replace("%20", " ");
    }
  }

As seen in the code, the original facet value is being converted to its escaped representation. This is where the issue comes in.

Original value: args.OriginalValue = "Corporate / M & A":

Encoded value: args.EncodedValue = "Corporate%20%2F%20M%20%26%20A"

Final encoded value: args.EncodedValue = "Corporate %2F M %26 A"

The final encoded value is returned and used as search filter. Search filter yields no result due to encoded special characters.

Workaround:

I created a custom pipeline and patch this pipeline replacing the original pipeline.

public class EscapeValue : EncodeFacetValueProcessor
{
     public override void Process(EncodeFacetValueArgs args)
     {
          args.EncodedValue = args.OriginalValue;
     }
}

As the intended value search filter is the args.OriginalValue, I just assigned that value to args.EncodedValue.

I did some testing to make sure nothing is impacted as for my project is concern and I didn't find any.

I am pretty sure that there is an explanation why the facet value is being converted to its escaped representation which I don't know the answer yet.

But in my case the workaround works fine.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.