當前位置: 首頁>>代碼示例>>Java>>正文


Java DateTools.dateToString方法代碼示例

本文整理匯總了Java中org.apache.lucene.document.DateTools.dateToString方法的典型用法代碼示例。如果您正苦於以下問題:Java DateTools.dateToString方法的具體用法?Java DateTools.dateToString怎麽用?Java DateTools.dateToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.lucene.document.DateTools的用法示例。


在下文中一共展示了DateTools.dateToString方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getLuceneDateValue

import org.apache.lucene.document.DateTools; //導入方法依賴的package包/類
/**
 * Typically the value itself converted to string
 * But there are some exceptions where the toString()
 * doesn't work as expected. 
 * It should be implemented
 * specific to the lucene requirement to be indexable
 * set the date according to offset from the GMT
 * see http://www.gossamer-threads.com/lists/lucene/java-user/39303?search_string=DateTools;#39303
 * @param value
 * @return
 */
public static String getLuceneDateValue(Object value) {
	Calendar cal = new GregorianCalendar();
	int minutesOffset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / (60 * 1000);
	if (value!=null) {
		Date dateValue = null;
		try {
			dateValue = (Date)value;
		} catch (Exception e) {
			LOGGER.error("The type of the lucene value is " + value.getClass().getName() + 
					". Casting it to Date failed with " + e.getMessage());
			LOGGER.debug(ExceptionUtils.getStackTrace(e));
		}
		if (dateValue!=null) {
			cal.setTime(dateValue);
			cal.add(Calendar.MINUTE, minutesOffset);
			return DateTools.dateToString(cal.getTime(), DateTools.Resolution.DAY);
		}
	}
	return null;
}
 
開發者ID:trackplus,項目名稱:Genji,代碼行數:32,代碼來源:LuceneUtil.java

示例2: transformDateFields

import org.apache.lucene.document.DateTools; //導入方法依賴的package包/類
/**
 * Transforms the user entered date string to lucene date string format
 * by trying to reconstruct the Date object either by local or by ISO (yyy-MM-dd)
 * DateTools calculates in GMT (comparing to the server TimeZone), so it should be adjusted  
 * @param originalFieldValue
 * @param locale
 * @return
 */
private static String transformDateFields(String originalFieldValue, Locale locale) {
	String dateString = originalFieldValue;
	Date date;
	//DateTimeUtils dtu = new DateTimeUtils(locale);
	date = DateTimeUtils.getInstance().parseGUIDate(originalFieldValue, locale);
	if (date==null) {
		date = DateTimeUtils.getInstance().parseShortDate(originalFieldValue, locale);
	}
	//set the date according to offset from the GMT
	//see http://www.gossamer-threads.com/lists/lucene/java-user/39303?search_string=DateTools;#39303
	Calendar cal = new GregorianCalendar();
	int minutesOffset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / (60 * 1000);
	if (date!=null) {
		cal.setTime(date);
		cal.add(Calendar.MINUTE, minutesOffset); 
		return DateTools.dateToString(cal.getTime(), Resolution.DAY);
	}
	date = DateTimeUtils.getInstance().parseISODate(originalFieldValue);
	if (date!=null) {
		cal.setTime(date);
		cal.add(Calendar.MINUTE, minutesOffset);
		return DateTools.dateToString(cal.getTime(), Resolution.DAY);
	}
	return dateString;
}
 
開發者ID:trackplus,項目名稱:Genji,代碼行數:34,代碼來源:LuceneSearcher.java

示例3: getRangeQuery

import org.apache.lucene.document.DateTools; //導入方法依賴的package包/類
/**
 * @exception ParseException throw in overridden method to disallow
 */
protected Query getRangeQuery(String field, String part1, String part2, boolean inclusive) throws ParseException {
	if (lowercaseExpandedTerms) {
		part1 = part1.toLowerCase();
		part2 = part2.toLowerCase();
	}
	try {
		DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
		df.setLenient(true);
		Date d1 = df.parse(part1);
		Date d2 = df.parse(part2);
		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:
			Calendar cal = Calendar.getInstance(locale);
			cal.setTime(d2);
			cal.set(Calendar.HOUR_OF_DAY, 23);
			cal.set(Calendar.MINUTE, 59);
			cal.set(Calendar.SECOND, 59);
			cal.set(Calendar.MILLISECOND, 999);
			d2 = cal.getTime();
		}
		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 e) {
	}

	return newRangeQuery(field, part1, part2, inclusive);
}
 
開發者ID:kuzavas,項目名稱:ephesoft,代碼行數:42,代碼來源:QueryParser.java

示例4: setCheckin

import org.apache.lucene.document.DateTools; //導入方法依賴的package包/類
/**
 * @param checkinIn the checkin to set
 */
public void setCheckin(Date checkinIn) {
    if (checkinIn != null) {
        this.checkin = DateTools.dateToString(checkinIn,
            DateTools.Resolution.MINUTE);
    }
    else {
        this.checkin = null;
    }
}
 
開發者ID:spacewalkproject,項目名稱:spacewalk,代碼行數:13,代碼來源:Server.java

示例5: setRegistered

import org.apache.lucene.document.DateTools; //導入方法依賴的package包/類
/**
 * @param registeredIn the registered to set
 */
public void setRegistered(Date registeredIn) {
    if (registeredIn != null) {
        this.registered = DateTools.dateToString(registeredIn,
            DateTools.Resolution.MINUTE);
    }
    else {
        this.registered = null;
    }
}
 
開發者ID:spacewalkproject,項目名稱:spacewalk,代碼行數:13,代碼來源:Server.java

示例6: getDate

