List of usage examples for org.apache.lucene.document DateTools stringToTime
public static long stringToTime(String dateString) throws ParseException
timeToString or dateToString back to a time, represented as the number of milliseconds since January 1, 1970, 00:00:00 GMT. From source file:com.esri.gpt.catalog.lucene.QueryProvider.java
License:Apache License
/** * Checks if provided date is a full date stored in the index. Full date is * a date of milliseconds resolution./*from w w w . j av a 2 s . c om*/ * @param queryText possibly a full date * @return <code>true</code> if this is a full date. */ private boolean isFullDate(String queryText) { try { queryText = Val.chkStr(queryText); long lngDate = DateTools.stringToTime(queryText); return queryText.matches("[0-9]+") && queryText.length() >= DateTools .timeToString(lngDate, DateTools.Resolution.MILLISECOND).length(); } catch (java.text.ParseException ex) { return false; } }
From source file:com.esri.gpt.catalog.lucene.TimestampField.java
License:Apache License
/** * Reverts an indexable String back to a time stamp. * @param value the indexable string to revert * @return the update date (null if the value is invalid) *///w w w . java2s .c om protected static Timestamp timestampFromIndexableString(String value) { try { long lValue = DateTools.stringToTime(value); return new Timestamp(lValue); } catch (ParseException e) { return null; } }
From source file:com.esri.gpt.control.georss.DiscoveredRecordAdapter.java
License:Apache License
@Override public Date getModfiedDate() { try {// w w w . jav a2 s . c o m return new Date(DateTools.stringToTime(select(PropertyMeanings.NAME_DATEMODIFIED))); } catch (ParseException ex) { return new Date(); } }
From source file:com.esri.gpt.server.assertion.index.AsnSystemPart.java
License:Apache License
/** * Reads the fields of an indexed document. * @param document the document//from ww w . j ava 2 s . c o m */ public void readFields(Document document) { String val; this.setAssertionId(document.get(AsnConstants.FIELD_SYS_ASSERTIONID)); this.setResourceId(document.get(AsnConstants.FIELD_SYS_RESOURCEID)); val = Val.chkStr(document.get(AsnConstants.FIELD_SYS_ENABLED)); this.setEnabled(!val.equals("false")); val = document.get(AsnConstants.FIELD_SYS_TIMESTAMP); if ((val != null) && (val.length() > 0)) { try { long millis = DateTools.stringToTime(val); this.setTimestamp(new Timestamp(millis)); } catch (ParseException e) { // not fatal } } val = document.get(AsnConstants.FIELD_SYS_EDIT_TIMESTAMP); if ((val != null) && (val.length() > 0)) { try { long millis = DateTools.stringToTime(val); this.setEditTimestamp(new Timestamp(millis)); } catch (ParseException e) { // not fatal } } }
From source file:com.fuerve.villageelder.search.SearchQueryParser.java
License:Apache License
/** * Called by Lucene's {@link QueryParserBase} to compose a range query when * a range field is detected in the input. This is overridden here in order * to provide special handling for specific fields. * @param field The name of the field for which the query is being composed. * @param part1 The lower bound of the specified numeric range. * @param part2 The upper bound of the specified numeric range. * @param startInclusive Determines whether the lower bound is inclusive. * @param endInclusive Determines whether the upper bound is inclusive. * @return The Lucene {@link Query} object appropriate for the requested * field.//from ww w. j av a 2 s .c o m */ public Query getRangeQuery(final String field, final String part1, final String part2, final boolean startInclusive, final boolean endInclusive) throws ParseException { TermRangeQuery query = (TermRangeQuery) super.getRangeQuery(field, part1, part2, startInclusive, endInclusive); if ("RevisionNumber".equals(field)) { try { return NumericRangeQuery.newLongRange(field, Long.parseLong(part1), Long.parseLong(part2), startInclusive, endInclusive); } catch (NumberFormatException e) { return query; } } else if ("Date".equals(field)) { try { return NumericRangeQuery.newLongRange(field, DateTools.stringToTime(part1), DateTools.stringToTime(part2), startInclusive, endInclusive); } catch (java.text.ParseException e) { return query; } } return query; }
From source file:com.github.cmisbox.persistence.StoredItem.java
License:Open Source License
public StoredItem(int docNumber, Fieldable id, Fieldable type, Fieldable path, Fieldable localModified, Fieldable remoteModified, Fieldable version) throws Exception { this.docNumber = docNumber; if (id != null) { this.id = id.stringValue(); }/*from w w w. j ava2 s . c o m*/ if (type != null) { this.type = type.stringValue(); } if (path != null) { this.path = path.stringValue(); } if (localModified != null) { this.localModified = DateTools.stringToTime(localModified.stringValue()); } if (remoteModified != null) { this.remoteModified = DateTools.stringToTime(remoteModified.stringValue()); } if (version != null) { this.setVersion(version.stringValue()); } }
From source file:com.stinkyteddy.utils.StDateUtils.java
License:Apache License
static public String makePrintedString(String indexString) { if (indexString == null || indexString == "") return ""; Date now = new Date(); try {//from w w w . j a v a 2s . c om long indexed = DateTools.stringToTime(indexString); long diff = now.getTime() - indexed; long number = 0; String unit = ""; if (diff / MILLIS_PER_YEAR > 0) { number = diff / MILLIS_PER_YEAR; unit = "year"; } else if (diff / MILLIS_PER_MONTH > 0) { number = diff / MILLIS_PER_MONTH; unit = "month"; } else if (diff / MILLIS_PER_WEEK > 0) { number = diff / MILLIS_PER_WEEK; unit = "week"; } else if (diff / MILLIS_PER_DAY > 0) { number = diff / MILLIS_PER_DAY; unit = "day"; } else if (diff / MILLIS_PER_HOUR > 0) { number = diff / MILLIS_PER_HOUR; unit = "hour"; } else if (diff / MILLIS_PER_MINUTE > 0) { number = diff / MILLIS_PER_MINUTE; unit = "minute"; } else if (diff / MILLIS_PER_SECOND > 0) { number = diff / MILLIS_PER_SECOND; unit = "second"; } else { return ""; } StringBuilder sb = new StringBuilder(); sb.append(String.valueOf(number)); sb.append(" " + unit); if (number != 1) { sb.append("s"); } sb.append(" ago"); return sb.toString(); } catch (Exception e) { // System.out.println(e.getMessage() + indexString); return ""; } }
From source file:com.stinkyteddy.utils.StDateUtils.java
License:Apache License
static public long getAgeInMillis(String indexString) { if (indexString == null) return 0; Date now = new Date(); try {/*from w w w.java 2 s . c om*/ long indexed = DateTools.stringToTime(indexString); long diff = now.getTime() - indexed; return diff; } catch (Exception e) { // System.out.println(e.getMessage()); return 0; } }
From source file:com.zimbra.cs.index.MessageHit.java
License:Open Source License
public long getDateHeader() throws ServiceException { if (message == null && document != null) { String dateStr = document.get(LuceneFields.L_SORT_DATE); if (dateStr != null) { try { return DateTools.stringToTime(dateStr); } catch (ParseException e) { return 0; }//w w w . jav a 2 s .c o m } else { return 0; } } return getMessage().getDate(); }
From source file:de.joergjahnke.jdesktopsearch.abstractionlayer.LuceneIndexManager.java
License:Open Source License
/** * Documents are not removed from a Lucene index. Therefore the most recent version needs to be checked. *//* ww w . j a va 2 s. co m*/ private boolean isDocumentUpToDate(final Document doc) throws Exception { return DateTools .stringToTime(doc.getField("modified").stringValue()) == getDocumentFileDate(doc.get("path")); }