本文整理汇总了Java中org.apache.lucene.document.DateTools.stringToDate方法的典型用法代码示例。如果您正苦于以下问题:Java DateTools.stringToDate方法的具体用法?Java DateTools.stringToDate怎么用?Java DateTools.stringToDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.document.DateTools
的用法示例。
在下文中一共展示了DateTools.stringToDate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSearchResult
import org.apache.lucene.document.DateTools; //导入方法依赖的package包/类
private SearchResult createSearchResult(Document doc, float score, int hitId, int totalHits) throws ParseException {
SearchResult result = new SearchResult();
result.hitId = hitId;
result.totalHits = totalHits;
result.score = score;
result.date = DateTools.stringToDate(doc.get(FIELD_DATE));
result.summary = doc.get(FIELD_SUMMARY);
result.author = doc.get(FIELD_AUTHOR);
result.committer = doc.get(FIELD_COMMITTER);
result.type = SearchObjectType.fromName(doc.get(FIELD_OBJECT_TYPE));
result.branch = doc.get(FIELD_BRANCH);
result.commitId = doc.get(FIELD_COMMIT);
result.path = doc.get(FIELD_PATH);
if (doc.get(FIELD_TAG) != null) {
result.tags = StringUtils.getStringsFromValue(doc.get(FIELD_TAG));
}
return result;
}
示例2: stringToDate
import org.apache.lucene.document.DateTools; //导入方法依赖的package包/类
/**
* Converts a string produced by {@link #timeToString} or {@link #dateToString} back to a time, represented
* as a Date object. Is also able to parse dates encoded in the old Lucene 1.x DateField format, for
* compatibility with old indexes (this functionality will go away in a future release).
*
* @param dateString A string produced by timeToString or dateToString
* @return The parsed time as a Date object
* @exception ParseException If parse error
*/
public final static Date stringToDate(String dateString) throws ParseException {
try {
return DateTools.stringToDate(dateString);
} catch (ParseException pe) {
// Handle dates encoded in the Lucene 1.x format, for compatibility with old indexes
try {
// This method will go away in a future release of Lucene...
return DateField.stringToDate(dateString);
} catch (Throwable t) {
throw new ParseException("Unable to parse date string: " + t.getMessage(), 0);
}
}
}
示例3: assertDocData
import org.apache.lucene.document.DateTools; //导入方法依赖的package包/类
private void assertDocData(DocData dd, String expName, String expTitle,
String expBody, Date expDate)
throws ParseException {
assertNotNull(dd);
assertEquals(expName, dd.getName());
assertEquals(expTitle, dd.getTitle());
assertTrue(dd.getBody().indexOf(expBody) != -1);
Date date = dd.getDate() != null ? DateTools.stringToDate(dd.getDate()) : null;
assertEquals(expDate, date);
}
示例4: stringToObject
import org.apache.lucene.document.DateTools; //导入方法依赖的package包/类
public Object stringToObject(String stringValue) {
if ( StringHelper.isEmpty( stringValue ) ) return null;
try {
return DateTools.stringToDate( stringValue );
}
catch (ParseException e) {
throw new SearchException( "Unable to parse into date: " + stringValue, e );
}
}