How to sort/filter search result in Sitecore SXA by __created date
or __updated date
to retrieve recent search items
2 Answers
Create facet item
- Navigate to your site facets node
/sitecore/content/tenant/site/Settings/Facets
- Add new item using following template
/sitecore/templates/Feature/Experience Accelerator/Search/Settings/Facets/DateFacet
- Fill field name with the name of the field stored in index. (In my case it will be
movie_released
as I am showing you configuration from my example site)
Add rendering to a page
- Open page where you want to display results
- Add Search Results rendering (will be used to display sorted results)
- Add Sort Results rendering. When adding create new data source item for it (template:
/sitecore/templates/Feature/Experience Accelerator/Search/Datasource/SortingGroups
). - Next create your filter configuration items under datasource created above. You can do it in CE.
Fields:
- Title - used for displaying purposes
- Facet - select your date facet that you create in step 1.
- Direction - there are two directions: ascending and descending. Normally you create two option items for a single facet, on for asc. and another for desc. order.
Summary
Once you configure everything properly you should be able to sort your results using different drop down options. See example:
If you are new to SXA you can learn how to use different renderings from XA.Reference. I created a reference site which shows how to configure every rendering in SXA. It is standard Sitecore package with example site inside.
Latest release supports SXA 1.2
-
1It works properly when i am creating facet with my custom date field but its not working with __created and __updated date field facet. Thanks for your valuable time– mahboobCommented May 22, 2017 at 9:19
-
1Make sure that the name of the field is valid (it is not always the same as field name taken from Sitecore item). For fields you are trying to use it will be:
__smallcreateddate
,__smallupdateddate
. You will find those field definitions in configuration. Commented May 22, 2017 at 10:29 -
To be able to sort by date you have to create a facet for your date field. Then you can use that facet as a default sort order in the Sort Results rendering. You can also use Sort Results rendering.
-
It works properly when i am creating facet with my custom date field but its not working with __created and __updated date field facet. Thanks for your valuable time– mahboobCommented May 22, 2017 at 9:20
-
1Ensure that you are using proper case of letters, those fields are called __Created and __Updated. Commented May 22, 2017 at 11:13