To enable sorting by updated date in Sitecore you will need to first, add the __smallupdateddate field to your search Model. Please note that this is small updated date... and is a default field that is included in the Lucene index.
[IndexField("__smallupdateddate")]Once this has been added, you can then sort by this with your search query:
public DateTime LastUpdated { get; set; }
searchResults = searchContext.GetQueryable<SearchModel>().Filter(searchPredicate).OrderBy(x => x.LastUpdated);For more complex logic such as Google's last year filtering, you could use the where clause in your search logic:
.Where(x => x.LastUpdated >= DateTime.Now.AddYears(-1))
No comments:
Post a Comment