简体   繁体   English

在Lucene 6.5.0中存储数值

[英]Storing numeric values in Lucene 6.5.0

I need to Store the Numeric field in the Lucene docs, but Lucene 6.5.1 the signature of the NumericField is like 我需要在Lucene文档中存储Numeric字段,但是Lucene 6.5.1 NumericField的签名就像

NumericDocValuesField(String name, long value) NumericDocValuesField(字符串名称,长值)

In older lucene versions the method is like, 在较旧的lucene版本中,方法类似于

NumericField(String, Field.Store, boolean) NumericField(String,Field.Store,boolean)

. Can someone guide me how to store the numeric values in the document using lucene6.5.1. 有人可以指导我如何使用lucene6.5.1将数字值存储在文档中。

Regards, 问候,
Raghavan 拉加万

NumericDocValuesField is used for scoring/sorting only: http://lucene.apache.org/core/6_5_0/core/org/apache/lucene/document/NumericDocValuesField.html NumericDocValuesField仅用于评分/排序: http ://lucene.apache.org/core/6_5_0/core/org/apache/lucene/document/NumericDocValuesField.html

If you like to store any kind of values (including numeric) you have to use a StoredField: https://lucene.apache.org/core/6_5_0/core/org/apache/lucene/document/StoredField.html 如果您想存储任何类型的值(包括数字),则必须使用StoredField: https ://lucene.apache.org/core/6_5_0/core/org/apache/lucene/document/StoredField.html

Depending on what you need you have to add multiple fields for multiple purposes. 根据您的需要,您必须添加多个字段以实现多种用途。 If you have a numeric value as long and you like to do range queries and sort you would do something like this: 如果您的数字值很长,并且希望进行范围查询和排序,则可以执行以下操作:

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

Use special type oriented numeric fields: 使用面向类型的特殊数字字段:

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);

You can store their values and sort them if you need. 您可以存储它们的值并在需要时对其进行排序。 All of those field are indexable. 所有这些字段都是可索引的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM