/** * Parses the given date query term into a date representation * * @param dateQueryTerm the date query term as string * @return the milliseconds since 1970 of the given dateQueryTerm * @throws ParseException if the term could not be parsed */ private long parseDate(String dateQueryTerm) throws ParseException { return new DateMathParser().parseMath(dateQueryTerm).getTime(); }
/** * Parses the timeSeriesAge term with solr date math * * @return the end date for the range query * @throws ParseException if the term is not a solr date math expression */ private Date parseEndDate() throws ParseException { return new DateMathParser().parseMath(String.format("+0MILLISECOND-%s", timeSeriesAge)); }
private static boolean intervalDateFacetMatcher(String query) { Matcher dateMatcher = INTERVAL_DATE_FACET.matcher(query); if (dateMatcher.matches()) { DateMathParser solrDateMathParser = new DateMathParser(); try { String startDateMath = dateMatcher.group("dateMathStart"); if (startDateMath != null) { solrDateMathParser.parseMath(startDateMath); } String endDateMath = dateMatcher.group("dateMathStart"); if (endDateMath != null) { solrDateMathParser.parseMath(endDateMath); } } catch (ParseException e) { return false; } String startDate = dateMatcher.group("dateStart"); if (startDate != null) { DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(Long.valueOf(startDate))); } String endDate = dateMatcher.group("dateEnd"); if (endDate != null) { DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(Long.valueOf(endDate))); } return true; } else { return false; } }
/** * NOTE: declared as a method to allow for extensibility * @lucene.experimental * @return the result of evaluating a string */ protected Date evaluateString(String datemathfmt, Locale locale, TimeZone tz) { // note: DMP does not use the locale but perhaps a subclass might use it, for e.g. parsing a date in a custom // string that doesn't necessarily have date math? //TODO refactor DateMathParser.parseMath a bit to have a static method for this logic. if (datemathfmt.startsWith("NOW")) { datemathfmt = datemathfmt.substring("NOW".length()); } try { DateMathParser parser = new DateMathParser(tz); parser.setNow(new Date());// thus do *not* use SolrRequestInfo return parser.parseMath(datemathfmt); } catch (ParseException e) { throw wrapAndThrow(SEVERE, e, "Invalid expression for date"); } }
return new DateMathParser(TimeZone.getDefault()).parseMath(expr); } catch (ParseException exp) { throw new DataImportHandlerException(DataImportHandlerException.SEVERE,
final DateMathParser p = new DateMathParser(MATH_TZ, MATH_LOCALE);
if (maxCommitAge != null) { if (maxCommitAgeTimeStamp==-1) { DateMathParser dmp = new DateMathParser(DateField.UTC, Locale.US); maxCommitAgeTimeStamp = dmp.parseMath(maxCommitAge).getTime();
public static <T> Interval<DateMathExpression> intervalDateFacetMapper(String name, String query) { final Matcher dateMatcher = INTERVAL_DATE_FACET.matcher(query); if (dateMatcher.matches()) { final DateMathParser solrDateMathParser = new DateMathParser();
final DateMathParser p = new DateMathParser(MATH_TZ, MATH_LOCALE);
final DateMathParser dmp = new DateMathParser(ft.UTC, Locale.US); dmp.setNow(NOW);