From 18a2a2b5f550274bacd4a6471a7f3a733f0207f0 Mon Sep 17 00:00:00 2001 From: Robert Newson Date: Tue, 4 Nov 2014 23:47:39 +0000 Subject: [PATCH] Use the same precisionStep when indexing as when querying Doing otherwise leads to all kinds of crazy results. closes #207 --- .../couchdb/lucene/couchdb/FieldType.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/github/rnewson/couchdb/lucene/couchdb/FieldType.java b/src/main/java/com/github/rnewson/couchdb/lucene/couchdb/FieldType.java index aa5eb0d9..72139d7b 100644 --- a/src/main/java/com/github/rnewson/couchdb/lucene/couchdb/FieldType.java +++ b/src/main/java/com/github/rnewson/couchdb/lucene/couchdb/FieldType.java @@ -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); @@ -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); } @@ -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); @@ -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); } @@ -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); @@ -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); } @@ -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); @@ -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); } @@ -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); @@ -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); } @@ -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(), @@ -196,10 +196,8 @@ private static 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; }