/** for testing DateTools support */ private String getDate(String s, DateResolution resolution) { // we use the default Locale since LuceneTestCase randomizes it //DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()); //return getDate(df.parse(s), resolution); return(getDate(DateTime.ParseExact(s, "d", CultureInfo.CurrentCulture), resolution)); }
public override void SetDateResolution(ICommonQueryParserConfiguration cqpC, string field, DateResolution value) { if (Debugging.AssertsEnabled) { Debugging.Assert(cqpC is StandardQueryParser); } StandardQueryParser qp = (StandardQueryParser)cqpC; qp.DateResolutionMap.Put(field, value); }
public void assertDateRangeQueryEquals(PrecedenceQueryParser qp, String field, String startDate, String endDate, DateTime endDateInclusive, DateResolution resolution) { assertQueryEquals(qp, field, field + ":[" + escapeDateString(startDate) + " TO " + escapeDateString(endDate) + "]", "[" + getDate(startDate, resolution) + " TO " + getDate(endDateInclusive, resolution) + "]"); assertQueryEquals(qp, field, field + ":{" + escapeDateString(startDate) + " TO " + escapeDateString(endDate) + "}", "{" + getDate(startDate, resolution) + " TO " + getDate(endDate, resolution) + "}"); }
/** for testing DateTools support */ private String getDate(DateTime d, DateResolution resolution) { return(DateTools.DateToString(d, resolution)); }
public IBooleanOperation Range(string fieldName, DateTime lower, DateTime upper, bool includeLower, bool includeUpper, DateResolution resolution) { return(this.SearchCriteria.Range(fieldName, lower, upper, includeLower, includeUpper, resolution)); }
/// <summary> /// Returns the date format string for the specified <paramref name="resolution"/> /// or <c>null</c> if the resolution is invalid. /// </summary> private static string ToDateFormat(DateResolution resolution) => resolution switch {
/// <summary> /// Ranges the specified field name. /// </summary> /// <param name="fieldName">Name of the field.</param> /// <param name="start">The start.</param> /// <param name="end">The end.</param> /// <param name="includeLower">if set to <c>true</c> [include lower].</param> /// <param name="includeUpper">if set to <c>true</c> [include upper].</param> /// <param name="resolution">The resolution.</param> /// <returns></returns> public IBooleanOperation Range(string fieldName, DateTime start, DateTime end, bool includeLower, bool includeUpper, DateResolution resolution) { return this.search.Range(fieldName, start, end, includeLower, includeUpper); }
public IBooleanOperation Range(string fieldName, DateTime start, DateTime end, bool includeLower, bool includeUpper, DateResolution resolution) { //By specifying the resolution we can do more accurate range searching on date fields DateTools.Resolution luceneResolution; switch (resolution) { case DateResolution.Year: luceneResolution = DateTools.Resolution.YEAR; break; case DateResolution.Month: luceneResolution = DateTools.Resolution.MONTH; break; case DateResolution.Day: luceneResolution = DateTools.Resolution.DAY; break; case DateResolution.Hour: luceneResolution = DateTools.Resolution.HOUR; break; case DateResolution.Minute: luceneResolution = DateTools.Resolution.MINUTE; break; case DateResolution.Second: luceneResolution = DateTools.Resolution.SECOND; break; case DateResolution.Millisecond: default: luceneResolution = DateTools.Resolution.MILLISECOND; break; } //since lucene works on string's for all searching we need to flatten the date return(this.RangeInternal(fieldName, DateTools.DateToString(start, luceneResolution), DateTools.DateToString(end, luceneResolution), includeLower, includeUpper, _occurance)); }
/// <summary> /// Ranges the specified field name. /// </summary> /// <param name="fieldName">Name of the field.</param> /// <param name="start">The start.</param> /// <param name="end">The end.</param> /// <param name="includeLower">if set to <c>true</c> [include lower].</param> /// <param name="includeUpper">if set to <c>true</c> [include upper].</param> /// <param name="resolution">The resolution.</param> /// <returns></returns> public IBooleanOperation Range(string fieldName, DateTime start, DateTime end, bool includeLower, bool includeUpper, DateResolution resolution) { return(this.search.Range(fieldName, start, end, includeLower, includeUpper)); }
protected override IQueryNode PostProcessNode(IQueryNode node) { if (node is TermRangeQueryNode termRangeNode) { FieldQueryNode upper = (FieldQueryNode)termRangeNode.UpperBound; FieldQueryNode lower = (FieldQueryNode)termRangeNode.LowerBound; // LUCENENET specific - set to 0 (instead of null), since it doesn't correspond to any valid setting DateResolution dateRes = 0 /* = null*/; bool inclusive = false; CultureInfo locale = GetQueryConfigHandler().Get(ConfigurationKeys.LOCALE); if (locale == null) { locale = CultureInfo.CurrentCulture; //Locale.getDefault(); } TimeZoneInfo timeZone = GetQueryConfigHandler().Get(ConfigurationKeys.TIMEZONE); if (timeZone == null) { timeZone = TimeZoneInfo.Local; //TimeZone.getDefault(); } string field = termRangeNode.Field; string fieldStr = null; if (field != null) { fieldStr = field.ToString(); } FieldConfig fieldConfig = GetQueryConfigHandler() .GetFieldConfig(fieldStr); if (fieldConfig != null) { dateRes = fieldConfig.Get(ConfigurationKeys.DATE_RESOLUTION); } if (termRangeNode.IsUpperInclusive) { inclusive = true; } string part1 = lower.GetTextAsString(); string part2 = upper.GetTextAsString(); try { string shortDateFormat = locale.DateTimeFormat.ShortDatePattern; if (DateTime.TryParseExact(part1, shortDateFormat, locale, DateTimeStyles.None, out DateTime d1)) { part1 = DateTools.DateToString(d1, timeZone, dateRes); lower.Text = new StringCharSequence(part1); } if (DateTime.TryParseExact(part2, shortDateFormat, locale, DateTimeStyles.None, out DateTime d2)) { if (inclusive) { // The user can only specify the date, not the time, so make sure // the time is set to the latest possible time of that date to // really // include all documents: //Calendar cal = Calendar.getInstance(timeZone, locale); //cal.setTime(d2); //cal.set(Calendar.HOUR_OF_DAY, 23); //cal.set(Calendar.MINUTE, 59); //cal.set(Calendar.SECOND, 59); //cal.set(Calendar.MILLISECOND, 999); //d2 = cal.getTime(); d2 = TimeZoneInfo.ConvertTime(d2, timeZone); var cal = locale.Calendar; d2 = cal.AddHours(d2, 23); d2 = cal.AddMinutes(d2, 59); d2 = cal.AddSeconds(d2, 59); d2 = cal.AddMilliseconds(d2, 999); } part2 = DateTools.DateToString(d2, timeZone, dateRes); upper.Text = new StringCharSequence(part2); } } catch (Exception e) when(e.IsException()) { // do nothing } } return(node); }
public IBooleanOperation Range(string fieldName, DateTime start, DateTime end, bool includeLower, bool includeUpper, DateResolution resolution) { //By specifying the resolution we can do more accurate range searching on date fields DateTools.Resolution luceneResolution; switch (resolution) { case DateResolution.Year: luceneResolution = DateTools.Resolution.YEAR; break; case DateResolution.Month: luceneResolution = DateTools.Resolution.MONTH; break; case DateResolution.Day: luceneResolution = DateTools.Resolution.DAY; break; case DateResolution.Hour: luceneResolution = DateTools.Resolution.HOUR; break; case DateResolution.Minute: luceneResolution = DateTools.Resolution.MINUTE; break; case DateResolution.Second: luceneResolution = DateTools.Resolution.SECOND; break; case DateResolution.Millisecond: default: luceneResolution = DateTools.Resolution.MILLISECOND; break; } //since lucene works on string's for all searching we need to flatten the date return this.RangeInternal(fieldName, DateTools.DateToString(start, luceneResolution), DateTools.DateToString(end, luceneResolution), includeLower, includeUpper, _occurance); }