当前位置: 首页>>代码示例>>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;未经允许,请勿转载。