Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Root>/sitecore/content/Articles</Root>
- public class Article : SearchResultItem
- {
- [IndexField("_uniqueid")]
- public string ItemPath { get; set; }
- [IndexField("_group")]
- public string Id { get; set; }
- [IndexField("title")]
- public string Title { get; set; }
- [IndexField("publisheddate")]
- public DateTime PublishedDate { get; set; }
- [IndexField("summary")]
- public string Summary { get; set; }
- }
- list.Where(c => c.PublishedDate.Year == 2017).ToList();
- public class ComputedYearField: IComputedIndexField
- {
- public string FieldName { get; set; }
- public string ReturnType { get; set; }
- public object ComputeFieldValue(IIndexable indexable) {
- Item item = (indexable as SitecoreIndexableItem);
- if (item != null)
- {
- // check if item is an Article
- if(item.TemplateID == "YOURARTICLETEMPLATEID")
- {
- // extract the year from PublishDate field
- var dateField = (DateField)item.Fields["PublishedDate"];
- var itemDate = Sitecore.DateUtil.IsoDateToDateTime(dateField.Value);
- return itemDate.Year
- }
- }
- return null;
- }
- }
- <fields hint="raw:AddComputedIndexField">
- <field fieldName="ComputedYear" returnType="int">
- MyProjectNamespace.ComputedYearField,MyProjectNamespace
- </field>
- </fields>
- list.Where(c => c.ComputedYear == 2017).ToList();
- var dateStart = new DateTime(year, 1, 1);
- var dateEnd = new DateTime(year, 12, DateTime.DaysInMonth(year,12));
- list.Where(x => x.Date.Between(dateStart, dateEnd, Inclusion.Both));
- // or
- // list.Where(x => x.Date>=dateStart && x.Date<=dateEnd);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement