在 Lucene 6.5.0 中存储数值

Rag*_*van 4 java lucene

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

NumericDocValuesField(字符串名称,长值)

在旧的 lucene 版本中,该方法是这样的,

NumericField(字符串、Field.Store、布尔值)

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

问候,
拉格万

dom*_*dom 6

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);
Run Code Online (Sandbox Code Playgroud)