在Lucene 6.5.0中存储数值

时间:2017-07-05 12:36:35

标签: java lucene

我需要将Numeric字段存储在Lucene文档中,但Lucene 6.5.1 NumericField的签名就像

  

NumericDocValuesField(String name,long value)

在较旧的lucene版本中,该方法就像,

  

NumericField(String,Field.Store,boolean)

。 有人可以指导我如何使用lucene6.5.1将数值存储在文档中。

的问候,
拉加

2 个答案:

答案 0 :(得分:3)

NumericDocValuesField仅用于评分/排序: http://lucene.apache.org/core/6_5_0/core/org/apache/lucene/document/NumericDocValuesField.html

如果您想存储任何类型的值(包括数字),您必须使用StoredField: https://lucene.apache.org/core/6_5_0/core/org/apache/lucene/document/StoredField.html

根据您的需要,您必须为多种目的添加多个字段。如果你有一个数字值,你喜欢做范围查询和排序,你会做这样的事情:

// for range queries
new LongPoint(field, value);
// for storing the value
new StoredField(field, value);
// for sorting / scoring
new NumericDocValuesField(field, value);

答案 1 :(得分:0)

使用特殊类型的数字字段:

IntField intField = new IntField("int_value", 100, Field.Store.YES);
LongField longField = new LongField("long_value", 100L, Field.Store.
YES);
FloatField floatField = new FloatField("float_value", 100.0F, Field.
Store.YES);
DoubleField doubleField = new DoubleField("double_value", 100.0D, 
Field.Store.YES);

如果需要,您可以存储其值并对其进行排序。所有这些字段都是可索引的。