List of usage examples for java.util Calendar getMaximum
public abstract int getMaximum(int field);
Calendar
instance. From source file:com.ecofactor.qa.automation.api.ReportsAPITest.java
/** * Gets the month params./* w ww . j a v a 2 s . c o m*/ * @param month the month * @return the month params */ private HashMap<String, String> getMonthParams(int month) { HashMap<String, String> params = new HashMap<String, String>(); Calendar start = DateUtil.getUTCCalendar(); start.set(Calendar.MONTH, month - 1); start.set(Calendar.DATE, 1); start.set(Calendar.HOUR, 12); start.set(Calendar.MINUTE, 0); start.set(Calendar.SECOND, 0); start.set(Calendar.AM_PM, 0); Calendar end = DateUtil.getUTCCalendar(); end.set(Calendar.MONTH, month - 1); end.set(Calendar.DATE, end.getMaximum(Calendar.DATE)); end.set(Calendar.HOUR, 12); end.set(Calendar.MINUTE, 0); end.set(Calendar.SECOND, 0); start.set(Calendar.AM_PM, 0); params.put(ReportsAPIConfig.START_DATE, DateUtil.format(start, DateUtil.DATE_FMT)); params.put(ReportsAPIConfig.END_DATE, DateUtil.format(end, DateUtil.DATE_FMT)); params.put(ReportsAPIConfig.INTERVAL, "MONTHS"); return params; }
From source file:com.ecofactor.qa.automation.api.HttpsReportsAPITest.java
/** * Gets the accumulated params.//from w w w . j a va 2 s .c om * @param month the month * @return the accumulated params */ private HashMap<String, String> getAccumulatedParams(int month) { HashMap<String, String> params = new HashMap<String, String>(); Calendar start = DateUtil.getUTCCalendar(); start.set(Calendar.MONTH, month - 1); start.set(Calendar.DATE, 1); Calendar end = DateUtil.getUTCCalendar(); end.set(Calendar.MONTH, month - 1); end.set(Calendar.DATE, end.getMaximum(Calendar.DATE)); params.put(HttpsReportsAPIConfig.START_DATE, DateUtil.format(start, DateUtil.DATE_FMT)); params.put(HttpsReportsAPIConfig.END_DATE, DateUtil.format(end, DateUtil.DATE_FMT)); params.put(HttpsReportsAPIConfig.ACCUMULATED, "true"); return params; }
From source file:com.ecofactor.qa.automation.api.HttpsReportsAPITest.java
/** * Gets the not accumulated params.//from www . j a va2 s . c o m * @param month the month * @return the not accumulated params */ private HashMap<String, String> getNotAccumulatedParams(int month) { HashMap<String, String> params = new HashMap<String, String>(); Calendar start = DateUtil.getUTCCalendar(); start.set(Calendar.MONTH, month - 1); start.set(Calendar.DATE, 1); Calendar end = DateUtil.getUTCCalendar(); end.set(Calendar.MONTH, month - 1); end.set(Calendar.DATE, end.getMaximum(Calendar.DATE)); params.put(HttpsReportsAPIConfig.START_DATE, DateUtil.format(start, DateUtil.DATE_FMT)); params.put(HttpsReportsAPIConfig.END_DATE, DateUtil.format(end, DateUtil.DATE_FMT)); params.put(HttpsReportsAPIConfig.ACCUMULATED, "false"); return params; }
From source file:com.ecofactor.qa.automation.api.HttpsReportsAPITest.java
/** * Location savings./*from w w w . j a va 2 s. c om*/ */ @Test(groups = { "sanity1" }) public void locationSavings() { String id = reportsAPIConfig.get(HttpsReportsAPIConfig.LOCATION_ID); String content = HttpsUtil.get(getLocationSavingsURL(id), getNotAccumulatedParams(5), 200); JSONObject object = JsonUtil.parseObject(content); Calendar start = DateUtil.getUTCCalendar(); start.set(Calendar.MONTH, 5 - 1); start.set(Calendar.DATE, 1); start.set(Calendar.HOUR, 0); start.set(Calendar.MINUTE, 0); start.set(Calendar.SECOND, 0); Calendar end = DateUtil.getUTCCalendar(); end.set(Calendar.MONTH, 5 - 1); end.set(Calendar.DATE, end.getMaximum(Calendar.DATE)); end.set(Calendar.HOUR, 23); end.set(Calendar.MINUTE, 59); end.set(Calendar.SECOND, 0); assertLocationSavingsData(object, start, end); }
From source file:com.ecofactor.qa.automation.api.HttpsReportsAPITest.java
/** * User savings.// ww w .j a v a2 s . c om */ @Test(groups = { "sanity1" }) public void userSavings() { String id = reportsAPIConfig.get(HttpsReportsAPIConfig.USER_ID); String content = HttpsUtil.get(getUserSavingsURL(id), getNotAccumulatedParams(5), 200); JSONObject object = JsonUtil.parseObject(content); Calendar start = DateUtil.getUTCCalendar(); start.set(Calendar.MONTH, 5 - 1); start.set(Calendar.DATE, 1); start.set(Calendar.HOUR, 0); start.set(Calendar.MINUTE, 0); start.set(Calendar.SECOND, 0); Calendar end = DateUtil.getUTCCalendar(); end.set(Calendar.MONTH, 5 - 1); end.set(Calendar.DATE, end.getMaximum(Calendar.DATE)); end.set(Calendar.HOUR, 23); end.set(Calendar.MINUTE, 59); end.set(Calendar.SECOND, 0); assertUserSavingsData(object, start, end); }
From source file:com.ecofactor.qa.automation.api.HttpsReportsAPITest.java
/** * User savings accumulated./*from ww w . j a v a 2 s . co m*/ */ @Test(groups = { "sanity1" }) public void userSavingsAccumulated() { String id = reportsAPIConfig.get(HttpsReportsAPIConfig.USER_ID); String content = HttpsUtil.get(getUserSavingsURL(id), getAccumulatedParams(5), 200); JSONObject object = JsonUtil.parseObject(content); Calendar start = DateUtil.getUTCCalendar(); start.set(Calendar.MONTH, 5 - 1); start.set(Calendar.DATE, 1); start.set(Calendar.HOUR, 0); start.set(Calendar.MINUTE, 0); start.set(Calendar.SECOND, 0); Calendar end = DateUtil.getUTCCalendar(); end.set(Calendar.MONTH, 5 - 1); end.set(Calendar.DATE, end.getMaximum(Calendar.DATE)); end.set(Calendar.HOUR, 23); end.set(Calendar.MINUTE, 59); end.set(Calendar.SECOND, 0); assertAccumulatedUserSavingsData(object, start, end); }
From source file:com.ecofactor.qa.automation.api.HttpsReportsAPITest.java
/** * Gets the month params.//from w ww .j a v a 2 s. c om * @param month the month * @return the month params */ private HashMap<String, String> getMonthParams(int month) { HashMap<String, String> params = new HashMap<String, String>(); Calendar start = DateUtil.getUTCCalendar(); start.set(Calendar.MONTH, month - 1); start.set(Calendar.DATE, 1); start.set(Calendar.HOUR, 12); start.set(Calendar.MINUTE, 0); start.set(Calendar.SECOND, 0); start.set(Calendar.AM_PM, 0); Calendar end = DateUtil.getUTCCalendar(); end.set(Calendar.MONTH, month - 1); end.set(Calendar.DATE, end.getMaximum(Calendar.DATE)); end.set(Calendar.HOUR, 12); end.set(Calendar.MINUTE, 0); end.set(Calendar.SECOND, 0); end.set(Calendar.AM_PM, 0); params.put(HttpsReportsAPIConfig.START_DATE, DateUtil.format(start, DateUtil.DATE_FMT)); params.put(HttpsReportsAPIConfig.END_DATE, DateUtil.format(end, DateUtil.DATE_FMT)); params.put(HttpsReportsAPIConfig.INTERVAL, "MONTHS"); return params; }
From source file:org.alfresco.solr.query.Solr4QueryParser.java
private Pair<Date, Integer> parseDateString(String dateString) { try {/* w ww .ja v a2 s .c o m*/ Pair<Date, Integer> result = CachingDateFormat.lenientParse(dateString, Calendar.YEAR); return result; } catch (java.text.ParseException e) { SimpleDateFormat oldDf = CachingDateFormat.getDateFormat(); try { Date date = oldDf.parse(dateString); return new Pair<Date, Integer>(date, Calendar.SECOND); } catch (java.text.ParseException ee) { if (dateString.equalsIgnoreCase("min")) { Calendar cal = Calendar.getInstance(I18NUtil.getLocale()); cal.set(Calendar.YEAR, cal.getMinimum(Calendar.YEAR)); cal.set(Calendar.DAY_OF_YEAR, cal.getMinimum(Calendar.DAY_OF_YEAR)); cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE)); cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND)); return new Pair<Date, Integer>(cal.getTime(), Calendar.MILLISECOND); } else if (dateString.equalsIgnoreCase("now")) { return new Pair<Date, Integer>(new Date(), Calendar.MILLISECOND); } else if (dateString.equalsIgnoreCase("today")) { Calendar cal = Calendar.getInstance(I18NUtil.getLocale()); cal.setTime(new Date()); cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE)); cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND)); return new Pair<Date, Integer>(cal.getTime(), Calendar.DAY_OF_MONTH); } else if (dateString.equalsIgnoreCase("max")) { Calendar cal = Calendar.getInstance(I18NUtil.getLocale()); cal.set(Calendar.YEAR, cal.getMaximum(Calendar.YEAR)); cal.set(Calendar.DAY_OF_YEAR, cal.getMaximum(Calendar.DAY_OF_YEAR)); cal.set(Calendar.HOUR_OF_DAY, cal.getMaximum(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cal.getMaximum(Calendar.MINUTE)); cal.set(Calendar.SECOND, cal.getMaximum(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND)); return new Pair<Date, Integer>(cal.getTime(), Calendar.MILLISECOND); } else { return null; // delegate to SOLR date parsing } } } }
From source file:org.alfresco.repo.search.impl.lucene.AbstractLuceneQueryParser.java
private Query buildStart(String field, Calendar cal, int startField, int padField, int resolutionField) { BooleanQuery range = new BooleanQuery(); // only ms difference Query part;/*from w ww. java2 s. co m*/ switch (startField) { case Calendar.YEAR: if ((cal.get(Calendar.YEAR) == 1) && (cal.get(Calendar.MONTH) == 0) && (cal.get(Calendar.DAY_OF_MONTH) == 1) && (cal.get(Calendar.HOUR_OF_DAY) == 0) && (cal.get(Calendar.MINUTE) == 0) && (cal.get(Calendar.SECOND) == 0) && (cal.get(Calendar.MILLISECOND) == 0)) { if (padField == Calendar.MONTH) { if (Calendar.YEAR <= resolutionField) { part = new TermQuery(new Term(field, "YE" + cal.get(Calendar.YEAR))); range.add(part, Occur.MUST); } else { return null; } } break; } else if (padField == Calendar.YEAR) { return null; } else { if (Calendar.YEAR <= resolutionField) { part = new TermQuery(new Term(field, "YE" + cal.get(Calendar.YEAR))); range.add(part, Occur.MUST); } else { return null; } } case Calendar.MONTH: if ((cal.get(Calendar.MONTH) == 0) && (cal.get(Calendar.DAY_OF_MONTH) == 1) && (cal.get(Calendar.HOUR_OF_DAY) == 0) && (cal.get(Calendar.MINUTE) == 0) && (cal.get(Calendar.SECOND) == 0) && (cal.get(Calendar.MILLISECOND) == 0)) { if (padField == Calendar.DAY_OF_MONTH) { if (Calendar.MONTH <= resolutionField) { part = new TermQuery(new Term(field, build2SF("MO", cal.get(Calendar.MONTH)))); range.add(part, Occur.MUST); } else { return null; } } break; } else if (padField == Calendar.MONTH) { if (Calendar.MONTH < resolutionField) { part = new ConstantScoreRangeQuery(field, build2SF("MO", (cal.get(Calendar.MONTH) + 1)), "MO" + cal.getMaximum(Calendar.MONTH), true, true); range.add(part, Occur.MUST); } else if (Calendar.MONTH == resolutionField) { part = new ConstantScoreRangeQuery(field, build2SF("MO", (cal.get(Calendar.MONTH))), "MO" + cal.getMaximum(Calendar.MONTH), true, true); range.add(part, Occur.MUST); } else { return null; } break; } else { if (Calendar.MONTH <= resolutionField) { part = new TermQuery(new Term(field, build2SF("MO", cal.get(Calendar.MONTH)))); range.add(part, Occur.MUST); } else { return null; } } case Calendar.DAY_OF_MONTH: if ((cal.get(Calendar.DAY_OF_MONTH) == 1) && (cal.get(Calendar.HOUR_OF_DAY) == 0) && (cal.get(Calendar.MINUTE) == 0) && (cal.get(Calendar.SECOND) == 0) && (cal.get(Calendar.MILLISECOND) == 0)) { if (padField == Calendar.HOUR_OF_DAY) { if (Calendar.DAY_OF_MONTH <= resolutionField) { part = new TermQuery(new Term(field, build2SF("DA", cal.get(Calendar.DAY_OF_MONTH)))); range.add(part, Occur.MUST); } else { return null; } } break; } else if (padField == Calendar.DAY_OF_MONTH) { if (Calendar.DAY_OF_MONTH < resolutionField) { part = new ConstantScoreRangeQuery(field, build2SF("DA", (cal.get(Calendar.DAY_OF_MONTH) + 1)), "DA" + cal.getMaximum(Calendar.DAY_OF_MONTH), true, true); range.add(part, Occur.MUST); } else if (Calendar.DAY_OF_MONTH == resolutionField) { part = new ConstantScoreRangeQuery(field, build2SF("DA", (cal.get(Calendar.DAY_OF_MONTH))), "DA" + cal.getMaximum(Calendar.DAY_OF_MONTH), true, true); range.add(part, Occur.MUST); } else { return null; } break; } else { if (Calendar.DAY_OF_MONTH <= resolutionField) { part = new TermQuery(new Term(field, build2SF("DA", cal.get(Calendar.DAY_OF_MONTH)))); range.add(part, Occur.MUST); } else { return null; } } case Calendar.HOUR_OF_DAY: if ((cal.get(Calendar.HOUR_OF_DAY) == 0) && (cal.get(Calendar.MINUTE) == 0) && (cal.get(Calendar.SECOND) == 0) && (cal.get(Calendar.MILLISECOND) == 0)) { if (padField == Calendar.MINUTE) { if (Calendar.HOUR_OF_DAY <= resolutionField) { part = new TermQuery(new Term(field, build2SF("HO", cal.get(Calendar.HOUR_OF_DAY)))); range.add(part, Occur.MUST); } else { return null; } } break; } else if (padField == Calendar.HOUR_OF_DAY) { if (Calendar.HOUR_OF_DAY < resolutionField) { part = new ConstantScoreRangeQuery(field, build2SF("HO", (cal.get(Calendar.HOUR_OF_DAY) + 1)), "HO" + cal.getMaximum(Calendar.HOUR_OF_DAY), true, true); range.add(part, Occur.MUST); } else if (Calendar.HOUR_OF_DAY == resolutionField) { part = new ConstantScoreRangeQuery(field, build2SF("HO", (cal.get(Calendar.HOUR_OF_DAY))), "HO" + cal.getMaximum(Calendar.HOUR_OF_DAY), true, true); range.add(part, Occur.MUST); } else { return null; } break; } else { if (Calendar.HOUR_OF_DAY <= resolutionField) { part = new TermQuery(new Term(field, build2SF("HO", cal.get(Calendar.HOUR_OF_DAY)))); range.add(part, Occur.MUST); } else { return null; } } case Calendar.MINUTE: if ((cal.get(Calendar.MINUTE) == 0) && (cal.get(Calendar.SECOND) == 0) && (cal.get(Calendar.MILLISECOND) == 0)) { if (padField == Calendar.SECOND) { if (Calendar.MINUTE <= resolutionField) { part = new TermQuery(new Term(field, build2SF("MI", cal.get(Calendar.MINUTE)))); range.add(part, Occur.MUST); } else { return null; } } break; } else if (padField == Calendar.MINUTE) { if (Calendar.MINUTE < resolutionField) { part = new ConstantScoreRangeQuery(field, build2SF("MI", (cal.get(Calendar.MINUTE) + 1)), "MI" + cal.getMaximum(Calendar.MINUTE), true, true); range.add(part, Occur.MUST); } else if (Calendar.MINUTE == resolutionField) { part = new ConstantScoreRangeQuery(field, build2SF("MI", (cal.get(Calendar.MINUTE))), "MI" + cal.getMaximum(Calendar.MINUTE), true, true); range.add(part, Occur.MUST); } else { return null; } break; } else { if (Calendar.MINUTE <= resolutionField) { part = new TermQuery(new Term(field, build2SF("MI", cal.get(Calendar.MINUTE)))); range.add(part, Occur.MUST); } else { return null; } } case Calendar.SECOND: if ((cal.get(Calendar.SECOND) == 0) && (cal.get(Calendar.MILLISECOND) == 0)) { if (padField == Calendar.MILLISECOND) { if (Calendar.SECOND <= resolutionField) { part = new TermQuery(new Term(field, build2SF("SE", cal.get(Calendar.SECOND)))); range.add(part, Occur.MUST); } else { return null; } } break; } else if (padField == Calendar.SECOND) { if (Calendar.SECOND < resolutionField) { part = new ConstantScoreRangeQuery(field, build2SF("SE", (cal.get(Calendar.SECOND) + 1)), "SE" + cal.getMaximum(Calendar.SECOND), true, true); range.add(part, Occur.MUST); } else if (Calendar.SECOND == resolutionField) { part = new ConstantScoreRangeQuery(field, build2SF("SE", (cal.get(Calendar.SECOND))), "SE" + cal.getMaximum(Calendar.SECOND), true, true); range.add(part, Occur.MUST); } else { return null; } break; } else { if (Calendar.SECOND <= resolutionField) { part = new TermQuery(new Term(field, build2SF("SE", cal.get(Calendar.SECOND)))); range.add(part, Occur.MUST); } else { return null; } } case Calendar.MILLISECOND: if ((cal.get(Calendar.MILLISECOND) > 0) && (cal.get(Calendar.MILLISECOND) <= cal.getMaximum(Calendar.MILLISECOND))) { if (Calendar.MILLISECOND <= resolutionField) { part = new ConstantScoreRangeQuery(field, build3SF("MS", cal.get(Calendar.MILLISECOND)), "MS" + cal.getMaximum(Calendar.MILLISECOND), true, true); range.add(part, Occur.MUST); } else { break; } } default: } return getNonEmptyBooleanQuery(range); }
From source file:org.alfresco.repo.search.impl.lucene.AbstractLuceneQueryParser.java
/** * @param field String// www.j a v a 2 s . co m * @param part1 String * @param part2 String * @param includeLower boolean * @param includeUpper boolean * @param analysisMode AnalysisMode * @param luceneFunction LuceneFunction * @return the query * @exception ParseException * throw in overridden method to disallow */ public Query getRangeQuery(String field, String part1, String part2, boolean includeLower, boolean includeUpper, AnalysisMode analysisMode, LuceneFunction luceneFunction) throws ParseException { if (field.equals(FIELD_PATH)) { throw new UnsupportedOperationException("Range Queries are not support for " + FIELD_PATH); } else if (field.equals(FIELD_PATHWITHREPEATS)) { throw new UnsupportedOperationException("Range Queries are not support for " + FIELD_PATHWITHREPEATS); } else if (field.equals(FIELD_TEXT)) { Set<String> text = searchParameters.getTextAttributes(); if ((text == null) || (text.size() == 0)) { Query query = getRangeQuery(PROPERTY_FIELD_PREFIX + ContentModel.PROP_CONTENT.toString(), part1, part2, includeLower, includeUpper, analysisMode, luceneFunction); if (query == null) { return createNoMatchQuery(); } return query; } else { BooleanQuery query = new BooleanQuery(); for (String fieldName : text) { Query part = getRangeQuery(fieldName, part1, part2, includeLower, includeUpper, analysisMode, luceneFunction); if (part != null) { query.add(part, Occur.SHOULD); } else { query.add(createNoMatchQuery(), Occur.SHOULD); } } return query; } } // FIELD_ID uses the default // FIELD_DBID uses the default // FIELD_ISROOT uses the default // FIELD_ISCONTAINER uses the default // FIELD_ISNODE uses the default // FIELD_TX uses the default // FIELD_PARENT uses the default // FIELD_PRIMARYPARENT uses the default // FIELD_QNAME uses the default // FIELD_PRIMARYASSOCTYPEQNAME uses the default // FIELD_ASSOCTYPEQNAME uses the default // FIELD_CLASS uses the default // FIELD_TYPE uses the default // FIELD_EXACTTYPE uses the default // FIELD_ASPECT uses the default // FIELD_EXACTASPECT uses the default // FIELD_TYPE uses the default // FIELD_TYPE uses the default if (field.startsWith(PROPERTY_FIELD_PREFIX)) { String fieldName; PropertyDefinition propertyDef = matchPropertyDefinition(field.substring(1)); if (propertyDef != null) { fieldName = PROPERTY_FIELD_PREFIX + propertyDef.getName(); } else { fieldName = expandAttributeFieldName(field); } IndexTokenisationMode tokenisationMode = IndexTokenisationMode.TRUE; if (propertyDef != null) { tokenisationMode = propertyDef.getIndexTokenisationMode(); if (tokenisationMode == null) { tokenisationMode = IndexTokenisationMode.TRUE; } } if (propertyDef != null) { // LOWER AND UPPER if (luceneFunction != LuceneFunction.FIELD) { if (luceneFunction == LuceneFunction.LOWER) { if ((false == part1.toLowerCase().equals(part1)) || (false == part2.toLowerCase().equals(part2))) { return createNoMatchQuery(); } } if (luceneFunction == LuceneFunction.UPPER) { if ((false == part1.toUpperCase().equals(part1)) || (false == part2.toUpperCase().equals(part2))) { return createNoMatchQuery(); } } if (propertyDef.getDataType().getName().equals(DataTypeDefinition.TEXT)) { BooleanQuery booleanQuery = new BooleanQuery(); MLAnalysisMode mlAnalysisMode = searchParameters.getMlAnalaysisMode() == null ? defaultSearchMLAnalysisMode : searchParameters.getMlAnalaysisMode(); List<Locale> locales = searchParameters.getLocales(); List<Locale> expandedLocales = new ArrayList<Locale>(); for (Locale locale : (((locales == null) || (locales.size() == 0)) ? Collections.singletonList(I18NUtil.getLocale()) : locales)) { expandedLocales.addAll(MLAnalysisMode.getLocales(mlAnalysisMode, locale, false)); } for (Locale locale : (((expandedLocales == null) || (expandedLocales.size() == 0)) ? Collections.singletonList(I18NUtil.getLocale()) : expandedLocales)) { addLocaleSpecificUntokenisedTextRangeFunction(fieldName, part1, part2, includeLower, includeUpper, luceneFunction, booleanQuery, mlAnalysisMode, locale, tokenisationMode); } return booleanQuery; } else { throw new UnsupportedOperationException("Lucene Function"); } } if (propertyDef.getDataType().getName().equals(DataTypeDefinition.MLTEXT)) { throw new UnsupportedOperationException("Range is not supported against ml-text"); } else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT)) { throw new UnsupportedOperationException("Range is not supported against content"); } else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.TEXT)) { BooleanQuery booleanQuery = new BooleanQuery(); MLAnalysisMode mlAnalysisMode = searchParameters.getMlAnalaysisMode() == null ? defaultSearchMLAnalysisMode : searchParameters.getMlAnalaysisMode(); List<Locale> locales = searchParameters.getLocales(); List<Locale> expandedLocales = new ArrayList<Locale>(); for (Locale locale : (((locales == null) || (locales.size() == 0)) ? Collections.singletonList(I18NUtil.getLocale()) : locales)) { expandedLocales.addAll(MLAnalysisMode.getLocales(mlAnalysisMode, locale, false)); } for (Locale locale : (((expandedLocales == null) || (expandedLocales.size() == 0)) ? Collections.singletonList(I18NUtil.getLocale()) : expandedLocales)) { addTextRange(field, part1, part2, includeLower, includeUpper, analysisMode, fieldName, propertyDef, tokenisationMode, booleanQuery, mlAnalysisMode, locale); } return booleanQuery; } else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.DATETIME)) { String analyserClassName = propertyDef.resolveAnalyserClassName(); boolean usesDateTimeAnalyser = analyserClassName .equals(DateTimeAnalyser.class.getCanonicalName()); // Expand query for internal date time format if (usesDateTimeAnalyser) { Calendar start = Calendar.getInstance(); int startResolution; Calendar end = Calendar.getInstance(); int endResolution; try { Pair<Date, Integer> result = CachingDateFormat.lenientParse(part1, Calendar.YEAR); start.setTime(result.getFirst()); startResolution = result.getSecond(); } catch (java.text.ParseException e) { SimpleDateFormat oldDf = CachingDateFormat.getDateFormat(); try { Date date = oldDf.parse(part1); start.setTime(date); start.set(Calendar.MILLISECOND, 0); startResolution = Calendar.SECOND; } catch (java.text.ParseException ee) { if (part1.equalsIgnoreCase("min")) { start.set(Calendar.YEAR, start.getMinimum(Calendar.YEAR)); start.set(Calendar.DAY_OF_YEAR, start.getMinimum(Calendar.DAY_OF_YEAR)); start.set(Calendar.HOUR_OF_DAY, start.getMinimum(Calendar.HOUR_OF_DAY)); start.set(Calendar.MINUTE, start.getMinimum(Calendar.MINUTE)); start.set(Calendar.SECOND, start.getMinimum(Calendar.SECOND)); start.set(Calendar.MILLISECOND, start.getMinimum(Calendar.MILLISECOND)); startResolution = Calendar.MILLISECOND; } else if (part1.equalsIgnoreCase("now")) { start.setTime(new Date()); startResolution = Calendar.MILLISECOND; } else if (part1.equalsIgnoreCase("today")) { start.setTime(new Date()); start.set(Calendar.HOUR_OF_DAY, start.getMinimum(Calendar.HOUR_OF_DAY)); start.set(Calendar.MINUTE, start.getMinimum(Calendar.MINUTE)); start.set(Calendar.SECOND, start.getMinimum(Calendar.SECOND)); start.set(Calendar.MILLISECOND, start.getMinimum(Calendar.MILLISECOND)); startResolution = Calendar.DAY_OF_MONTH; } else { return createNoMatchQuery(); } } } try { Pair<Date, Integer> result = CachingDateFormat.lenientParse(part2, Calendar.YEAR); end.setTime(result.getFirst()); endResolution = result.getSecond(); } catch (java.text.ParseException e) { SimpleDateFormat oldDf = CachingDateFormat.getDateFormat(); try { Date date = oldDf.parse(part2); end.setTime(date); end.set(Calendar.MILLISECOND, 0); endResolution = Calendar.SECOND; } catch (java.text.ParseException ee) { if (part2.equalsIgnoreCase("max")) { end.set(Calendar.YEAR, end.getMaximum(Calendar.YEAR)); end.set(Calendar.DAY_OF_YEAR, end.getMaximum(Calendar.DAY_OF_YEAR)); end.set(Calendar.HOUR_OF_DAY, end.getMaximum(Calendar.HOUR_OF_DAY)); end.set(Calendar.MINUTE, end.getMaximum(Calendar.MINUTE)); end.set(Calendar.SECOND, end.getMaximum(Calendar.SECOND)); end.set(Calendar.MILLISECOND, end.getMaximum(Calendar.MILLISECOND)); endResolution = Calendar.MILLISECOND; } else if (part2.equalsIgnoreCase("now")) { end.setTime(new Date()); endResolution = Calendar.MILLISECOND; } else if (part2.equalsIgnoreCase("today")) { end.setTime(new Date()); end.set(Calendar.HOUR_OF_DAY, end.getMinimum(Calendar.HOUR_OF_DAY)); end.set(Calendar.MINUTE, end.getMinimum(Calendar.MINUTE)); end.set(Calendar.SECOND, end.getMinimum(Calendar.SECOND)); end.set(Calendar.MILLISECOND, end.getMinimum(Calendar.MILLISECOND)); endResolution = Calendar.DAY_OF_MONTH; } else { return createNoMatchQuery(); } } } // Build a composite query for all the bits Query rq = buildDateTimeRange(fieldName, start, startResolution, end, endResolution, includeLower, includeUpper); return rq; } else { // Old Date time String first = getToken(fieldName, part1, AnalysisMode.DEFAULT); String last = getToken(fieldName, part2, AnalysisMode.DEFAULT); return new ConstantScoreRangeQuery(fieldName, first, last, includeLower, includeUpper); } } else { // Default property behaviour String first = getToken(fieldName, part1, AnalysisMode.DEFAULT); String last = getToken(fieldName, part2, AnalysisMode.DEFAULT); return new ConstantScoreRangeQuery(fieldName, first, last, includeLower, includeUpper); } } else { // No DD def String first = getToken(fieldName, part1, AnalysisMode.DEFAULT); String last = getToken(fieldName, part2, AnalysisMode.DEFAULT); return new ConstantScoreRangeQuery(fieldName, first, last, includeLower, includeUpper); } } else if (field.equals(FIELD_ALL)) { Set<String> all = searchParameters.getAllAttributes(); if ((all == null) || (all.size() == 0)) { Collection<QName> contentAttributes = dictionaryService.getAllProperties(null); BooleanQuery query = new BooleanQuery(); for (QName qname : contentAttributes) { Query part = getRangeQuery(PROPERTY_FIELD_PREFIX + qname.toString(), part1, part2, includeLower, includeUpper, analysisMode, luceneFunction); query.add(part, Occur.SHOULD); } return query; } else { BooleanQuery query = new BooleanQuery(); for (String fieldName : all) { Query part = getRangeQuery(fieldName, part1, part2, includeLower, includeUpper, analysisMode, luceneFunction); query.add(part, Occur.SHOULD); } return query; } } // FIELD_ISUNSET uses the default // FIELD_ISNULL uses the default // FIELD_ISNOTNULL uses the default else if (matchDataTypeDefinition(field) != null) { Collection<QName> contentAttributes = dictionaryService .getAllProperties(matchDataTypeDefinition(field).getName()); BooleanQuery query = new BooleanQuery(); for (QName qname : contentAttributes) { Query part = getRangeQuery(PROPERTY_FIELD_PREFIX + qname.toString(), part1, part2, includeLower, includeUpper, analysisMode, luceneFunction); query.add(part, Occur.SHOULD); } return query; } // FIELD_FTSSTATUS uses the default if (field.equals(FIELD_TAG)) { throw new UnsupportedOperationException("Range Queries are not support for " + FIELD_TAG); } else { // None property - leave alone if (getLowercaseExpandedTerms()) { part1 = part1.toLowerCase(); part2 = part2.toLowerCase(); } return new ConstantScoreRangeQuery(field, part1, part2, includeLower, includeUpper); } }