import org.apache.lucene.document.DateTools; //導入方法依賴的package包/類
public String getDate(String s) throws Exception {
  // we use the default Locale since LuceneTestCase randomizes it
  DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
  return DateTools.dateToString(df.parse(s), DateTools.Resolution.DAY);
}
 
開發者ID:europeana,項目名稱:search,代碼行數:6,代碼來源:TestPrecedenceQueryParser.java

示例7: getDate

import org.apache.lucene.document.DateTools; //導入方法依賴的package包/類
/** for testing DateTools support */
private String getDate(Date d, DateTools.Resolution resolution) {
  return DateTools.dateToString(d, resolution);
}
 
開發者ID:europeana,項目名稱:search,代碼行數:5,代碼來源:TestQPHelper.java

示例8: getDate

import org.apache.lucene.document.DateTools; //導入方法依賴的package包/類
/** for testing DateTools support */
private String getDate(Date d, DateTools.Resolution resolution) {
   return DateTools.dateToString(d, resolution);
}
 
開發者ID:europeana,項目名稱:search,代碼行數:5,代碼來源:QueryParserTestBase.java

示例9: getDate

import org.apache.lucene.document.DateTools; //導入方法依賴的package包/類
/** for testing DateTools support */
private String getDate(Date d, DateTools.Resolution resolution) {
	return DateTools.dateToString(d, resolution);
}
 
開發者ID:easynet-cn,項目名稱:resource-query-parser,代碼行數:5,代碼來源:QueryParserTestBase.java

示例10: buildPDFDocument

import org.apache.lucene.document.DateTools; //導入方法依賴的package包/類
/**
 * Creates a new Lucene Document instance using the PDF text and metadata provided by the PDFxStream
 * Document using the provided {@link LucenePDFConfiguration} to control Lucene field
 * names, etc.
 */
public static Document buildPDFDocument (com.snowtide.pdf.Document pdf, LucenePDFConfiguration config) throws
        IOException {
    StringWriter sb = new StringWriter();
    pdf.pipe(new OutputTarget(sb));

    Document doc = new Document();

    LUCENE_INTERFACE.addField(doc, config.getBodyTextFieldName(), sb.toString(),
            config.storeBodyText(), config.indexBodyText(), config.tokenizeBodyText());

    for (Map.Entry<String, Object> metadataEntry : pdf.getAttributeMap().entrySet()) {
        String docPropName = metadataEntry.getKey();
        String fieldName = config.getMetadataFieldMapping(docPropName);
        if (fieldName == null) {
            if (config.copyAllPDFMetadata()) {
                fieldName = docPropName;
            } else {
                continue;
            }
        }

        Object value = metadataEntry.getValue();
        String valueStr;

        if (value == null) {
            if (LOG_DEBUG) log.debug("Null document property value found for name ["+docPropName+"] ("+pdf.getName()+')');
            continue;
        } else if (value instanceof String) {
            if (docPropName.equals(com.snowtide.pdf.Document.ATTR_MOD_DATE) ||
                    docPropName.equals(com.snowtide.pdf.Document.ATTR_CREATION_DATE)) {
                try {
                    valueStr = DateTools.dateToString(PDFDateParser.parseDateString((String)value),
                            DateTools.Resolution.MILLISECOND);
                } catch (Exception e) {
                    log.warn("PDF date string could not be parsed into a java.util.Date instance ["+value+"] ("+pdf.getName()+')', e);
                    valueStr = (String)value;
                }
            } else {
                valueStr = (String)value;
            }
        } else if (value instanceof Number) {
            valueStr = value.toString();
        } else {
            if (LOG_DEBUG) log.debug("Unexpected document property value type: "+value.getClass().getName()+
                    ", for name ("+docPropName+") ("+pdf.getName()+')');
            continue;
        }

        LUCENE_INTERFACE.addField(doc, fieldName, valueStr,
                config.storeMetadata(), config.indexMetadata(), config.tokenizeMetadata());
    }

    return doc;
}
 
開發者ID:snowtide,項目名稱:lucene-pdf,代碼行數:60,代碼來源:LucenePDFDocumentFactory.java

示例11: getDate

import org.apache.lucene.document.DateTools; //導入方法依賴的package包/類
private String getDate(Date d, DateTools.Resolution resolution) {
   return DateTools.dateToString(d, resolution);
}
 
開發者ID:tballison,項目名稱:lucene-addons,代碼行數:4,代碼來源:QueryParserTestCase.java

示例12: DateRangeFilter

import org.apache.lucene.document.DateTools; //導入方法依賴的package包/類
/**
 *  Constructs a filter for field f matching dates between from and to inclusively. Uses time resolution to
 *  seconds.
 *
 * @param  f     The field name
 * @param  from  From Date
 * @param  to    To Date
 */
public DateRangeFilter(String f, Date from, Date to) {
	String lowerTerm = DateTools.dateToString(from, DateTools.Resolution.SECOND);
	String upperTerm = DateTools.dateToString(to, DateTools.Resolution.SECOND);
	_myFilter = new TermRangeFilter(f, lowerTerm, upperTerm, true, true);
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:14,代碼來源:DateRangeFilter.java

示例13: dateToString

import org.apache.lucene.document.DateTools; //導入方法依賴的package包/類
/**
 *  Converts a Date to a string suitable for indexing using resolution to seconds.
 *
 * @param  date  The Date
 * @return       A string in format yyyyMMddHHmmss; using UTC as timezone
 */
public final static String dateToString(Date date) {
	return DateTools.dateToString(date, DateTools.Resolution.SECOND);
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:10,代碼來源:DateFieldTools.java


注:本文中的org.apache.lucene.document.DateTools.dateToString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。