本文整理汇总了Java中org.apache.lucene.document.FieldType.setNumericType方法的典型用法代码示例。如果您正苦于以下问题:Java FieldType.setNumericType方法的具体用法?Java FieldType.setNumericType怎么用?Java FieldType.setNumericType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.document.FieldType
的用法示例。
在下文中一共展示了FieldType.setNumericType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createField
import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public IndexableField createField(SchemaField field, Object value, float boost) {
final boolean indexed = field.indexed();
final boolean stored = field.stored();
final boolean docValues = field.hasDocValues();
if (!indexed && !stored && !docValues) {
if (log.isTraceEnabled())
log.trace("Ignoring unindexed/unstored field: " + field);
return null;
}
final Integer intValue = stringValueToIntValue(value.toString());
if (intValue == null || intValue.equals(DEFAULT_VALUE))
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown value for enum field: " + value.toString());
String intAsString = intValue.toString();
final FieldType newType = new FieldType();
newType.setIndexed(field.indexed());
newType.setTokenized(field.isTokenized());
newType.setStored(field.stored());
newType.setOmitNorms(field.omitNorms());
newType.setIndexOptions(getIndexOptions(field, intAsString));
newType.setStoreTermVectors(field.storeTermVector());
newType.setStoreTermVectorOffsets(field.storeTermOffsets());
newType.setStoreTermVectorPositions(field.storeTermPositions());
newType.setNumericType(FieldType.NumericType.INT);
newType.setNumericPrecisionStep(DEFAULT_PRECISION_STEP);
final org.apache.lucene.document.Field f;
f = new org.apache.lucene.document.IntField(field.getName(), intValue.intValue(), newType);
f.setBoost(boost);
return f;
}
示例2: createField
import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
@Override
public IndexableField createField(SchemaField field, Object value, float boost) {
boolean indexed = field.indexed();
boolean stored = field.stored();
boolean docValues = field.hasDocValues();
if (!indexed && !stored && !docValues) {
if (log.isTraceEnabled())
log.trace("Ignoring unindexed/unstored field: " + field);
return null;
}
FieldType ft = new FieldType();
ft.setStored(stored);
ft.setTokenized(true);
ft.setIndexed(indexed);
ft.setOmitNorms(field.omitNorms());
ft.setIndexOptions(getIndexOptions(field, value.toString()));
switch (type) {
case INTEGER:
ft.setNumericType(NumericType.INT);
break;
case FLOAT:
ft.setNumericType(NumericType.FLOAT);
break;
case LONG:
ft.setNumericType(NumericType.LONG);
break;
case DOUBLE:
ft.setNumericType(NumericType.DOUBLE);
break;
case DATE:
ft.setNumericType(NumericType.LONG);
break;
default:
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
}
ft.setNumericPrecisionStep(precisionStep);
final org.apache.lucene.document.Field f;
switch (type) {
case INTEGER:
int i = (value instanceof Number)
? ((Number)value).intValue()
: Integer.parseInt(value.toString());
f = new org.apache.lucene.document.IntField(field.getName(), i, ft);
break;
case FLOAT:
float fl = (value instanceof Number)
? ((Number)value).floatValue()
: Float.parseFloat(value.toString());
f = new org.apache.lucene.document.FloatField(field.getName(), fl, ft);
break;
case LONG:
long l = (value instanceof Number)
? ((Number)value).longValue()
: Long.parseLong(value.toString());
f = new org.apache.lucene.document.LongField(field.getName(), l, ft);
break;
case DOUBLE:
double d = (value instanceof Number)
? ((Number)value).doubleValue()
: Double.parseDouble(value.toString());
f = new org.apache.lucene.document.DoubleField(field.getName(), d, ft);
break;
case DATE:
Date date = (value instanceof Date)
? ((Date)value)
: dateField.parseMath(null, value.toString());
f = new org.apache.lucene.document.LongField(field.getName(), date.getTime(), ft);
break;
default:
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
}
f.setBoost(boost);
return f;
}
示例3: _fieldTypeFrom
import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
private static FieldType _fieldTypeFrom(final IndexDocumentStandardFieldType fieldType,
final boolean stored,
final IndexDocumentFieldIndexOptions options) {
FieldType outFieldType = new FieldType();
// [1] - Set if the field is stored or not
outFieldType.setStored(stored);
// [2] - Set the options: indexed, tokenized, etc
if (options != null) {
outFieldType.setIndexed(true);
outFieldType.setOmitNorms(options.isOmitingNorms());
outFieldType.setTokenized(options.isTokenized());
if (options.getTermVectorsStoring() != null) {
outFieldType.setStoreTermVectors(options.getTermVectorsStoring().isEnabled());
if (options.getTermVectorsStoring().isEnabled()) {
outFieldType.setStoreTermVectorOffsets(options.getTermVectorsStoring().isIncludeTermOffsets());
outFieldType.setStoreTermVectorPositions(options.getTermVectorsStoring().isIncludeTermPositions());
outFieldType.setStoreTermVectorPayloads(options.getTermVectorsStoring().isIncludeTermPayLoads());
}
}
}
// [3] - Set the lucene's FieldType's numericType
switch(fieldType) {
case Double:
outFieldType.setNumericType(FieldType.NumericType.DOUBLE);
break;
case Float:
outFieldType.setNumericType(FieldType.NumericType.FLOAT);
break;
case Int:
outFieldType.setNumericType(FieldType.NumericType.INT);
break;
case Long:
outFieldType.setNumericType(FieldType.NumericType.LONG);
break;
case String:
// nothing
break;
case Text:
// nothing
break;
default:
throw new IllegalArgumentException(fieldType + "is NOT a supported type");
}
return outFieldType;
}