Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing numeric values in Lucene 6.5.0

Tags:

java

lucene

I need to Store the Numeric field in the Lucene docs, but Lucene 6.5.1 the signature of the NumericField is like

NumericDocValuesField(String name, long value)

In older lucene versions the method is like,

NumericField(String, Field.Store, boolean)

. Can someone guide me how to store the numeric values in the document using lucene6.5.1.

Regards,
Raghavan

like image 540
Raghavan Avatar asked Oct 29 '25 16:10

Raghavan


1 Answers

NumericDocValuesField is used for scoring/sorting only: 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

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);
like image 117
dom Avatar answered Oct 31 '25 06:10

dom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!