Skip to content
This repository has been archived by the owner on May 4, 2023. It is now read-only.

Commit

Permalink
Use the same precisionStep when indexing as when querying
Browse files Browse the repository at this point in the history
Doing otherwise leads to all kinds of crazy results.

closes #207
  • Loading branch information
rnewson committed Nov 4, 2014
1 parent 71cee3b commit 18a2a2b
Showing 1 changed file with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

public enum FieldType {

DATE(8, SortField.Type.LONG) {
DATE(SortField.Type.LONG) {
@Override
public LongField toField(final String name, final Object value, final ViewSettings settings) throws ParseException {
return boost(new LongField(name, toDate(value), settings.getStore()), settings);
Expand All @@ -38,7 +38,7 @@ public LongField toField(final String name, final Object value, final ViewSettin
public Query toRangeQuery(final String name, final String lower, final String upper,
final boolean lowerInclusive, final boolean upperInclusive)
throws ParseException {
return NumericRangeQuery.newLongRange(name, precisionStep, toDate(lower), toDate(upper),
return NumericRangeQuery.newLongRange(name, toDate(lower), toDate(upper),
lowerInclusive, upperInclusive);
}

Expand All @@ -51,7 +51,7 @@ public Query toTermQuery(final String name, final String text) throws ParseExcep
}

},
DOUBLE(8, SortField.Type.DOUBLE) {
DOUBLE(SortField.Type.DOUBLE) {
@Override
public DoubleField toField(final String name, final Object value, final ViewSettings settings) {
return boost(new DoubleField(name, toDouble(value), settings.getStore()), settings);
Expand All @@ -60,7 +60,7 @@ public DoubleField toField(final String name, final Object value, final ViewSett
@Override
public Query toRangeQuery(final String name, final String lower, final String upper,
final boolean lowerInclusive, final boolean upperInclusive) {
return NumericRangeQuery.newDoubleRange(name, precisionStep, toDouble(lower), toDouble(upper),
return NumericRangeQuery.newDoubleRange(name, toDouble(lower), toDouble(upper),
lowerInclusive, upperInclusive);
}

Expand All @@ -80,7 +80,7 @@ private double toDouble(final Object obj) {
}

},
FLOAT(4, SortField.Type.FLOAT) {
FLOAT(SortField.Type.FLOAT) {
@Override
public FloatField toField(final String name, final Object value, final ViewSettings settings) {
return boost(new FloatField(name, toFloat(value), settings.getStore()), settings);
Expand All @@ -89,7 +89,7 @@ public FloatField toField(final String name, final Object value, final ViewSetti
@Override
public Query toRangeQuery(final String name, final String lower, final String upper,
final boolean lowerInclusive, final boolean upperInclusive) {
return NumericRangeQuery.newFloatRange(name, precisionStep, toFloat(lower), toFloat(upper),
return NumericRangeQuery.newFloatRange(name, toFloat(lower), toFloat(upper),
lowerInclusive, upperInclusive);
}

Expand All @@ -108,7 +108,7 @@ private float toFloat(final Object obj) {
return Float.parseFloat(obj.toString());
}
},
INT(4, SortField.Type.INT) {
INT(SortField.Type.INT) {
@Override
public IntField toField(final String name, final Object value, final ViewSettings settings) {
return boost(new IntField(name, toInt(value), settings.getStore()), settings);
Expand All @@ -117,7 +117,7 @@ public IntField toField(final String name, final Object value, final ViewSetting
@Override
public Query toRangeQuery(final String name, final String lower, final String upper,
final boolean lowerInclusive, final boolean upperInclusive) {
return NumericRangeQuery.newIntRange(name, precisionStep, toInt(lower), toInt(upper),
return NumericRangeQuery.newIntRange(name, toInt(lower), toInt(upper),
lowerInclusive, upperInclusive);
}

Expand All @@ -136,7 +136,7 @@ private int toInt(final Object obj) {
}

},
LONG(8, SortField.Type.LONG) {
LONG(SortField.Type.LONG) {
@Override
public LongField toField(final String name, final Object value, final ViewSettings settings) {
return boost(new LongField(name, toLong(value), settings.getStore()), settings);
Expand All @@ -145,7 +145,7 @@ public LongField toField(final String name, final Object value, final ViewSettin
@Override
public Query toRangeQuery(final String name, final String lower, final String upper,
final boolean lowerInclusive, final boolean upperInclusive) {
return NumericRangeQuery.newLongRange(name, precisionStep, toLong(lower), toLong(upper),
return NumericRangeQuery.newLongRange(name, toLong(lower), toLong(upper),
lowerInclusive, upperInclusive);
}

Expand All @@ -164,7 +164,7 @@ public Query toTermQuery(final String name, final String text) {
}

},
STRING(0, SortField.Type.STRING) {
STRING(SortField.Type.STRING) {
@Override
public Field toField(final String name, final Object value, final ViewSettings settings) {
return boost(new Field(name, value.toString(), settings.getStore(), settings.getIndex(),
Expand Down Expand Up @@ -196,10 +196,8 @@ private static <T extends Field> T boost(final T field, final ViewSettings setti

private final SortField.Type type;

protected final int precisionStep;

private FieldType(final int precisionStep, final SortField.Type type) {
this.precisionStep = precisionStep;
private FieldType(final SortField.Type type) {
this.type = type;
}

Expand Down

0 comments on commit 18a2a2b

Please sign in to comment.