Index: src/java/org/apache/lucene/document/NumericField.java
===================================================================
--- src/java/org/apache/lucene/document/NumericField.java (revision 962932)
+++ src/java/org/apache/lucene/document/NumericField.java (working copy)
@@ -142,6 +142,7 @@
*/
public final class NumericField extends AbstractField {
+ final int divisor;
private final NumericTokenStream tokenStream;
/**
@@ -153,7 +154,7 @@
* @param name the field name
*/
public NumericField(String name) {
- this(name, NumericUtils.PRECISION_STEP_DEFAULT, Field.Store.NO, true);
+ this(name, NumericUtils.PRECISION_STEP_DEFAULT, 1, Field.Store.NO, true);
}
/**
@@ -167,7 +168,7 @@
* @param index if the field should be indexed using {@link NumericTokenStream}
*/
public NumericField(String name, Field.Store store, boolean index) {
- this(name, NumericUtils.PRECISION_STEP_DEFAULT, store, index);
+ this(name, NumericUtils.PRECISION_STEP_DEFAULT, 1, store, index);
}
/**
@@ -180,7 +181,7 @@
* @param precisionStep the used precision step
*/
public NumericField(String name, int precisionStep) {
- this(name, precisionStep, Field.Store.NO, true);
+ this(name, precisionStep, 1, Field.Store.NO, true);
}
/**
@@ -195,8 +196,28 @@
* @param index if the field should be indexed using {@link NumericTokenStream}
*/
public NumericField(String name, int precisionStep, Field.Store store, boolean index) {
+ this(name, precisionStep, 1, store, index);
+ }
+
+ /**
+ * Creates a field for numeric values with the specified
+ * precisionStep. The instance is not yet initialized with
+ * a numeric value, before indexing a document containing this field,
+ * set a value using the various set???Value() methods.
+ * @param name the field name
+ * @param precisionStep the used precision step
+ * @param divisor the used precision step
+ * @param store if the field should be stored in plain text form
+ * (according to toString(value) of the used data type)
+ * @param index if the field should be indexed using {@link NumericTokenStream}
+ */
+ public NumericField(String name, int precisionStep, final int divisor, Field.Store store, boolean index) {
super(name, store, index ? Field.Index.ANALYZED_NO_NORMS : Field.Index.NO, Field.TermVector.NO);
+ if (divisor <= 0) {
+ throw new IllegalArgumentException("divisor must be positive");
+ }
setOmitTermFreqAndPositions(true);
+ this.divisor = divisor;
tokenStream = new NumericTokenStream(precisionStep);
}
@@ -233,7 +254,7 @@
* document.add(new NumericField(name, precisionStep).setLongValue(value))
*/
public NumericField setLongValue(final long value) {
- tokenStream.setLongValue(value);
+ tokenStream.setLongValue(value / divisor);
fieldsData = Long.valueOf(value);
return this;
}
@@ -245,7 +266,7 @@
* document.add(new NumericField(name, precisionStep).setIntValue(value))
*/
public NumericField setIntValue(final int value) {
- tokenStream.setIntValue(value);
+ tokenStream.setIntValue(value / divisor);
fieldsData = Integer.valueOf(value);
return this;
}
@@ -257,7 +278,7 @@
* document.add(new NumericField(name, precisionStep).setDoubleValue(value))
*/
public NumericField setDoubleValue(final double value) {
- tokenStream.setDoubleValue(value);
+ tokenStream.setDoubleValue(value / divisor);
fieldsData = Double.valueOf(value);
return this;
}
@@ -269,7 +290,7 @@
* document.add(new NumericField(name, precisionStep).setFloatValue(value))
*/
public NumericField setFloatValue(final float value) {
- tokenStream.setFloatValue(value);
+ tokenStream.setFloatValue(value / divisor);
fieldsData = Float.valueOf(value);
return this;
}