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"> <__SortOrder> <patch:delete/> </__SortOrder> </exclude>
The blog mentions you need to add the field as well, I'm not sure that is actually needed but just in case:
<sitecore> <contentSearch search:require="solr"> <indexConfigurations> <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" /> </fieldNames> </fieldMap> </defaultSolrIndexConfiguration> </indexConfigurations> </contentSearch> </sitecore>
All credits to Jorge Pimenta for writing the blog.