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.
mind, body and spirit
? Also, can you show your config? What settings for the tokenizer do you have for that field?