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


Java DateTools類代碼示例

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


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

示例1: StandardQueryConfigHandler

import org.apache.lucene.document.DateTools; //導入依賴的package包/類
public StandardQueryConfigHandler() {
  // Add listener that will build the FieldConfig.
  addFieldConfigListener(new FieldBoostMapFCListener(this));
  addFieldConfigListener(new FieldDateResolutionFCListener(this));
  addFieldConfigListener(new NumericFieldConfigListener(this));
  
  // Default Values
  set(ConfigurationKeys.ALLOW_LEADING_WILDCARD, false); // default in 2.9
  set(ConfigurationKeys.ANALYZER, null); //default value 2.4
  set(ConfigurationKeys.DEFAULT_OPERATOR, Operator.OR);
  set(ConfigurationKeys.PHRASE_SLOP, 0); //default value 2.4
  set(ConfigurationKeys.LOWERCASE_EXPANDED_TERMS, true); //default value 2.4
  set(ConfigurationKeys.ENABLE_POSITION_INCREMENTS, false); //default value 2.4
  set(ConfigurationKeys.FIELD_BOOST_MAP, new LinkedHashMap<String, Float>());
  set(ConfigurationKeys.FUZZY_CONFIG, new FuzzyConfig());
  set(ConfigurationKeys.LOCALE, Locale.getDefault());
  set(ConfigurationKeys.MULTI_TERM_REWRITE_METHOD, MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT);
  set(ConfigurationKeys.FIELD_DATE_RESOLUTION_MAP, new HashMap<CharSequence, DateTools.Resolution>());
  
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:StandardQueryConfigHandler.java

示例2: buildFieldConfig

import org.apache.lucene.document.DateTools; //導入依賴的package包/類
@Override
public void buildFieldConfig(FieldConfig fieldConfig) {
  DateTools.Resolution dateRes = null;
  Map<CharSequence, DateTools.Resolution> dateResMap = this.config.get(ConfigurationKeys.FIELD_DATE_RESOLUTION_MAP);

  if (dateResMap != null) {
    dateRes = dateResMap.get(
        fieldConfig.getField());
  }

  if (dateRes == null) {
    dateRes = this.config.get(ConfigurationKeys.DATE_RESOLUTION);
  }

  if (dateRes != null) {
    fieldConfig.set(ConfigurationKeys.DATE_RESOLUTION, dateRes);
  }

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:FieldDateResolutionFCListener.java

示例3: getDateResolution

import org.apache.lucene.document.DateTools; //導入依賴的package包/類
/**
 * Returns the date resolution that is used by RangeQueries for the given field.
 * Returns null, if no default or field specific date resolution has been set
 * for the given field.
 *
 */
public DateTools.Resolution getDateResolution(String fieldName) {
  if (fieldName == null) {
    throw new IllegalArgumentException("Field cannot be null.");
  }

  if (fieldToDateResolution == null) {
    // no field specific date resolutions set; return default date resolution instead
    return this.dateResolution;
  }

  DateTools.Resolution resolution = fieldToDateResolution.get(fieldName);
  if (resolution == null) {
    // no date resolutions set for the given field; return default date resolution instead
    resolution = this.dateResolution;
  }

  return resolution;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:25,代碼來源:QueryParserBase.java

示例4: getDateResolution

import org.apache.lucene.document.DateTools; //導入依賴的package包/類
/**
 * Returns the date resolution that is used by RangeQueries for the given field. Returns null, if no default or field specific date
 * resolution has been set for the given field.
 * 
 */
public DateTools.Resolution getDateResolution(String fieldName) {
	if (fieldName == null) {
		throw new IllegalArgumentException("Field cannot be null.");
	}

	if (fieldToDateResolution == null) {
		// no field specific date resolutions set; return default date resolution instead
		return this.dateResolution;
	}

	DateTools.Resolution resolution = fieldToDateResolution.get(fieldName);
	if (resolution == null) {
		// no date resolutions set for the given field; return default date resolution instead
		resolution = this.dateResolution;
	}

	return resolution;
}
 
開發者ID:kuzavas,項目名稱:ephesoft,代碼行數:24,代碼來源:QueryParser.java

示例5: Document

import org.apache.lucene.document.DateTools; //導入依賴的package包/類
public static Document Document(File f)
     throws java.io.FileNotFoundException {
  Document doc = new Document();
  doc.add(new StoredField("path", f.getPath()));
  doc.add(new StoredField("modified",
                    DateTools.timeToString(f.lastModified(), DateTools.Resolution.MINUTE)));
  
  //create new FieldType to store term positions (TextField is not sufficiently configurable)
  FieldType ft = new FieldType();
  ft.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
  ft.setTokenized(true);
  ft.setStoreTermVectors(true);
  ft.setStoreTermVectorPositions(true);
  Field contentsField = new Field("contents", new FileReader(f), ft);

  doc.add(contentsField);
  return doc;
}
 
開發者ID:semanticvectors,項目名稱:semanticvectors,代碼行數:19,代碼來源:FilePositionDoc.java

示例6: 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

示例7: 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

示例8: createDocument

import org.apache.lucene.document.DateTools; //導入依賴的package包/類
/**
 * Creates Lucene document with the fields:
 * <ul>
 *  <li>path: relative path from the constructor</li>
 *  <li>id: the same as path</li>
 *  <li>modified: last modified date of the file</li>
 *  <li>filesize: size of the file</li>
 *  <li>title: name of the file</li>
 * </ul>
 * @return New Lucene document.
 */
@Override
public Document createDocument() {
    Document doc = new Document();

    doc.add(new StringField("path", path, Field.Store.YES));
    
    doc.add(new StringField("id", path, Field.Store.YES));

    doc.add(new StringField("modified",
            DateTools.timeToString(file.lastModified(), DateTools.Resolution.MINUTE),
            Field.Store.YES));

    doc.add(new LongField("filesize", file.length(), Field.Store.YES));
    
    doc.add(new TextField("title", file.getName(), Field.Store.YES));
    return doc;
}
 
開發者ID:martinliska,項目名稱:MIaS,代碼行數:29,代碼來源:FileDocument.java

示例9: getDateResolution

import org.apache.lucene.document.DateTools; //導入依賴的package包/類
/**
 * Returns the date resolution that is used by RangeQueries for the given
 * field. Returns null, if no default or field specific date resolution has
 * been set for the given field.
 *
 */
public DateTools.Resolution getDateResolution(String fieldName) {
	if (fieldName == null) {
		throw new IllegalArgumentException("Field must not be null.");
	}

	if (fieldToDateResolution == null) {
		// no field specific date resolutions set; return default date
		// resolution instead
		return this.dateResolution;
	}

	DateTools.Resolution resolution = fieldToDateResolution.get(fieldName);
	if (resolution == null) {
		// no date resolutions set for the given field; return default date
		// resolution instead
		resolution = this.dateResolution;
	}

	return resolution;
}
 
開發者ID:easynet-cn,項目名稱:resource-query-parser,代碼行數:27,代碼來源:QueryParserBase.java

示例10: indexDocument

import org.apache.lucene.document.DateTools; //導入依賴的package包/類
/**
 * Indexes a single conversation.
 *
 * @param writer the index modifier.
 * @param conversationID the ID of the conversation to index.
 * @param external true if the conversation has a participant from an external server.
 * @param date the date the conversation was started.
 * @param jids the JIDs of the users in the conversation.
 * @param text the full text of the conversation.
 * @throws IOException if an IOException occurs.
 */
private void indexDocument(IndexModifier writer, long conversationID, boolean external,
        long date, Set<String> jids, String text) throws IOException
{
    Document document = new Document();
    document.add(new Field("conversationID", String.valueOf(conversationID),
            Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("external", String.valueOf(external),
            Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("date", DateTools.timeToString(date, DateTools.Resolution.DAY),
            Field.Store.YES, Field.Index.UN_TOKENIZED));
    for (String jid : jids) {
        document.add(new Field("jid", jid, Field.Store.YES, Field.Index.TOKENIZED));
    }
    document.add(new Field("text", text, Field.Store.NO, Field.Index.TOKENIZED));
    writer.addDocument(document);
}
 
開發者ID:igniterealtime,項目名稱:Openfire,代碼行數:28,代碼來源:ArchiveIndexer.java

示例11: 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;
}
 
開發者ID:tomaswolf,項目名稱:gerrit-gitblit-plugin,代碼行數:19,代碼來源:LuceneService.java

示例12: 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);
		}
	}
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:23,代碼來源:DateFieldTools.java

示例13: stringToTime

import org.apache.lucene.document.DateTools; //導入依賴的package包/類
/**
 *  Converts a string produced by {@link #timeToString} or {@link #dateToString} back to a time, represented
 *  as the number of milliseconds since January 1, 1970, 00:00:00 GMT. 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 number of milliseconds since January 1, 1970, 00:00:00 GMT
 * @exception  ParseException  If parse error
 */
public final static long stringToTime(String dateString) throws ParseException {
	try {
		return DateTools.stringToTime(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.stringToTime(dateString);
		} catch (Throwable t) {
			throw new ParseException("Unable to parse date string: " + t.getMessage(), 0);
		}
	}
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:24,代碼來源:DateFieldTools.java

示例14: setDateResolution

import org.apache.lucene.document.DateTools; //導入依賴的package包/類
/**
 * Sets the date resolution used by RangeQueries for a specific field.
 *
 * @param fieldName field for which the date resolution is to be set
 * @param dateResolution date resolution to set
 */
public void setDateResolution(String fieldName, DateTools.Resolution dateResolution) {
  if (fieldName == null) {
    throw new IllegalArgumentException("Field cannot be null.");
  }

  if (fieldToDateResolution == null) {
    // lazily initialize HashMap
    fieldToDateResolution = new HashMap<>();
  }

  fieldToDateResolution.put(fieldName, dateResolution);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:QueryParserBase.java

示例15: insert

import org.apache.lucene.document.DateTools; //導入依賴的package包/類
/**
 * Add a row to the index.
 *
 * @param row the row
 * @param commitIndex whether to commit the changes to the Lucene index
 */
protected void insert(Object[] row, boolean commitIndex) throws SQLException {
    String query = getQuery(row);
    Document doc = new Document();
    doc.add(new Field(LUCENE_FIELD_QUERY, query,
            Field.Store.YES, Field.Index.NOT_ANALYZED));
    long time = System.currentTimeMillis();
    doc.add(new Field(LUCENE_FIELD_MODIFIED,
            DateTools.timeToString(time, DateTools.Resolution.SECOND),
            Field.Store.YES, Field.Index.NOT_ANALYZED));
    StatementBuilder buff = new StatementBuilder();
    for (int index : indexColumns) {
        String columnName = columns[index];
        String data = asString(row[index], columnTypes[index]);
        // column names that start with _
        // must be escaped to avoid conflicts
        // with internal field names (_DATA, _QUERY, _modified)
        if (columnName.startsWith(LUCENE_FIELD_COLUMN_PREFIX)) {
            columnName = LUCENE_FIELD_COLUMN_PREFIX + columnName;
        }
        doc.add(new Field(columnName, data,
                Field.Store.NO, Field.Index.ANALYZED));
        buff.appendExceptFirst(" ");
        buff.append(data);
    }
    Field.Store storeText = STORE_DOCUMENT_TEXT_IN_INDEX ?
            Field.Store.YES : Field.Store.NO;
    doc.add(new Field(LUCENE_FIELD_DATA, buff.toString(), storeText,
            Field.Index.ANALYZED));
    try {
        indexAccess.writer.addDocument(doc);
        if (commitIndex) {
            commitIndex();
        }
    } catch (IOException e) {
        throw convertException(e);
    }
}
 
開發者ID:vdr007,項目名稱:ThriftyPaxos,代碼行數:44,代碼來源:FullTextLucene.java


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