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.