Lucene.Net.QueryParsers.QueryParser.GetRangeQuery C# (CSharp) Method

GetRangeQuery() protected method

throw in overridden method to disallow ///
protected GetRangeQuery ( String field, String part1, String part2, bool inclusive ) : Query
field String
part1 String
part2 String
inclusive bool
return Lucene.Net.Search.Query
        protected internal virtual Query GetRangeQuery(String field,
                                      String part1,
                                      String part2,
                                      bool inclusive)
        {
            if (lowercaseExpandedTerms)
            {
                part1 = part1.ToLower();
                part2 = part2.ToLower();
            }

            try
            {
                DateTime d1, d2;
                if (_useJavaStyleDateRangeParsing)
                {
                    // TODO: This doesn't emulate java perfectly.
                    // Java allows parsing of the string up to the end of the pattern
                    // and then ignores everything else.  .NET will throw an exception, 
                    // so this will fail in those cases, though the code below is clear
                    // that users can only specify the date, not the time.
                    var shortFormat = locale.DateTimeFormat.ShortDatePattern;
                    d1 = DateTime.ParseExact(part1, shortFormat, locale);
                    d2 = DateTime.ParseExact(part2, shortFormat, locale);
                }
                else
                {
                    d1 = DateTime.Parse(part1, locale);
                    d2 = DateTime.Parse(part2, locale);
                }

                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:
                    var cal = locale.Calendar;
                    d2 = cal.AddHours(d2, 23);
                    d2 = cal.AddMinutes(d2, 59);
                    d2 = cal.AddSeconds(d2, 59);
                    d2 = cal.AddMilliseconds(d2, 999);
                }
                DateTools.Resolution resolution = getDateResolution(field);
                if (resolution == null)
                {
                    // no default or field specific date resolution has been set,
                    // use deprecated DateField to maintain compatibility with
                    // pre-1.9 Lucene versions.
                    part1 = DateField.DateToString(d1);
                    part2 = DateField.DateToString(d2);
                }
                else
                {
                    part1 = DateTools.DateToString(d1, resolution);
                    part2 = DateTools.DateToString(d2, resolution);
                }
            }
            catch (Exception)
            {
            }

            return NewRangeQuery(field, part1, part2, inclusive);
        }