本文整理汇总了Java中org.apache.lucene.document.FloatField类的典型用法代码示例。如果您正苦于以下问题:Java FloatField类的具体用法?Java FloatField怎么用?Java FloatField使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FloatField类属于org.apache.lucene.document包,在下文中一共展示了FloatField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveField
import org.apache.lucene.document.FloatField; //导入依赖的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;
}
示例2: simpleTest
import org.apache.lucene.document.FloatField; //导入依赖的package包/类
@Test
public void simpleTest() throws IOException {
LuceneValuesDB valuesDB = new LuceneValuesDB();
URL testPath = LuceneValuesDB.class.getResource("test.csv");
@SuppressWarnings("unchecked")
UserDefineDocumentCreator creator = new UserDefineDocumentCreator(new Class[] {
IntField.class,
StringField.class,
FloatField.class,
TextField.class
}, new String[] {
"docNum",
"docType",
"score",
"text"
});
valuesDB.open(new File(testPath.getFile()), new CSVParser(), creator);
assertEquals(1, valuesDB.search("docNum", 0).length);
assertEquals(1, valuesDB.search("docType", "a").length);
assertEquals(2, valuesDB.search("score", "0.1").length);
assertEquals(1, valuesDB.search("text", "this is a pen").length);
}
示例3: setUp
import org.apache.lucene.document.FloatField; //导入依赖的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: testFloatFieldMinMax
import org.apache.lucene.document.FloatField; //导入依赖的package包/类
public void testFloatFieldMinMax() throws Exception {
Directory dir = newDirectory();
RandomIndexWriter w = new RandomIndexWriter(random(), dir);
int numDocs = atLeast(100);
float minValue = Float.POSITIVE_INFINITY;
float maxValue = Float.NEGATIVE_INFINITY;
for(int i=0;i<numDocs;i++ ){
Document doc = new Document();
float num = random().nextFloat();
minValue = Math.min(num, minValue);
maxValue = Math.max(num, maxValue);
doc.add(new FloatField("field", num, Field.Store.NO));
w.addDocument(doc);
}
IndexReader r = w.getReader();
Terms terms = MultiFields.getTerms(r, "field");
assertEquals(minValue, NumericUtils.sortableIntToFloat(NumericUtils.getMinInt(terms)), 0.0f);
assertEquals(maxValue, NumericUtils.sortableIntToFloat(NumericUtils.getMaxInt(terms)), 0.0f);
r.close();
w.close();
dir.close();
}
示例5: configure
import org.apache.lucene.document.FloatField; //导入依赖的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(FloatField.TYPE_STORED);
_typeStored.setNumericPrecisionStep(_precisionStep);
_typeStored.freeze();
_typeNotStored = new FieldType(FloatField.TYPE_NOT_STORED);
_typeNotStored.setNumericPrecisionStep(_precisionStep);
_typeNotStored.freeze();
} else {
_typeStored = FloatField.TYPE_STORED;
_typeNotStored = FloatField.TYPE_NOT_STORED;
}
}
示例6: setUp
import org.apache.lucene.document.FloatField; //导入依赖的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: getField
import org.apache.lucene.document.FloatField; //导入依赖的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;
}
}
示例8: addField
import org.apache.lucene.document.FloatField; //导入依赖的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;
}
示例9: doLogic
import org.apache.lucene.document.FloatField; //导入依赖的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;
}
示例10: floatField
import org.apache.lucene.document.FloatField; //导入依赖的package包/类
@Override
public void floatField(FieldInfo fieldInfo, float value) {
FieldType ft = new FieldType(FloatField.TYPE_NOT_STORED);
ft.setStored(true);
ft.setIndexed(fieldInfo.isIndexed());
doc.add(new FloatField(fieldInfo.name, value, ft));
}
示例11: searchDocuments
import org.apache.lucene.document.FloatField; //导入依赖的package包/类
public List<Document> searchDocuments(String text) {
List<Document> documents = new ArrayList<Document>();
try {
TokenStream tokenStream = analyzer.tokenStream("text", text);
CharTermAttribute charTermAtt = tokenStream.addAttribute(CharTermAttribute.class);
tokenStream.reset();
BooleanQuery bQuery = new BooleanQuery();
while (tokenStream.incrementToken()) {
String token = charTermAtt.toString();
TermQuery tq = new TermQuery(new Term("text", token));
tq.setBoost(2f);
bQuery.add(tq, Occur.MUST);
}
tokenStream.close();
TopDocs results = searcher.search(bQuery, 100000);
ScoreDoc[] hits = results.scoreDocs;
for(ScoreDoc hit : hits) {
Document doc = searcher.doc(hit.doc);
doc.add(new FloatField("score", hit.score, FloatField.TYPE_STORED));
documents.add(doc);
}
} catch (Exception e) {
e.printStackTrace();
}
return documents;
}
示例12: doLogic
import org.apache.lucene.document.FloatField; //导入依赖的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);
// reset the TokenStream to the first token
stream.reset();
TermToBytesRefAttribute termAtt = stream.getAttribute(TermToBytesRefAttribute.class);
while(stream.incrementToken()) {
termAtt.fillBytesRef();
tokenCount++;
}
}
totalTokenCount += tokenCount;
return tokenCount;
}
示例13: setUp
import org.apache.lucene.document.FloatField; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
super.setUp();
dir = newDirectory();
RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
int numDocs = atLeast(200);
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(newStringField("bytes", _TestUtil.randomRealisticUnicodeString(random()), Field.Store.NO));
document.add(newStringField("bytesval", _TestUtil.randomRealisticUnicodeString(random()), Field.Store.NO));
document.add(new DoubleField("double", random().nextDouble(), Field.Store.NO));
if (supportsDocValues) {
document.add(new NumericDocValuesField("intdocvalues", random().nextInt()));
document.add(new FloatDocValuesField("floatdocvalues", random().nextFloat()));
document.add(new SortedDocValuesField("sortedbytesdocvalues", new BytesRef(_TestUtil.randomRealisticUnicodeString(random()))));
document.add(new SortedDocValuesField("sortedbytesdocvaluesval", new BytesRef(_TestUtil.randomRealisticUnicodeString(random()))));
document.add(new BinaryDocValuesField("straightbytesdocvalues", new BytesRef(_TestUtil.randomRealisticUnicodeString(random()))));
}
iw.addDocument(document);
}
reader = iw.getReader();
iw.close();
searcher = newSearcher(reader);
}
示例14: getFieldsForColumn
import org.apache.lucene.document.FloatField; //导入依赖的package包/类
@Override
public Iterable<? extends Field> getFieldsForColumn(String family, Column column) {
String name = getName(family, column.getName());
float value = Float.parseFloat(column.getValue());
FloatField field = new FloatField(name, value, _typeStored);
if (isSortEnable()) {
return addSort(name, Float.floatToRawIntBits(value), field);
}
return makeIterable(field);
}
示例15: getFieldsForSubColumn
import org.apache.lucene.document.FloatField; //导入依赖的package包/类
@Override
public Iterable<? extends Field> getFieldsForSubColumn(String family, Column column, String subName) {
String name = getName(family, column.getName(), subName);
float value = Float.parseFloat(column.getValue());
FloatField field = new FloatField(name, value, _typeNotStored);
if (isSortEnable()) {
return addSort(name, Float.floatToRawIntBits(value), field);
}
return makeIterable(field);
}