protected void ApplyDateRangeSearchParam(BooleanQuery query, DateRangeSearchParam param, BooleanClause.Occur innerOccurance) { if (param.Ranges.Count <= 0) return; foreach (var dateParam in param.Ranges) { AddDateRangeQuery(query, dateParam, innerOccurance); } }
protected void AddDateRangeQuery(BooleanQuery query, DateRangeSearchParam.DateRangeField dateRangeField, BooleanClause.Occur occurance) { var startDateTime = dateRangeField.StartDate; if (dateRangeField.InclusiveStart) { startDateTime = startDateTime.AddDays(1); } var startDate = startDateTime.ToString(IndexConstants.DateTimeFormat); var endDateTime = dateRangeField.EndDate; if (dateRangeField.InclusiveStart) { endDateTime = endDateTime.AddDays(1); } var endDate = endDateTime.ToString(IndexConstants.DateTimeFormat); var rangeQuery = new RangeQuery(new Term(dateRangeField.FieldName, startDate), new Term(dateRangeField.FieldName, endDate), true); query.Add(rangeQuery, occurance); }
public virtual List<SkinnyItem> GetItemsInRange(DateRangeSearchParam param) { var globalQuery = new CombinedQuery(); ApplyLanguageClause(globalQuery, param.Language); ApplyTemplateFilter(globalQuery, param.TemplateIds); ApplyLocationFilter(globalQuery, param.LocationIds); ApplyFullTextClause(globalQuery, param.FullTextQuery); var translator = new QueryTranslator(Index); var booleanQuery = translator.ConvertCombinedQuery(globalQuery); var innerOccurance = translator.GetOccur(param.Occurance); ApplyDateRangeSearchParam(booleanQuery, param, innerOccurance); return RunQuery(booleanQuery, param.ShowAllVersions); }