1

I am using SXA's search results and dropdown filter to be able to filter items on the search scope by their parent item display name.

I have it sort of working by first creating a Computed Index field for the title / display name:

public class ParentTitle : AbstractComputedIndexField
{
    public override object ComputeFieldValue(IIndexable indexable)
    {
        var obj = (Item)(indexable as SitecoreIndexableItem);
        if (!string.IsNullOrEmpty(obj?.Parent?["Title"]))
            return (object)obj?.Parent?["Title"];
        if (!string.IsNullOrEmpty(obj?.Parent?["__Display Name"]))
            return (object)obj?.Parent?["__Display Name"];
        return (object)false;
    }
}

I added the field to both Solr and Azure Search configs and confirmed they are indexing correctly.

Azure:

<fieldMap type="Sitecore.ContentSearch.Azure.FieldMaps.CloudFieldMap, Sitecore.ContentSearch.Azure">
    <fieldNames hint="raw:AddFieldByFieldName">
        <field fieldName="parenttitle" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.Azure.CloudSearchFieldConfiguration, Sitecore.ContentSearch.Azure" />
    </fieldNames>
</fieldMap>
<documentOptions type="Sitecore.ContentSearch.DocumentBuilderOptions, Sitecore.ContentSearch">
    <fields hint="raw:AddComputedIndexField">
      <field fieldName="parenttitle" returnType="string">Feature.ServiceLocator.Models.ComputedFields.ParentTitle, Feature.ServiceLocator</field>
    </fields>
</documentOptions>

Solr:

<documentOptions type="Sitecore.ContentSearch.SolrProvider.SolrDocumentBuilderOptions, Sitecore.ContentSearch.SolrProvider">
    <fields hint="raw:AddComputedIndexField">
        <field fieldName="parenttitle" returnType="string">Feature.ServiceLocator.Models.ComputedFields.ParentTitle, Feature.ServiceLocator</field>
    </fields>
</documentOptions>

Then I created a Facet on the parent title index field and added it to the dropdown filter.

However it does not filter properly on Azure Search due to the parent name having spaces or other characters such as a comma.

Sometimes on Azure Search it sort of works ok: e.g. "around the house" returns mostly the right results with a few extras that I assume are matching other parent titles

AzureSearch Query [sitecore_sxa_master_index]: &search=(parenttitle:(around%20the%20house) AND template_1:(bb0d12e06efe4895a21d9a44f271fcfc))&$filter=(latestversion_1 and (path_1/any(t:t eq 'f51e14d7e75b4846abddcdafd6d58cc8')) and searchable and (path_1/any(t:t eq '4aa9044620cd43fb8995b2f2eb54e733')))&queryType=full&$top=2147483647

However "mind, body and spirit" does not work - it returns all results:

AzureSearch Query [sitecore_sxa_master_index]: &search=((parenttitle:(for%20mind) OR parenttitle:(body%20and%20spirit)) AND template_1:(bb0d12e06efe4895a21d9a44f271fcfc))&$filter=(latestversion_1 and (path_1/any(t:t eq 'f51e14d7e75b4846abddcdafd6d58cc8')) and searchable and (path_1/any(t:t eq '4aa9044620cd43fb8995b2f2eb54e733')))&queryType=full&$top=2147483647

On Solr it populates the dropdown field correctly, but does not actually return any results. I can see the XHR request returning 0 results.

How do I change the logic so that it is filtering on the parent item ID and just using the parent title for display purposes only? If that's not possible then I'd be interested in any other workarounds? I could add new fields to the actual search result items if that would help.

  • 1
    Are you trying to do an exact match on mind, body and spirit ? Also, can you show your config? What settings for the tokenizer do you have for that field? – Richard Seal Aug 7 at 13:46
  • 1
    What kind of SXA version are you using? I had similar issues some months ago. There are bugs in the facet filter checkbox and has to do with upper/lowercase. The other - as you already mentioned - is when the facet value contains spaces. When you filter on "around the house" it will match every parent containing "around" and "the" and "house". It has to do with the tokenizer. Unfortunately I left the project before the issues were resolved. Sitecore support is already aware of these issues. – Mathijs Vlasveld Aug 7 at 14:20
  • I have the same issue on SXA 1.7 and 1.9 (just upgrading it and was hoping it was fixed). – Mark Gibbons Aug 7 at 22:41
  • Thanks @RichardSeal you helped me fix Azure, but solr is actually not returning any results but the drop down looks correct – Mark Gibbons Aug 8 at 0:43
1

Thanks to Richard Seal for getting me to have a look at the azure config again.

I changed it to add facetable etc attributes as well as the language analyzer which has fixed the issue for Azure Search.

<fieldMap type="Sitecore.ContentSearch.Azure.FieldMaps.CloudFieldMap, Sitecore.ContentSearch.Azure">
    <fieldNames hint="raw:AddFieldByFieldName">
        <field fieldName="parenttitle" searchable="YES" retrievable="YES" facetable="YES" filterable="YES" sortable="YES" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.Azure.CloudSearchFieldConfiguration, Sitecore.ContentSearch.Azure" cloudAnalyzer="language"/>
    </fieldNames>
</fieldMap>

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.