When it comes to sorting SXA Search Results, Sitecore has many ways of sorting the results.
But what if the user wants to sort the results like they are sorted in the content tree?
The items in the Content tree are sort by the “__Sortorder” field when we move an item, and we can do the same in the search results.
First, we have to add the field to the index, by adding the following patch.
<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>
But that’s not enough because 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 final patch will look like this.
<?xml version="1.0"?> <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:search="http://www.sitecore.net/xmlconfig/search/"> <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> <documentOptions type="Sitecore.ContentSearch.SolrProvider.SolrDocumentBuilderOptions, Sitecore.ContentSearch.SolrProvider"> <exclude hint="list:AddExcludedField"> <__SortOrder> <patch:delete/> </__SortOrder> </exclude> </documentOptions> </defaultSolrIndexConfiguration> </indexConfigurations> </contentSearch> </sitecore> </configuration>
Now we create our facet to point it to the _Sortorder field

Add the facet to the Sorting Group

And select it on the Search Results component properties.

And here you have it, the results are now being sorted with the same order as the content tree


By changing the order of an item the order in the SXA Search Results component will also change.



My man! Doing SXA so that we don’t have to!
Hi Jorge,
What if the default sortorder field is empty?