I am currently working on a project to implement Sitecore 7.0 Update 2
In my data template, I have this field "Start Date" and another end date. These two fields are created with type "Date" (not Datetime). Thus, it shows the date when I edit and create elements, and I submitted some elements with dummy content and with start and end dates from the last month and the current month.
What I want to achieve is to get all the items within the selected month. My method contains a month and an integer as a parameter. This should control elements with start and end dates that it should receive from Lucene sitecore_master_index. The raw Sitecore values for the Date field are ISO date and time strings.
So this is a query in which I try to get all the items from the selected month.
private void GetItems(int month, int year)
{
using (
IProviderSearchContext context =
ContentSearchManager.
GetIndex("sitecore_master_index").CreateSearchContext())
{
List<EventSearchResultItem> allEvents = context.GetQueryable<EventSearchResultItem>(new CultureExecutionContext(Sitecore.Context.Language.CultureInfo))
.Where(s =>
s.TemplateId == this.EventTemplateID &&
((s.BeginDate.Month == month && s.BeginDate.Year == year) || (s.EndDate.Month == month && s.EndDate.Year == year))
)
.ToList();
}
}
Where Events, . . , Lamba, , , . - 1 999 :) , IQueryable - , DateTime . , . , , TemplateID - Where-where, . BeginDate DateTime.MinValue DateTime.MaxValue .
EvenSearchResultItem POCO, . TypeConverter, DateTime. , ...
public class EventSearchResultItem : SearchResultItem
{
[TypeConverter(typeof(IndexFieldDateTimeValueConverter))]
[IndexField("__begin_date")]
public DateTime BeginDate { get; set; }
[TypeConverter(typeof(IndexFieldDateTimeValueConverter))]
[IndexField("__end_date")]
public DateTime EndDate { get; set; }
}
Sitecore.ContentSearch.Lucene.DefaultIndexConfiguration.config -tag ( -tag, , ).
:
<field luceneName="__begin_date" storageType="yes" indexType="tokenized" format="yyyyMMdd">Begin Date</field>
<field luceneName="__end_date" storageType="yes" indexType="tokenized" format="yyyyMMdd">End Date</field>
, Luke (Java- Lucene) ( yyyyMMdd > 20140214). , __smallCreatedDate.
, :
List<EventSearchResultItem> allEvents = context.GetQueryable<EventSearchResultItem>()
.Where(s =>
(s["Begin Date"].StartsWith(string.Concat(year, month.ToString("00"))) || s["End Date"].StartsWith(string.Concat(year, month.ToString("00"))))
)
.ToList();
, Stack Overflow. . , Google . , -, , ?
- Lucene- DateTime IQueryable? ?