本文整理汇总了Java中org.apache.lucene.document.DoubleField类的典型用法代码示例。如果您正苦于以下问题:Java DoubleField类的具体用法?Java DoubleField怎么用?Java DoubleField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DoubleField类属于org.apache.lucene.document包,在下文中一共展示了DoubleField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addLuceneIndexFields
import org.apache.lucene.document.DoubleField; //导入依赖的package包/类
private void addLuceneIndexFields(String indexField, List<IndexableField> list, JsonNode node, JsonSchema nodeSchema) {
JsonNode.Type type = nodeSchema.getSchemaType();
if (type == JsonNode.Type.ARRAY) {
for (int i = 0; i < node.getSize(); i++) {
addLuceneIndexFields(indexField, list, node.get(i), nodeSchema.getItemSchema());
}
} else if (type == JsonNode.Type.OBJECT) {
Iterator<String> properties = node.getProperties();
while (properties.hasNext()) {
String propName = properties.next();
// Index property key for object nodes
list.add(new StringField(indexField, propName, Field.Store.NO));
}
} else if (type == JsonNode.Type.STRING) {
list.add(new StringField(indexField, node.asString(), Field.Store.NO));
} else if (type == JsonNode.Type.BOOLEAN) {
list.add(new StringField(indexField, node.asString(), Field.Store.NO));
} else if (type == JsonNode.Type.INTEGER) {
list.add(new LongField(indexField, node.asLong(), Field.Store.NO));
} else if (type == JsonNode.Type.NUMBER) {
list.add(new DoubleField(indexField, node.asDouble(), Field.Store.NO));
} else {
throw new UnsupportedOperationException("Node type " + type + " not supported for index field " + indexField);
}
}
示例2: resolveField
import org.apache.lucene.document.DoubleField; //导入依赖的package包/类
/**
* resolve field convertable premitive type
*
* premitive type
* byte, short, int, long, float, double, char, boolean
*
* @param type field type
* @return lucene field type
*/
private Class<? extends Field> resolveField(Type type) {
if(type == String.class) {
return StringField.class;
} else if (type == Double.class || type == double.class) {
return DoubleField.class;
} else if(type == Float.class || type == float.class) {
return FloatField.class;
} else if(type == Integer.class || type == int.class ||
type == Short.class || type == short.class ||
type == Boolean.class || type == boolean.class ||
type == Byte.class || type == byte.class ||
type == Character.class || type == char.class) {
return IntField.class;
} else if(type == Long.class || type == long.class) {
return LongField.class;
}
return null;
}
示例3: setUp
import org.apache.lucene.document.DoubleField; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
super.setUp();
dir = newDirectory();
RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
int numDocs = TestUtil.nextInt(random(), 2049, 4000);
for (int i = 0; i < numDocs; i++) {
Document document = new Document();
document.add(newTextField("english", English.intToEnglish(i), Field.Store.NO));
document.add(newTextField("oddeven", (i % 2 == 0) ? "even" : "odd", Field.Store.NO));
document.add(newStringField("byte", "" + ((byte) random().nextInt()), Field.Store.NO));
document.add(newStringField("short", "" + ((short) random().nextInt()), Field.Store.NO));
document.add(new IntField("int", random().nextInt(), Field.Store.NO));
document.add(new LongField("long", random().nextLong(), Field.Store.NO));
document.add(new FloatField("float", random().nextFloat(), Field.Store.NO));
document.add(new DoubleField("double", random().nextDouble(), Field.Store.NO));
document.add(new NumericDocValuesField("intdocvalues", random().nextInt()));
document.add(new FloatDocValuesField("floatdocvalues", random().nextFloat()));
iw.addDocument(document);
}
reader = iw.getReader();
iw.close();
searcher = newSearcher(reader);
}
示例4: testDoubleFieldMinMax
import org.apache.lucene.document.DoubleField; //导入依赖的package包/类
public void testDoubleFieldMinMax() throws Exception {
Directory dir = newDirectory();
RandomIndexWriter w = new RandomIndexWriter(random(), dir);
int numDocs = atLeast(100);
double minValue = Double.POSITIVE_INFINITY;
double maxValue = Double.NEGATIVE_INFINITY;
for(int i=0;i<numDocs;i++ ){
Document doc = new Document();
double num = random().nextDouble();
minValue = Math.min(num, minValue);
maxValue = Math.max(num, maxValue);
doc.add(new DoubleField("field", num, Field.Store.NO));
w.addDocument(doc);
}
IndexReader r = w.getReader();
Terms terms = MultiFields.getTerms(r, "field");
assertEquals(minValue, NumericUtils.sortableLongToDouble(NumericUtils.getMinLong(terms)), 0.0);
assertEquals(maxValue, NumericUtils.sortableLongToDouble(NumericUtils.getMaxLong(terms)), 0.0);
r.close();
w.close();
dir.close();
}
示例5: configure
import org.apache.lucene.document.DoubleField; //导入依赖的package包/类
@Override
public void configure(String fieldNameForThisInstance, Map<String, String> properties, Configuration configuration) {
String precisionStepStr = properties.get(NUMERIC_PRECISION_STEP);
if (precisionStepStr != null) {
_precisionStep = Integer.parseInt(precisionStepStr);
_typeStored = new FieldType(DoubleField.TYPE_STORED);
_typeStored.setNumericPrecisionStep(_precisionStep);
_typeStored.freeze();
_typeNotStored = new FieldType(DoubleField.TYPE_NOT_STORED);
_typeNotStored.setNumericPrecisionStep(_precisionStep);
_typeNotStored.freeze();
} else {
_typeStored = DoubleField.TYPE_STORED;
_typeNotStored = DoubleField.TYPE_NOT_STORED;
}
}
示例6: setUp
import org.apache.lucene.document.DoubleField; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
super.setUp();
dir = newDirectory();
RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
int numDocs = _TestUtil.nextInt(random(), 2049, 4000);
for (int i = 0; i < numDocs; i++) {
Document document = new Document();
document.add(newTextField("english", English.intToEnglish(i), Field.Store.NO));
document.add(newTextField("oddeven", (i % 2 == 0) ? "even" : "odd", Field.Store.NO));
document.add(newStringField("byte", "" + ((byte) random().nextInt()), Field.Store.NO));
document.add(newStringField("short", "" + ((short) random().nextInt()), Field.Store.NO));
document.add(new IntField("int", random().nextInt(), Field.Store.NO));
document.add(new LongField("long", random().nextLong(), Field.Store.NO));
document.add(new FloatField("float", random().nextFloat(), Field.Store.NO));
document.add(new DoubleField("double", random().nextDouble(), Field.Store.NO));
document.add(new NumericDocValuesField("intdocvalues", random().nextInt()));
document.add(new FloatDocValuesField("floatdocvalues", random().nextFloat()));
iw.addDocument(document);
}
reader = iw.getReader();
iw.close();
searcher = newSearcher(reader);
}
示例7: addCorner
import org.apache.lucene.document.DoubleField; //导入依赖的package包/类
private void addCorner(IndexWriter iwriter, StreetVertex sv) throws IOException {
String mainStreet = null;
String crossStreet = null;
// TODO score based on OSM street type, using intersection nodes instead of vertices.
for (PlainStreetEdge pse : Iterables.filter(sv.getOutgoing(), PlainStreetEdge.class)) {
if (mainStreet == null) {
mainStreet = pse.getName();
} else {
crossStreet = pse.getName();
}
}
if ((mainStreet == null) || (crossStreet == null)) { return; }
if (mainStreet.equals(crossStreet)) { return; }
Document doc = new Document();
doc.add(new TextField("name", mainStreet + " & " + crossStreet, Field.Store.YES));
doc.add(new DoubleField("lat", sv.getLat(), Field.Store.YES));
doc.add(new DoubleField("lon", sv.getLon(), Field.Store.YES));
doc.add(new StringField("category", Category.CORNER.name(), Field.Store.YES));
iwriter.addDocument(doc);
}
示例8: addToDoc
import org.apache.lucene.document.DoubleField; //导入依赖的package包/类
void addToDoc(Document doc, Double value){
Preconditions.checkArgument(valueType == Double.class);
if(value == null){
return;
}
doc.add(new DoubleField(indexFieldName, value, stored ? Store.YES : Store.NO));
if(isSorted()){
Preconditions.checkArgument(sortedValueType == SearchFieldSorting.FieldType.DOUBLE);
doc.add(new DoubleDocValuesField(indexFieldName, value));
}
}
示例9: getField
import org.apache.lucene.document.DoubleField; //导入依赖的package包/类
public Field getField(ValueSource value) {
if (value.isNull())
return null;
Field.Store store = Field.Store.NO; // Only store hkey.
switch (fieldType) {
case INT:
switch (TInstance.underlyingType(value.getType())) {
case INT_8:
return new IntField(name, value.getInt8(), store);
case INT_16:
return new IntField(name, value.getInt16(), store);
case UINT_16:
return new IntField(name, value.getUInt16(), store);
case INT_32:
default:
return new IntField(name, value.getInt32(), store);
}
case LONG:
return new LongField(name, value.getInt64(), store);
case FLOAT:
return new FloatField(name, value.getFloat(), store);
case DOUBLE:
return new DoubleField(name, value.getDouble(), store);
case STRING:
switch (TInstance.underlyingType(value.getType())) {
case STRING:
return new StringField(name, value.getString(), store);
default:
{
StringBuilder str = new StringBuilder();
value.getType().format(value, AkibanAppender.of(str));
return new StringField(name, str.toString(), store);
}
}
case TEXT:
return new TextField(name, value.getString(), store);
default:
return null;
}
}
示例10: createDocument
import org.apache.lucene.document.DoubleField; //导入依赖的package包/类
private Document createDocument(int rowId, Object[] row) {
Document doc = new Document();
if (row == null)
return doc;
try {
//FieldType crosscol = new FieldType();
//crosscol.setStored(true);
//crosscol.setTokenized(false);
//doc.add(new Field("at__rowid__", Integer.toString(rowId),
//Field.Store.YES, Field.Index.UN_TOKENIZED)); // for cross column search
doc.add(new StringField("at__rowid__", Integer.toString(rowId),Field.Store.YES) );
// crosscol));
//FieldType forhive = new FieldType();
//forhive.setStored(true);
//forhive.setTokenized(true);
for (int i = 0; i < row.length; i++) {
if (row[i] != null && colName[i] != null)
//doc.add(new Field(colName[i], row[i].toString(),
// Field.Store.NO, Field.Index.TOKENIZED)); we have to do hive query
// Field.Store.YES, Field.Index.TOKENIZED));
if(row[i] instanceof java.lang.Number ) {
doc.add(new DoubleField(colName[i], new Double(row[i].toString()),Field.Store.YES));
}
else if (row[i] instanceof java.util.Date)
doc.add(new TextField(colName[i], DateTools.dateToString((Date) row[i],DateTools.Resolution.SECOND),Field.Store.YES));
else
doc.add(new TextField(colName[i], row[i].toString(),Field.Store.YES));
//forhive));
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("\n " + e.getMessage());
System.out.println("\n Error: Document Creation Error");
}
return doc;
}
示例11: addField
import org.apache.lucene.document.DoubleField; //导入依赖的package包/类
/**
* add lucene field in document
* @param doc document
* @param name fieldName
* @param val value
* @param type field original Type
* @param store store
* @param textFieldable isTextField
* @return if true, added document
*/
private boolean addField(Document doc, String name, Object val, Type type, Store store, TextFieldable textFieldable, NoIndex noIndex) {
boolean add = true;
if (noIndex != null) {
if (type == Character.class || type == char.class) {
val = (int) val;
} else if(type == Boolean.class || type == boolean.class) {
val = (boolean)val ? 1 : 0;
}
doc.add(new StoredField(name, val.toString()));
} else if (textFieldable != null) {
doc.add(new TextField(name, val.toString(), store));
} else if(type == String.class) {
doc.add(new StringField(name, val.toString(), store));
}else if (type == Double.class || type == double.class) {
doc.add(new DoubleField(name, (double) val, store));
} else if(type == Float.class || type == float.class) {
doc.add(new FloatField(name, (float) val, store));
} else if(type == Short.class || type == short.class ||
type == Integer.class || type == int.class ||
type == Byte.class || type == byte.class) {
doc.add(new IntField(name, Integer.valueOf(val.toString()), store));
} else if(type == Character.class || type == char.class) {
doc.add(new IntField(name, Integer.valueOf((char)val), store));
} else if(type == Boolean.class || type == boolean.class) {
if ((boolean)val) {
doc.add(new IntField(name, 1, store));
} else {
doc.add(new IntField(name, 0, store));
}
} else if(type == Long.class || type == long.class) {
doc.add(new LongField(name, (long) val, store));
} else {
add = false;
}
return add;
}
示例12: doLogic
import org.apache.lucene.document.DoubleField; //导入依赖的package包/类
@Override
public int doLogic() throws Exception {
List<IndexableField> fields = doc.getFields();
Analyzer analyzer = getRunData().getAnalyzer();
int tokenCount = 0;
for(final IndexableField field : fields) {
if (!field.fieldType().tokenized() ||
field instanceof IntField ||
field instanceof LongField ||
field instanceof FloatField ||
field instanceof DoubleField) {
continue;
}
final TokenStream stream = field.tokenStream(analyzer, null);
// reset the TokenStream to the first token
stream.reset();
TermToBytesRefAttribute termAtt = stream.getAttribute(TermToBytesRefAttribute.class);
while(stream.incrementToken()) {
termAtt.fillBytesRef();
tokenCount++;
}
stream.end();
stream.close();
}
totalTokenCount += tokenCount;
return tokenCount;
}
示例13: index
import org.apache.lucene.document.DoubleField; //导入依赖的package包/类
/** Build the example index. */
public void index() throws IOException {
IndexWriter writer = new IndexWriter(indexDir, new IndexWriterConfig(FacetExamples.EXAMPLES_VER,
new WhitespaceAnalyzer()));
// TODO: we could index in radians instead ... saves all the conversions in getBoundingBoxFilter
// Add documents with latitude/longitude location:
Document doc = new Document();
doc.add(new DoubleField("latitude", 40.759011, Field.Store.NO));
doc.add(new DoubleField("longitude", -73.9844722, Field.Store.NO));
writer.addDocument(doc);
doc = new Document();
doc.add(new DoubleField("latitude", 40.718266, Field.Store.NO));
doc.add(new DoubleField("longitude", -74.007819, Field.Store.NO));
writer.addDocument(doc);
doc = new Document();
doc.add(new DoubleField("latitude", 40.7051157, Field.Store.NO));
doc.add(new DoubleField("longitude", -74.0088305, Field.Store.NO));
writer.addDocument(doc);
// Open near-real-time searcher
searcher = new IndexSearcher(DirectoryReader.open(writer, true));
writer.close();
}
示例14: BBoxStrategy
import org.apache.lucene.document.DoubleField; //导入依赖的package包/类
public BBoxStrategy(SpatialContext ctx, String fieldNamePrefix) {
super(ctx, fieldNamePrefix);
field_bbox = fieldNamePrefix;
field_minX = fieldNamePrefix + SUFFIX_MINX;
field_maxX = fieldNamePrefix + SUFFIX_MAXX;
field_minY = fieldNamePrefix + SUFFIX_MINY;
field_maxY = fieldNamePrefix + SUFFIX_MAXY;
field_xdl = fieldNamePrefix + SUFFIX_XDL;
FieldType fieldType = new FieldType(DoubleField.TYPE_NOT_STORED);
fieldType.setNumericPrecisionStep(8);//Solr's default
fieldType.setDocValueType(FieldInfo.DocValuesType.NUMERIC);
setFieldType(fieldType);
}
示例15: createIndexableFields
import org.apache.lucene.document.DoubleField; //导入依赖的package包/类
/** @see #createIndexableFields(com.spatial4j.core.shape.Shape) */
public Field[] createIndexableFields(Point point) {
FieldType doubleFieldType = new FieldType(DoubleField.TYPE_NOT_STORED);
doubleFieldType.setNumericPrecisionStep(precisionStep);
Field[] f = new Field[2];
f[0] = new DoubleField(fieldNameX, point.getX(), doubleFieldType);
f[1] = new DoubleField(fieldNameY, point.getY(), doubleFieldType);
return f;
}