SXA has Query Builder SXA Tokens that can be applied on Search Results. One of them is "Sort by children of page in content tree order". We want to build a similar functionality using Sxa Search Sort Results Component. Is there any way of doing it?


You need to use the __Sortorder field to sort on. That is y default not in your index though so you need to add that as well. The explanation can be found in detail on this blog: https://www.sitecoreinsiders.com/sxa-search-results-sorting-by-sortorder-field/

In case that disappears, this is the short version:

This field is being excluded from the index by default, so we must remove it from this list, by applying the following:

<exclude hint="list:AddExcludedField">

The blog mentions you need to add the field as well, I'm not sure that is actually needed but just in case:

  <contentSearch search:require="solr">
      <defaultSolrIndexConfiguration type="Sitecore.ContentSearch.SolrProvider.SolrIndexConfiguration, Sitecore.ContentSearch.SolrProvider">
        <fieldMap type="Sitecore.ContentSearch.SolrProvider.SolrFieldMap, Sitecore.ContentSearch.SolrProvider">
          <fieldNames hint="raw:AddFieldByFieldName">              
            <field fieldName="__Sortorder" returnType="long" />

Now you can use this field to sort on. First create a facet for the __Sortorder field: enter image description here

Then create the sort with this facet: enter image description here

And then you can use this in the search results component sort order field: enter image description here

All credits to Jorge Pimenta for writing the blog.

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.