1

We are using Sitecore Experience Commerce 9 and SXA 1.6. We are using Azure Search. In the Search results page, we are using the Facets (Settings/Facets) with PageType for categorizing and it is configured with Field value as "_templatename" as shown in the screenshot. This will categorize the results based on the templates the search result pages are built of. We find that some of the templates are very generic and end users do not find it useful. I would like to know if we can remove one or two templates from the Search filter by changing the OOTB setup in Sitecore.

Any hints would be appreciated

enter image description here

  • Update-1 I have implemented the changes suggested by @Gatogordo. fieldname used in the config file is used in the "Field Name" of facet

enter image description here

And I am getting the Checklist filter as below:

enter image description here

Here is the same code that I used with very minor alteration:

    public object ComputeFieldValue(IIndexable indexable)
    {
        var indexableItem = indexable as SitecoreIndexableItem;
        if (indexableItem == null)
        {
            return null;
        }

        var item = indexableItem.Item;

        //get value based on item.TemplateName
        var value = item.TemplateName;
        if (!string.IsNullOrEmpty(value))
            return value;
        else
            return "";
    }
0

I had a similar request lately and created a partly custom solution. I also had to create a facet to show the "type", which -almost- related to the template. Using the template name seems like an option, but this way your end users will see the actual template names and those might not be so user friendly (and if you need them translated it will become even more difficult).

What we did: we created a custom field in the index (computed field) that stored a value based on the template. The value is actually just a dictionary value. This way we can translate them, we can also give different templates the same value if we want..

For the facet, we pointed towards this computed field. And that worked fine.

Code skeleton:

public class ContentTypeComputedField : IComputedIndexField
{     
    public ContentTypeComputedField()
    {
        ...
    }

    public object ComputeFieldValue(IIndexable indexable)
    {
        var indexableItem = indexable as SitecoreIndexableItem;
        if (indexableItem == null)
        {
            return null;
        }

        var item = indexableItem.Item;
        //get value based on item.TemplateName
        return value;
    }
}

You should add the logic to fetch the value. You might also want to add some code to get out of the code asap if not relevant (you don't want this on all your items).

For the configuration: you need to add this computed field to the SXA indexes (or to all if you want..) by adding the computed index field to the documentOptions section of the index configuration:

<fields hint="raw:AddComputedIndexField">
  <field fieldName="contenttypes" returnType="string" type="....ContentTypeComputedField, Assembly"/>
</fields>
  • Thank you very much. Do you mind sharing the skeleton of code snippet that you used for resolving this ? That will help me to reach the solution quickly. – Nebu Feb 11 at 13:50
  • Can you see my Update-1 in the description and provide your inputs ? @Gatogordo – Nebu Feb 14 at 6:07

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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