You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2014/12/07 11:52:05 UTC
svn commit: r1643659 [5/7] - in /lucene/dev/branches/lucene6005/lucene: ./
analysis/common/src/test/org/apache/lucene/analysis/core/
analysis/icu/src/test/org/apache/lucene/collation/
backward-codecs/src/test/org/apache/lucene/index/ benchmark/src/java...
Added: lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/util/TestNumericUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/util/TestNumericUtils.java?rev=1643659&view=auto
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/util/TestNumericUtils.java (added)
+++ lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/util/TestNumericUtils.java Sun Dec 7 10:52:03 2014
@@ -0,0 +1,112 @@
+package org.apache.lucene.util;
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Random;
+
+import org.apache.lucene.document.Document;
+
+public class TestNumericUtils extends LuceneTestCase {
+
+ public void testDoubles() throws Exception {
+ double[] vals=new double[]{
+ Double.NEGATIVE_INFINITY, -2.3E25, -1.0E15, -1.0, -1.0E-1, -1.0E-2, -0.0,
+ +0.0, 1.0E-2, 1.0E-1, 1.0, 1.0E15, 2.3E25, Double.POSITIVE_INFINITY, Double.NaN
+ };
+ long[] longVals=new long[vals.length];
+
+ // check forward and back conversion
+ for (int i=0; i<vals.length; i++) {
+ longVals[i]=NumericUtils.doubleToLong(vals[i]);
+ assertTrue( "forward and back conversion should generate same double", Double.compare(vals[i], NumericUtils.longToDouble(longVals[i]))==0 );
+ }
+
+ // check sort order (prefixVals should be ascending)
+ for (int i=1; i<longVals.length; i++) {
+ assertTrue( "check sort order", longVals[i-1] < longVals[i] );
+ }
+ }
+
+ public static final double[] DOUBLE_NANs = {
+ Double.NaN,
+ Double.longBitsToDouble(0x7ff0000000000001L),
+ Double.longBitsToDouble(0x7fffffffffffffffL),
+ Double.longBitsToDouble(0xfff0000000000001L),
+ Double.longBitsToDouble(0xffffffffffffffffL)
+ };
+
+ public void testSortableDoubleNaN() {
+ final long plusInf = NumericUtils.doubleToLong(Double.POSITIVE_INFINITY);
+ for (double nan : DOUBLE_NANs) {
+ assertTrue(Double.isNaN(nan));
+ final long sortable = NumericUtils.doubleToLong(nan);
+ assertTrue("Double not sorted correctly: " + nan + ", long repr: "
+ + sortable + ", positive inf.: " + plusInf, sortable > plusInf);
+ }
+ }
+
+ public void testFloats() throws Exception {
+ float[] vals=new float[]{
+ Float.NEGATIVE_INFINITY, -2.3E25f, -1.0E15f, -1.0f, -1.0E-1f, -1.0E-2f, -0.0f,
+ +0.0f, 1.0E-2f, 1.0E-1f, 1.0f, 1.0E15f, 2.3E25f, Float.POSITIVE_INFINITY, Float.NaN
+ };
+ int[] intVals=new int[vals.length];
+
+ // check forward and back conversion
+ for (int i=0; i<vals.length; i++) {
+ intVals[i]=NumericUtils.floatToInt(vals[i]);
+ assertTrue( "forward and back conversion should generate same double", Float.compare(vals[i], NumericUtils.intToFloat(intVals[i]))==0 );
+ }
+
+ // check sort order (prefixVals should be ascending)
+ for (int i=1; i<intVals.length; i++) {
+ assertTrue( "check sort order", intVals[i-1] < intVals[i] );
+ }
+ }
+
+ public static final float[] FLOAT_NANs = {
+ Float.NaN,
+ Float.intBitsToFloat(0x7f800001),
+ Float.intBitsToFloat(0x7fffffff),
+ Float.intBitsToFloat(0xff800001),
+ Float.intBitsToFloat(0xffffffff)
+ };
+
+ public void testSortableFloatNaN() {
+ final int plusInf = NumericUtils.floatToInt(Float.POSITIVE_INFINITY);
+ for (float nan : FLOAT_NANs) {
+ assertTrue(Float.isNaN(nan));
+ final int sortable = NumericUtils.floatToInt(nan);
+ assertTrue("Float not sorted correctly: " + nan + ", int repr: "
+ + sortable + ", positive inf.: " + plusInf, sortable > plusInf);
+ }
+ }
+
+ public void testHalfFloat() throws Exception {
+ for(int x=Short.MIN_VALUE;x<=Short.MAX_VALUE;x++) {
+ BytesRef bytes = NumericUtils.shortToBytes((short) x);
+ assertEquals(x, NumericUtils.bytesToShort(bytes));
+
+ short y = NumericUtils.sortableHalfFloatBits((short) x);
+ assertEquals(x, NumericUtils.sortableHalfFloatBits(y));
+ }
+ }
+}
Modified: lucene/dev/branches/lucene6005/lucene/demo/src/java/org/apache/lucene/demo/facet/DistanceFacetsExample.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/demo/src/java/org/apache/lucene/demo/facet/DistanceFacetsExample.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/demo/src/java/org/apache/lucene/demo/facet/DistanceFacetsExample.java (original)
+++ lucene/dev/branches/lucene6005/lucene/demo/src/java/org/apache/lucene/demo/facet/DistanceFacetsExample.java Sun Dec 7 10:52:03 2014
@@ -173,7 +173,7 @@ public class DistanceFacetsExample imple
BooleanFilter f = new BooleanFilter();
// Add latitude range filter:
- f.add(fieldTypes.newRangeFilter("latitude", Math.toDegrees(minLat), true, Math.toDegrees(maxLat), true),
+ f.add(fieldTypes.newDoubleRangeFilter("latitude", Math.toDegrees(minLat), true, Math.toDegrees(maxLat), true),
BooleanClause.Occur.MUST);
// Add longitude range filter:
@@ -181,13 +181,13 @@ public class DistanceFacetsExample imple
// The bounding box crosses the international date
// line:
BooleanFilter lonF = new BooleanFilter();
- lonF.add(fieldTypes.newRangeFilter("longitude", Math.toDegrees(minLng), true, null, true),
+ lonF.add(fieldTypes.newDoubleRangeFilter("longitude", Math.toDegrees(minLng), true, null, true),
BooleanClause.Occur.SHOULD);
- lonF.add(fieldTypes.newRangeFilter("longitude", null, true, Math.toDegrees(maxLng), true),
+ lonF.add(fieldTypes.newDoubleRangeFilter("longitude", null, true, Math.toDegrees(maxLng), true),
BooleanClause.Occur.SHOULD);
f.add(lonF, BooleanClause.Occur.MUST);
} else {
- f.add(fieldTypes.newRangeFilter("longitude", Math.toDegrees(minLng), true, Math.toDegrees(maxLng), true),
+ f.add(fieldTypes.newDoubleRangeFilter("longitude", Math.toDegrees(minLng), true, Math.toDegrees(maxLng), true),
BooleanClause.Occur.MUST);
}
Modified: lucene/dev/branches/lucene6005/lucene/demo/src/java/org/apache/lucene/demo/facet/RangeFacetsExample.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/demo/src/java/org/apache/lucene/demo/facet/RangeFacetsExample.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/demo/src/java/org/apache/lucene/demo/facet/RangeFacetsExample.java (original)
+++ lucene/dev/branches/lucene6005/lucene/demo/src/java/org/apache/lucene/demo/facet/RangeFacetsExample.java Sun Dec 7 10:52:03 2014
@@ -106,7 +106,7 @@ public class RangeFacetsExample implemen
// documents ("browse only"):
DrillDownQuery q = new DrillDownQuery(getConfig());
- q.add("timestamp", new ConstantScoreQuery(fieldTypes.newRangeFilter("timestamp", range.min, range.minInclusive, range.max, range.maxInclusive)));
+ q.add("timestamp", new ConstantScoreQuery(fieldTypes.newLongRangeFilter("timestamp", range.min, range.minInclusive, range.max, range.maxInclusive)));
return searcher.search(q, 10);
}
Modified: lucene/dev/branches/lucene6005/lucene/demo/src/java/org/apache/lucene/demo/xmlparser/FormBasedXmlQueryDemo.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/demo/src/java/org/apache/lucene/demo/xmlparser/FormBasedXmlQueryDemo.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/demo/src/java/org/apache/lucene/demo/xmlparser/FormBasedXmlQueryDemo.java (original)
+++ lucene/dev/branches/lucene6005/lucene/demo/src/java/org/apache/lucene/demo/xmlparser/FormBasedXmlQueryDemo.java Sun Dec 7 10:52:03 2014
@@ -80,7 +80,7 @@ public class FormBasedXmlQueryDemo exten
getServletContext().getResourceAsStream("/WEB-INF/" + xslFile));
//initialize an XML Query Parser for use by all threads
- xmlParser = new CorePlusExtensionsParser(defaultStandardQueryParserField, analyzer);
+ xmlParser = new CorePlusExtensionsParser(searcher.getFieldTypes(), defaultStandardQueryParserField, analyzer);
} catch (Exception e) {
throw new ServletException("Error loading query template", e);
}
@@ -104,7 +104,7 @@ public class FormBasedXmlQueryDemo exten
org.w3c.dom.Document xmlQuery = queryTemplateManager.getQueryAsDOM(completedFormFields);
//Parse the XML to produce a Lucene query
- Query query = xmlParser.getQuery(xmlQuery.getDocumentElement());
+ Query query = xmlParser.getQuery(searcher.getFieldTypes(), xmlQuery.getDocumentElement());
//Run the query
TopDocs topDocs = searcher.search(query, 10);
Modified: lucene/dev/branches/lucene6005/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java (original)
+++ lucene/dev/branches/lucene6005/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java Sun Dec 7 10:52:03 2014
@@ -28,6 +28,7 @@ import org.apache.lucene.search.DocIdSet
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.Filter;
import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.NumericUtils;
/** Represents a range over double values.
*
@@ -91,8 +92,8 @@ public final class DoubleRange extends R
LongRange toLongRange() {
return new LongRange(label,
- Document.doubleToSortableLong(minIncl), true,
- Document.doubleToSortableLong(maxIncl), true);
+ NumericUtils.doubleToLong(minIncl), true,
+ NumericUtils.doubleToLong(maxIncl), true);
}
@Override
Modified: lucene/dev/branches/lucene6005/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRangeFacetCounts.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRangeFacetCounts.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRangeFacetCounts.java (original)
+++ lucene/dev/branches/lucene6005/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRangeFacetCounts.java Sun Dec 7 10:52:03 2014
@@ -33,6 +33,7 @@ import org.apache.lucene.search.DocIdSet
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.Filter;
import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.NumericUtils;
/** {@link Facets} implementation that computes counts for
* dynamic double ranges from a provided {@link
@@ -83,8 +84,8 @@ public class DoubleRangeFacetCounts exte
for(int i=0;i<ranges.length;i++) {
DoubleRange range = ranges[i];
longRanges[i] = new LongRange(range.label,
- Document.doubleToSortableLong(range.minIncl), true,
- Document.doubleToSortableLong(range.maxIncl), true);
+ NumericUtils.doubleToLong(range.minIncl), true,
+ NumericUtils.doubleToLong(range.maxIncl), true);
}
LongRangeCounter counter = new LongRangeCounter(longRanges);
@@ -119,7 +120,7 @@ public class DoubleRangeFacetCounts exte
}
// Skip missing docs:
if (fv.exists(doc)) {
- counter.add(Document.doubleToSortableLong(fv.doubleVal(doc)));
+ counter.add(NumericUtils.doubleToLong(fv.doubleVal(doc)));
} else {
missingCount++;
}
Modified: lucene/dev/branches/lucene6005/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java (original)
+++ lucene/dev/branches/lucene6005/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java Sun Dec 7 10:52:03 2014
@@ -294,7 +294,7 @@ public class TestRangeFacetCounts extend
// Third search, drill down on "less than or equal to 10":
ddq = new DrillDownQuery(config);
- ddq.add("field", new ConstantScoreQuery(fieldTypes.newRangeFilter("field", 0L, true, 10L, true)));
+ ddq.add("field", new ConstantScoreQuery(fieldTypes.newLongRangeFilter("field", 0L, true, 10L, true)));
dsr = ds.search(null, ddq, 10);
assertEquals(11, dsr.hits.totalHits);
@@ -470,9 +470,9 @@ public class TestRangeFacetCounts extend
Filter fastMatchFilter;
if (random().nextBoolean()) {
if (random().nextBoolean()) {
- fastMatchFilter = fieldTypes.newRangeFilter("field", minValue, true, maxValue, true);
+ fastMatchFilter = fieldTypes.newLongRangeFilter("field", minValue, true, maxValue, true);
} else {
- fastMatchFilter = fieldTypes.newRangeFilter("field", minAcceptedValue, true, maxAcceptedValue, true);
+ fastMatchFilter = fieldTypes.newLongRangeFilter("field", minAcceptedValue, true, maxAcceptedValue, true);
}
} else {
fastMatchFilter = null;
@@ -495,9 +495,9 @@ public class TestRangeFacetCounts extend
DrillDownQuery ddq = new DrillDownQuery(config);
if (random().nextBoolean()) {
if (random().nextBoolean()) {
- ddq.add("field", fieldTypes.newRangeFilter("field", range.min, range.minInclusive, range.max, range.maxInclusive));
+ ddq.add("field", fieldTypes.newLongRangeFilter("field", range.min, range.minInclusive, range.max, range.maxInclusive));
} else {
- ddq.add("field", new ConstantScoreQuery(fieldTypes.newRangeFilter("field", range.min, range.minInclusive, range.max, range.maxInclusive)));
+ ddq.add("field", new ConstantScoreQuery(fieldTypes.newLongRangeFilter("field", range.min, range.minInclusive, range.max, range.maxInclusive)));
}
} else {
ddq.add("field", range.getFilter(fastMatchFilter, vs));
@@ -629,9 +629,9 @@ public class TestRangeFacetCounts extend
Filter fastMatchFilter;
if (random().nextBoolean()) {
if (random().nextBoolean()) {
- fastMatchFilter = fieldTypes.newRangeFilter("field", minValue, true, maxValue, true);
+ fastMatchFilter = fieldTypes.newFloatRangeFilter("field", minValue, true, maxValue, true);
} else {
- fastMatchFilter = fieldTypes.newRangeFilter("field", minAcceptedValue, true, maxAcceptedValue, true);
+ fastMatchFilter = fieldTypes.newFloatRangeFilter("field", minAcceptedValue, true, maxAcceptedValue, true);
}
} else {
fastMatchFilter = null;
@@ -654,9 +654,9 @@ public class TestRangeFacetCounts extend
DrillDownQuery ddq = new DrillDownQuery(config);
if (random().nextBoolean()) {
if (random().nextBoolean()) {
- ddq.add("field", fieldTypes.newRangeFilter("field", (float) range.min, range.minInclusive, (float) range.max, range.maxInclusive));
+ ddq.add("field", fieldTypes.newFloatRangeFilter("field", (float) range.min, range.minInclusive, (float) range.max, range.maxInclusive));
} else {
- ddq.add("field", new ConstantScoreQuery(fieldTypes.newRangeFilter("field", (float) range.min, range.minInclusive, (float) range.max, range.maxInclusive)));
+ ddq.add("field", new ConstantScoreQuery(fieldTypes.newFloatRangeFilter("field", (float) range.min, range.minInclusive, (float) range.max, range.maxInclusive)));
}
} else {
ddq.add("field", range.getFilter(fastMatchFilter, vs));
@@ -772,9 +772,9 @@ public class TestRangeFacetCounts extend
Filter fastMatchFilter;
if (random().nextBoolean()) {
if (random().nextBoolean()) {
- fastMatchFilter = fieldTypes.newRangeFilter("field", minValue, true, maxValue, true);
+ fastMatchFilter = fieldTypes.newDoubleRangeFilter("field", minValue, true, maxValue, true);
} else {
- fastMatchFilter = fieldTypes.newRangeFilter("field", minAcceptedValue, true, maxAcceptedValue, true);
+ fastMatchFilter = fieldTypes.newDoubleRangeFilter("field", minAcceptedValue, true, maxAcceptedValue, true);
}
} else {
fastMatchFilter = null;
@@ -797,9 +797,9 @@ public class TestRangeFacetCounts extend
DrillDownQuery ddq = new DrillDownQuery(config);
if (random().nextBoolean()) {
if (random().nextBoolean()) {
- ddq.add("field", fieldTypes.newRangeFilter("field", range.min, range.minInclusive, range.max, range.maxInclusive));
+ ddq.add("field", fieldTypes.newDoubleRangeFilter("field", range.min, range.minInclusive, range.max, range.maxInclusive));
} else {
- ddq.add("field", new ConstantScoreQuery(fieldTypes.newRangeFilter("field", range.min, range.minInclusive, range.max, range.maxInclusive)));
+ ddq.add("field", new ConstantScoreQuery(fieldTypes.newDoubleRangeFilter("field", range.min, range.minInclusive, range.max, range.maxInclusive)));
}
} else {
ddq.add("field", range.getFilter(fastMatchFilter, vs));
Modified: lucene/dev/branches/lucene6005/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java (original)
+++ lucene/dev/branches/lucene6005/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java Sun Dec 7 10:52:03 2014
@@ -494,7 +494,7 @@ public class HighlighterTest extends Bas
public void testNumericRangeQuery() throws Exception {
// doesn't currently highlight, but make sure it doesn't cause exception either
- query = new ConstantScoreQuery(reader.getFieldTypes().newRangeFilter(NUMERIC_FIELD_NAME, 2, true, 6, true));
+ query = new ConstantScoreQuery(reader.getFieldTypes().newIntRangeFilter(NUMERIC_FIELD_NAME, 2, true, 6, true));
searcher = newSearcher(reader);
hits = searcher.search(query, 100);
int maxNumFragmentsRequired = 2;
Modified: lucene/dev/branches/lucene6005/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java (original)
+++ lucene/dev/branches/lucene6005/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java Sun Dec 7 10:52:03 2014
@@ -98,7 +98,7 @@ public class TestBlockJoin extends Lucen
BooleanQuery childQuery = new BooleanQuery();
childQuery.add(new BooleanClause(new TermQuery(new Term("skill", "java")), Occur.MUST));
- childQuery.add(new BooleanClause(new ConstantScoreQuery(fieldTypes.newRangeFilter("year", 2006, true, 2011, true)), Occur.MUST));
+ childQuery.add(new BooleanClause(new ConstantScoreQuery(fieldTypes.newIntRangeFilter("year", 2006, true, 2011, true)), Occur.MUST));
ToParentBlockJoinQuery childJoinQuery = new ToParentBlockJoinQuery(childQuery, parentsFilter, ScoreMode.Avg);
@@ -152,7 +152,7 @@ public class TestBlockJoin extends Lucen
// Define child document criteria (finds an example of relevant work experience)
BooleanQuery childQuery = new BooleanQuery();
childQuery.add(new BooleanClause(new TermQuery(new Term("skill", "java")), Occur.MUST));
- childQuery.add(new BooleanClause(new ConstantScoreQuery(fieldTypes.newRangeFilter("year", 2006, true, 2011, true)), Occur.MUST));
+ childQuery.add(new BooleanClause(new ConstantScoreQuery(fieldTypes.newIntRangeFilter("year", 2006, true, 2011, true)), Occur.MUST));
// Define parent document criteria (find a resident in the UK)
Query parentQuery = new TermQuery(new Term("country", "United Kingdom"));
@@ -234,7 +234,7 @@ public class TestBlockJoin extends Lucen
IndexSearcher s = newSearcher(r);
FieldTypes fieldTypes = s.getFieldTypes();
- MultiTermQuery qc = new TermRangeQuery("year", Document.intToBytes(2007), Document.intToBytes(2007), true, true);
+ MultiTermQuery qc = new TermRangeQuery("year", NumericUtils.intToBytes(2007), NumericUtils.intToBytes(2007), true, true);
// Hacky: this causes the query to need 2 rewrite
// iterations:
qc.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE);
@@ -306,7 +306,7 @@ public class TestBlockJoin extends Lucen
// Define child document criteria (finds an example of relevant work experience)
BooleanQuery childQuery = new BooleanQuery();
childQuery.add(new BooleanClause(new TermQuery(new Term("skill", "java")), Occur.MUST));
- childQuery.add(new BooleanClause(new ConstantScoreQuery(fieldTypes.newRangeFilter("year", 2006, true, 2011, true)), Occur.MUST));
+ childQuery.add(new BooleanClause(new ConstantScoreQuery(fieldTypes.newIntRangeFilter("year", 2006, true, 2011, true)), Occur.MUST));
// Define parent document criteria (find a resident in the UK)
Query parentQuery = new TermQuery(new Term("country", "United Kingdom"));
@@ -413,7 +413,7 @@ public class TestBlockJoin extends Lucen
FieldTypes fieldTypes = s.getFieldTypes();
ToParentBlockJoinQuery q = new ToParentBlockJoinQuery(
- new ConstantScoreQuery(fieldTypes.newRangeFilter("year", 1990, true, 2010, true)),
+ new ConstantScoreQuery(fieldTypes.newIntRangeFilter("year", 1990, true, 2010, true)),
new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("docType", "resume")))),
ScoreMode.Total
);
@@ -1077,11 +1077,11 @@ public class TestBlockJoin extends Lucen
// Define child document criteria (finds an example of relevant work experience)
BooleanQuery childJobQuery = new BooleanQuery();
childJobQuery.add(new BooleanClause(new TermQuery(new Term("skill", "java")), Occur.MUST));
- childJobQuery.add(new BooleanClause(new ConstantScoreQuery(fieldTypes.newRangeFilter("year", 2006, true, 2011, true)), Occur.MUST));
+ childJobQuery.add(new BooleanClause(new ConstantScoreQuery(fieldTypes.newIntRangeFilter("year", 2006, true, 2011, true)), Occur.MUST));
BooleanQuery childQualificationQuery = new BooleanQuery();
childQualificationQuery.add(new BooleanClause(new TermQuery(new Term("qualification", "maths")), Occur.MUST));
- childQualificationQuery.add(new BooleanClause(new ConstantScoreQuery(fieldTypes.newRangeFilter("year", 1980, true, 2000, true)), Occur.MUST));
+ childQualificationQuery.add(new BooleanClause(new ConstantScoreQuery(fieldTypes.newIntRangeFilter("year", 1980, true, 2000, true)), Occur.MUST));
// Define parent document criteria (find a resident in the UK)
@@ -1226,7 +1226,7 @@ public class TestBlockJoin extends Lucen
// Define child document criteria (finds an example of relevant work experience)
BooleanQuery childQuery = new BooleanQuery();
childQuery.add(new BooleanClause(new TermQuery(new Term("skill", "java")), Occur.MUST));
- childQuery.add(new BooleanClause(new ConstantScoreQuery(fieldTypes.newRangeFilter("year", 2006, true, 2011, true)), Occur.MUST));
+ childQuery.add(new BooleanClause(new ConstantScoreQuery(fieldTypes.newIntRangeFilter("year", 2006, true, 2011, true)), Occur.MUST));
// Wrap the child document query to 'join' any matches
// up to corresponding parent:
Modified: lucene/dev/branches/lucene6005/lucene/misc/src/java/org/apache/lucene/uninverting/FieldCache.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/misc/src/java/org/apache/lucene/uninverting/FieldCache.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/misc/src/java/org/apache/lucene/uninverting/FieldCache.java (original)
+++ lucene/dev/branches/lucene6005/lucene/misc/src/java/org/apache/lucene/uninverting/FieldCache.java Sun Dec 7 10:52:03 2014
@@ -20,7 +20,6 @@ package org.apache.lucene.uninverting;
import java.io.IOException;
import java.io.PrintStream;
-import org.apache.lucene.analysis.NumericTokenStream;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.BinaryDocValues;
import org.apache.lucene.index.IndexReader; // javadocs
@@ -83,32 +82,11 @@ interface FieldCache {
/** Expert: The cache used internally by sorting and range query classes. */
public static FieldCache DEFAULT = new FieldCacheImpl();
- /**
- * A parser instance for int values encoded by {@link NumericUtils}, e.g. when indexed
- * via {@link IntField}/{@link NumericTokenStream}.
- */
- public static final Parser NUMERIC_UTILS_INT_PARSER = new Parser() {
- @Override
- public long parseValue(BytesRef term) {
- return NumericUtils.prefixCodedToInt(term);
- }
-
- @Override
- public TermsEnum termsEnum(Terms terms) throws IOException {
- return NumericUtils.filterPrefixCodedInts(terms.iterator(null));
- }
-
- @Override
- public String toString() {
- return FieldCache.class.getName()+".NUMERIC_UTILS_INT_PARSER";
- }
- };
-
// nocommit rename
- public static final Parser DOCUMENT2_INT_PARSER = new Parser() {
+ public static final Parser DOCUMENT_INT_PARSER = new Parser() {
@Override
public long parseValue(BytesRef term) {
- return Document.bytesToInt(term);
+ return NumericUtils.bytesToInt(term);
}
@Override
@@ -118,38 +96,15 @@ interface FieldCache {
@Override
public String toString() {
- return FieldCache.class.getName()+".DOCUMENT2_INT_PARSER";
- }
- };
-
- /**
- * A parser instance for float values encoded with {@link NumericUtils}, e.g. when indexed
- * via {@link FloatField}/{@link NumericTokenStream}.
- */
- public static final Parser NUMERIC_UTILS_FLOAT_PARSER = new Parser() {
- @Override
- public long parseValue(BytesRef term) {
- int val = NumericUtils.prefixCodedToInt(term);
- if (val<0) val ^= 0x7fffffff;
- return val;
- }
-
- @Override
- public String toString() {
- return FieldCache.class.getName()+".NUMERIC_UTILS_FLOAT_PARSER";
- }
-
- @Override
- public TermsEnum termsEnum(Terms terms) throws IOException {
- return NumericUtils.filterPrefixCodedInts(terms.iterator(null));
+ return FieldCache.class.getName()+".DOCUMENT_INT_PARSER";
}
};
// nocommit rename
- public static final Parser DOCUMENT2_FLOAT_PARSER = new Parser() {
+ public static final Parser DOCUMENT_FLOAT_PARSER = new Parser() {
@Override
public long parseValue(BytesRef term) {
- return Document.sortableFloatBits(Document.bytesToInt(term));
+ return NumericUtils.floatToInt(NumericUtils.bytesToFloat(term));
}
@Override
@@ -159,35 +114,15 @@ interface FieldCache {
@Override
public String toString() {
- return FieldCache.class.getName()+".DOCUMENT2_FLOAT_PARSER";
- }
- };
-
- /**
- * A parser instance for long values encoded by {@link NumericUtils}, e.g. when indexed
- * via {@link LongField}/{@link NumericTokenStream}.
- */
- public static final Parser NUMERIC_UTILS_LONG_PARSER = new Parser() {
- @Override
- public long parseValue(BytesRef term) {
- return NumericUtils.prefixCodedToLong(term);
- }
- @Override
- public String toString() {
- return FieldCache.class.getName()+".NUMERIC_UTILS_LONG_PARSER";
- }
-
- @Override
- public TermsEnum termsEnum(Terms terms) throws IOException {
- return NumericUtils.filterPrefixCodedLongs(terms.iterator(null));
+ return FieldCache.class.getName()+".DOCUMENT_FLOAT_PARSER";
}
};
// nocommit rename
- public static final Parser DOCUMENT2_LONG_PARSER = new Parser() {
+ public static final Parser DOCUMENT_LONG_PARSER = new Parser() {
@Override
public long parseValue(BytesRef term) {
- return Document.bytesToLong(term);
+ return NumericUtils.bytesToLong(term);
}
@Override
@@ -197,37 +132,17 @@ interface FieldCache {
@Override
public String toString() {
- return FieldCache.class.getName()+".DOCUMENT2_LONG_PARSER";
+ return FieldCache.class.getName()+".DOCUMENT_LONG_PARSER";
}
};
- /**
- * A parser instance for double values encoded with {@link NumericUtils}, e.g. when indexed
- * via {@link DoubleField}/{@link NumericTokenStream}.
- */
- public static final Parser NUMERIC_UTILS_DOUBLE_PARSER = new Parser() {
- @Override
- public long parseValue(BytesRef term) {
- long val = NumericUtils.prefixCodedToLong(term);
- if (val<0) val ^= 0x7fffffffffffffffL;
- return val;
- }
- @Override
- public String toString() {
- return FieldCache.class.getName()+".NUMERIC_UTILS_DOUBLE_PARSER";
- }
-
- @Override
- public TermsEnum termsEnum(Terms terms) throws IOException {
- return NumericUtils.filterPrefixCodedLongs(terms.iterator(null));
- }
- };
+ // nocommit half floats?
// nocommit rename
- public static final Parser DOCUMENT2_DOUBLE_PARSER = new Parser() {
+ public static final Parser DOCUMENT_DOUBLE_PARSER = new Parser() {
@Override
public long parseValue(BytesRef term) {
- return Document.sortableDoubleBits(Document.bytesToLong(term));
+ return NumericUtils.doubleToLong(NumericUtils.bytesToDouble(term));
}
@Override
@@ -237,7 +152,7 @@ interface FieldCache {
@Override
public String toString() {
- return FieldCache.class.getName()+".DOCUMENT2_DOUBLE_PARSER";
+ return FieldCache.class.getName()+".DOCUMENT_DOUBLE_PARSER";
}
};
@@ -314,11 +229,6 @@ interface FieldCache {
* subsequent calls will share the same cache entry. */
public SortedDocValues getTermsIndex(LeafReader reader, String field, float acceptableOverheadRatio) throws IOException;
- /** Can be passed to {@link #getDocTermOrds} to filter for 32-bit numeric terms */
- public static final BytesRef INT32_TERM_PREFIX = new BytesRef(new byte[] { NumericUtils.SHIFT_START_INT });
- /** Can be passed to {@link #getDocTermOrds} to filter for 64-bit numeric terms */
- public static final BytesRef INT64_TERM_PREFIX = new BytesRef(new byte[] { NumericUtils.SHIFT_START_LONG });
-
/**
* Checks the internal cache for an appropriate entry, and if none is found, reads the term values
* in <code>field</code> and returns a {@link DocTermOrds} instance, providing a method to retrieve
Modified: lucene/dev/branches/lucene6005/lucene/misc/src/java/org/apache/lucene/uninverting/FieldCacheImpl.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/misc/src/java/org/apache/lucene/uninverting/FieldCacheImpl.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/misc/src/java/org/apache/lucene/uninverting/FieldCacheImpl.java (original)
+++ lucene/dev/branches/lucene6005/lucene/misc/src/java/org/apache/lucene/uninverting/FieldCacheImpl.java Sun Dec 7 10:52:03 2014
@@ -883,7 +883,7 @@ class FieldCacheImpl implements FieldCac
// should share it...
public SortedSetDocValues getDocTermOrds(LeafReader reader, String field, BytesRef prefix) throws IOException {
// not a general purpose filtering mechanism...
- assert prefix == null || prefix == INT32_TERM_PREFIX || prefix == INT64_TERM_PREFIX;
+ assert prefix == null;
SortedSetDocValues dv = reader.getSortedSetDocValues(field);
if (dv != null) {
Modified: lucene/dev/branches/lucene6005/lucene/misc/src/java/org/apache/lucene/uninverting/UninvertingReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/misc/src/java/org/apache/lucene/uninverting/UninvertingReader.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/misc/src/java/org/apache/lucene/uninverting/UninvertingReader.java (original)
+++ lucene/dev/branches/lucene6005/lucene/misc/src/java/org/apache/lucene/uninverting/UninvertingReader.java Sun Dec 7 10:52:03 2014
@@ -216,28 +216,19 @@ public class UninvertingReader extends F
return fieldInfos;
}
- private boolean isFieldType(String field) {
- try {
- getFieldTypes().getIndexableFieldType(field);
- return true;
- } catch (IllegalArgumentException iae) {
- return false;
- }
- }
-
@Override
public NumericDocValues getNumericDocValues(String field) throws IOException {
Type v = getType(field);
if (v != null) {
switch (v) {
case INTEGER:
- return FieldCache.DEFAULT.getNumerics(in, field, isFieldType(field) ? FieldCache.DOCUMENT2_INT_PARSER : FieldCache.NUMERIC_UTILS_INT_PARSER, true);
+ return FieldCache.DEFAULT.getNumerics(in, field, FieldCache.DOCUMENT_INT_PARSER, true);
case FLOAT:
- return FieldCache.DEFAULT.getNumerics(in, field, isFieldType(field) ? FieldCache.DOCUMENT2_FLOAT_PARSER : FieldCache.NUMERIC_UTILS_FLOAT_PARSER, true);
+ return FieldCache.DEFAULT.getNumerics(in, field, FieldCache.DOCUMENT_FLOAT_PARSER, true);
case LONG:
- return FieldCache.DEFAULT.getNumerics(in, field, isFieldType(field) ? FieldCache.DOCUMENT2_LONG_PARSER : FieldCache.NUMERIC_UTILS_LONG_PARSER, true);
+ return FieldCache.DEFAULT.getNumerics(in, field, FieldCache.DOCUMENT_LONG_PARSER, true);
case DOUBLE:
- return FieldCache.DEFAULT.getNumerics(in, field, isFieldType(field) ? FieldCache.DOCUMENT2_DOUBLE_PARSER : FieldCache.NUMERIC_UTILS_DOUBLE_PARSER, true);
+ return FieldCache.DEFAULT.getNumerics(in, field, FieldCache.DOCUMENT_DOUBLE_PARSER, true);
}
}
return super.getNumericDocValues(field);
@@ -270,10 +261,10 @@ public class UninvertingReader extends F
switch (v) {
case SORTED_SET_INTEGER:
case SORTED_SET_FLOAT:
- return FieldCache.DEFAULT.getDocTermOrds(in, field, isFieldType(field) ? null : FieldCache.INT32_TERM_PREFIX);
+ return FieldCache.DEFAULT.getDocTermOrds(in, field, null);
case SORTED_SET_LONG:
case SORTED_SET_DOUBLE:
- return FieldCache.DEFAULT.getDocTermOrds(in, field, isFieldType(field) ? null : FieldCache.INT64_TERM_PREFIX);
+ return FieldCache.DEFAULT.getDocTermOrds(in, field, null);
case SORTED_SET_BINARY:
return FieldCache.DEFAULT.getDocTermOrds(in, field, null);
}
Modified: lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestDocTermOrds.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestDocTermOrds.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestDocTermOrds.java (original)
+++ lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestDocTermOrds.java Sun Dec 7 10:52:03 2014
@@ -48,6 +48,7 @@ import org.apache.lucene.index.TermsEnum
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.NumericUtils;
import org.apache.lucene.util.StringHelper;
import org.apache.lucene.util.TestUtil;
@@ -322,7 +323,7 @@ public class TestDocTermOrds extends Luc
TestUtil.nextInt(random(), 2, 10));
- final NumericDocValues docIDToID = FieldCache.DEFAULT.getNumerics(r, "id", FieldCache.DOCUMENT2_INT_PARSER, false);
+ final NumericDocValues docIDToID = FieldCache.DEFAULT.getNumerics(r, "id", FieldCache.DOCUMENT_INT_PARSER, false);
/*
for(int docID=0;docID<subR.maxDoc();docID++) {
System.out.println(" docID=" + docID + " id=" + docIDToID[docID]);
@@ -462,10 +463,10 @@ public class TestDocTermOrds extends Luc
assertEquals(SortedSetDocValues.NO_MORE_ORDS, v.nextOrd());
BytesRef value = v.lookupOrd(0);
- assertEquals(-3, Document.bytesToInt(value));
+ assertEquals(-3, NumericUtils.bytesToInt(value));
value = v.lookupOrd(1);
- assertEquals(5, Document.bytesToInt(value));
+ assertEquals(5, NumericUtils.bytesToInt(value));
ir.close();
dir.close();
@@ -506,10 +507,10 @@ public class TestDocTermOrds extends Luc
assertEquals(SortedSetDocValues.NO_MORE_ORDS, v.nextOrd());
BytesRef value = v.lookupOrd(0);
- assertEquals(-3, Document.bytesToLong(value));
+ assertEquals(-3, NumericUtils.bytesToLong(value));
value = v.lookupOrd(1);
- assertEquals(5, Document.bytesToLong(value));
+ assertEquals(5, NumericUtils.bytesToLong(value));
ir.close();
dir.close();
Modified: lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCache.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCache.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCache.java (original)
+++ lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCache.java Sun Dec 7 10:52:03 2014
@@ -48,6 +48,7 @@ import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.NumericUtils;
import org.apache.lucene.util.TestUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -139,7 +140,7 @@ public class TestFieldCache extends Luce
FieldCache cache = FieldCache.DEFAULT;
ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
cache.setInfoStream(new PrintStream(bos, false, IOUtils.UTF_8));
- cache.getNumerics(reader, "theDouble", FieldCache.DOCUMENT2_DOUBLE_PARSER, false);
+ cache.getNumerics(reader, "theDouble", FieldCache.DOCUMENT_DOUBLE_PARSER, false);
cache.getNumerics(reader, "theDouble", new FieldCache.Parser() {
@Override
public TermsEnum termsEnum(Terms terms) throws IOException {
@@ -147,7 +148,7 @@ public class TestFieldCache extends Luce
}
@Override
public long parseValue(BytesRef term) {
- return Document.sortableDoubleBits(Document.bytesToLong(term));
+ return NumericUtils.doubleToLong(NumericUtils.bytesToDouble(term));
}
}, false);
assertTrue(bos.toString(IOUtils.UTF_8).indexOf("WARNING") != -1);
@@ -159,26 +160,26 @@ public class TestFieldCache extends Luce
public void test() throws IOException {
FieldCache cache = FieldCache.DEFAULT;
- NumericDocValues doubles = cache.getNumerics(reader, "theDouble", FieldCache.DOCUMENT2_DOUBLE_PARSER, random().nextBoolean());
- assertSame("Second request to cache return same array", doubles, cache.getNumerics(reader, "theDouble", FieldCache.DOCUMENT2_DOUBLE_PARSER, random().nextBoolean()));
+ NumericDocValues doubles = cache.getNumerics(reader, "theDouble", FieldCache.DOCUMENT_DOUBLE_PARSER, random().nextBoolean());
+ assertSame("Second request to cache return same array", doubles, cache.getNumerics(reader, "theDouble", FieldCache.DOCUMENT_DOUBLE_PARSER, random().nextBoolean()));
for (int i = 0; i < NUM_DOCS; i++) {
- assertEquals(Double.doubleToLongBits(Double.MAX_VALUE - i), doubles.get(i));
+ assertEquals(NumericUtils.doubleToLong(Double.MAX_VALUE - i), doubles.get(i));
}
- NumericDocValues longs = cache.getNumerics(reader, "theLong", FieldCache.DOCUMENT2_LONG_PARSER, random().nextBoolean());
- assertSame("Second request to cache return same array", longs, cache.getNumerics(reader, "theLong", FieldCache.DOCUMENT2_LONG_PARSER, random().nextBoolean()));
+ NumericDocValues longs = cache.getNumerics(reader, "theLong", FieldCache.DOCUMENT_LONG_PARSER, random().nextBoolean());
+ assertSame("Second request to cache return same array", longs, cache.getNumerics(reader, "theLong", FieldCache.DOCUMENT_LONG_PARSER, random().nextBoolean()));
for (int i = 0; i < NUM_DOCS; i++) {
assertEquals(Long.MAX_VALUE - i, longs.get(i));
}
- NumericDocValues ints = cache.getNumerics(reader, "theInt", FieldCache.DOCUMENT2_INT_PARSER, random().nextBoolean());
- assertSame("Second request to cache return same array", ints, cache.getNumerics(reader, "theInt", FieldCache.DOCUMENT2_INT_PARSER, random().nextBoolean()));
+ NumericDocValues ints = cache.getNumerics(reader, "theInt", FieldCache.DOCUMENT_INT_PARSER, random().nextBoolean());
+ assertSame("Second request to cache return same array", ints, cache.getNumerics(reader, "theInt", FieldCache.DOCUMENT_INT_PARSER, random().nextBoolean()));
for (int i = 0; i < NUM_DOCS; i++) {
assertEquals(Integer.MAX_VALUE - i, ints.get(i));
}
- NumericDocValues floats = cache.getNumerics(reader, "theFloat", FieldCache.DOCUMENT2_FLOAT_PARSER, random().nextBoolean());
- assertSame("Second request to cache return same array", floats, cache.getNumerics(reader, "theFloat", FieldCache.DOCUMENT2_FLOAT_PARSER, random().nextBoolean()));
+ NumericDocValues floats = cache.getNumerics(reader, "theFloat", FieldCache.DOCUMENT_FLOAT_PARSER, random().nextBoolean());
+ assertSame("Second request to cache return same array", floats, cache.getNumerics(reader, "theFloat", FieldCache.DOCUMENT_FLOAT_PARSER, random().nextBoolean()));
for (int i = 0; i < NUM_DOCS; i++) {
assertEquals(Float.floatToIntBits(Float.MAX_VALUE - i), floats.get(i));
}
@@ -320,7 +321,7 @@ public class TestFieldCache extends Luce
FieldCache cache = FieldCache.DEFAULT;
cache.purgeAllCaches();
assertEquals(0, cache.getCacheEntries().length);
- cache.getNumerics(reader, "theDouble", FieldCache.DOCUMENT2_DOUBLE_PARSER, true);
+ cache.getNumerics(reader, "theDouble", FieldCache.DOCUMENT_DOUBLE_PARSER, true);
// The double[] takes one slots, and docsWithField should also
// have been populated:
@@ -331,7 +332,7 @@ public class TestFieldCache extends Luce
assertEquals(2, cache.getCacheEntries().length);
assertTrue(bits instanceof Bits.MatchAllBits);
- NumericDocValues ints = cache.getNumerics(reader, "sparse", FieldCache.DOCUMENT2_INT_PARSER, true);
+ NumericDocValues ints = cache.getNumerics(reader, "sparse", FieldCache.DOCUMENT_INT_PARSER, true);
assertEquals(4, cache.getCacheEntries().length);
Bits docsWithField = cache.getDocsWithField(reader, "sparse");
assertEquals(4, cache.getCacheEntries().length);
@@ -344,7 +345,7 @@ public class TestFieldCache extends Luce
}
}
- NumericDocValues numInts = cache.getNumerics(reader, "numInt", FieldCache.DOCUMENT2_INT_PARSER, random().nextBoolean());
+ NumericDocValues numInts = cache.getNumerics(reader, "numInt", FieldCache.DOCUMENT_INT_PARSER, random().nextBoolean());
docsWithField = cache.getDocsWithField(reader, "numInt");
for (int i = 0; i < docsWithField.length(); i++) {
if (i%2 == 0) {
@@ -394,7 +395,7 @@ public class TestFieldCache extends Luce
assertEquals(i%2 == 0, docsWithField.get(i));
}
} else {
- NumericDocValues ints = cache.getNumerics(reader, "sparse", FieldCache.DOCUMENT2_INT_PARSER, true);
+ NumericDocValues ints = cache.getNumerics(reader, "sparse", FieldCache.DOCUMENT_INT_PARSER, true);
Bits docsWithField = cache.getDocsWithField(reader, "sparse");
for (int i = 0; i < docsWithField.length(); i++) {
if (i%2 == 0) {
@@ -442,7 +443,7 @@ public class TestFieldCache extends Luce
// Binary type: can be retrieved via getTerms()
try {
- FieldCache.DEFAULT.getNumerics(ar, "binary", FieldCache.DOCUMENT2_INT_PARSER, false);
+ FieldCache.DEFAULT.getNumerics(ar, "binary", FieldCache.DOCUMENT_INT_PARSER, false);
fail();
} catch (IllegalStateException expected) {}
@@ -470,7 +471,7 @@ public class TestFieldCache extends Luce
// Sorted type: can be retrieved via getTerms(), getTermsIndex(), getDocTermOrds()
try {
- FieldCache.DEFAULT.getNumerics(ar, "sorted", FieldCache.DOCUMENT2_INT_PARSER, false);
+ FieldCache.DEFAULT.getNumerics(ar, "sorted", FieldCache.DOCUMENT_INT_PARSER, false);
fail();
} catch (IllegalStateException expected) {}
@@ -499,7 +500,7 @@ public class TestFieldCache extends Luce
assertTrue(bits.get(0));
// Numeric type: can be retrieved via getInts() and so on
- NumericDocValues numeric = FieldCache.DEFAULT.getNumerics(ar, "numeric", FieldCache.DOCUMENT2_INT_PARSER, false);
+ NumericDocValues numeric = FieldCache.DEFAULT.getNumerics(ar, "numeric", FieldCache.DOCUMENT_INT_PARSER, false);
assertEquals(-42, numeric.get(0));
try {
@@ -527,7 +528,7 @@ public class TestFieldCache extends Luce
// SortedSet type: can be retrieved via getDocTermOrds()
try {
- FieldCache.DEFAULT.getNumerics(ar, "sortedset", FieldCache.DOCUMENT2_INT_PARSER, false);
+ FieldCache.DEFAULT.getNumerics(ar, "sortedset", FieldCache.DOCUMENT_INT_PARSER, false);
fail();
} catch (IllegalStateException expected) {}
@@ -574,16 +575,16 @@ public class TestFieldCache extends Luce
cache.purgeAllCaches();
assertEquals(0, cache.getCacheEntries().length);
- NumericDocValues ints = cache.getNumerics(ar, "bogusints", FieldCache.DOCUMENT2_INT_PARSER, true);
+ NumericDocValues ints = cache.getNumerics(ar, "bogusints", FieldCache.DOCUMENT_INT_PARSER, true);
assertEquals(0, ints.get(0));
- NumericDocValues longs = cache.getNumerics(ar, "boguslongs", FieldCache.DOCUMENT2_LONG_PARSER, true);
+ NumericDocValues longs = cache.getNumerics(ar, "boguslongs", FieldCache.DOCUMENT_LONG_PARSER, true);
assertEquals(0, longs.get(0));
- NumericDocValues floats = cache.getNumerics(ar, "bogusfloats", FieldCache.DOCUMENT2_FLOAT_PARSER, true);
+ NumericDocValues floats = cache.getNumerics(ar, "bogusfloats", FieldCache.DOCUMENT_FLOAT_PARSER, true);
assertEquals(0, floats.get(0));
- NumericDocValues doubles = cache.getNumerics(ar, "bogusdoubles", FieldCache.DOCUMENT2_DOUBLE_PARSER, true);
+ NumericDocValues doubles = cache.getNumerics(ar, "bogusdoubles", FieldCache.DOCUMENT_DOUBLE_PARSER, true);
assertEquals(0, doubles.get(0));
BinaryDocValues binaries = cache.getTerms(ar, "bogusterms", true);
@@ -632,16 +633,16 @@ public class TestFieldCache extends Luce
cache.purgeAllCaches();
assertEquals(0, cache.getCacheEntries().length);
- NumericDocValues ints = cache.getNumerics(ar, "bogusints", FieldCache.DOCUMENT2_INT_PARSER, true);
+ NumericDocValues ints = cache.getNumerics(ar, "bogusints", FieldCache.DOCUMENT_INT_PARSER, true);
assertEquals(0, ints.get(0));
- NumericDocValues longs = cache.getNumerics(ar, "boguslongs", FieldCache.DOCUMENT2_LONG_PARSER, true);
+ NumericDocValues longs = cache.getNumerics(ar, "boguslongs", FieldCache.DOCUMENT_LONG_PARSER, true);
assertEquals(0, longs.get(0));
- NumericDocValues floats = cache.getNumerics(ar, "bogusfloats", FieldCache.DOCUMENT2_FLOAT_PARSER, true);
+ NumericDocValues floats = cache.getNumerics(ar, "bogusfloats", FieldCache.DOCUMENT_FLOAT_PARSER, true);
assertEquals(0, floats.get(0));
- NumericDocValues doubles = cache.getNumerics(ar, "bogusdoubles", FieldCache.DOCUMENT2_DOUBLE_PARSER, true);
+ NumericDocValues doubles = cache.getNumerics(ar, "bogusdoubles", FieldCache.DOCUMENT_DOUBLE_PARSER, true);
assertEquals(0, doubles.get(0));
BinaryDocValues binaries = cache.getTerms(ar, "bogusterms", true);
@@ -703,7 +704,7 @@ public class TestFieldCache extends Luce
}
iw.forceMerge(1);
final DirectoryReader reader = iw.getReader();
- final NumericDocValues longs = FieldCache.DEFAULT.getNumerics(getOnlySegmentReader(reader), "f", FieldCache.DOCUMENT2_LONG_PARSER, false);
+ final NumericDocValues longs = FieldCache.DEFAULT.getNumerics(getOnlySegmentReader(reader), "f", FieldCache.DOCUMENT_LONG_PARSER, false);
for (int i = 0; i < values.length; ++i) {
assertEquals(values[i], longs.get(i));
}
@@ -749,7 +750,7 @@ public class TestFieldCache extends Luce
}
iw.forceMerge(1);
final DirectoryReader reader = iw.getReader();
- final NumericDocValues ints = FieldCache.DEFAULT.getNumerics(getOnlySegmentReader(reader), "f", FieldCache.DOCUMENT2_INT_PARSER, false);
+ final NumericDocValues ints = FieldCache.DEFAULT.getNumerics(getOnlySegmentReader(reader), "f", FieldCache.DOCUMENT_INT_PARSER, false);
for (int i = 0; i < values.length; ++i) {
assertEquals(values[i], ints.get(i));
}
Modified: lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheReopen.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheReopen.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheReopen.java (original)
+++ lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheReopen.java Sun Dec 7 10:52:03 2014
@@ -52,7 +52,7 @@ public class TestFieldCacheReopen extend
// Open reader1
DirectoryReader r = DirectoryReader.open(dir);
LeafReader r1 = getOnlySegmentReader(r);
- final NumericDocValues ints = FieldCache.DEFAULT.getNumerics(r1, "number", FieldCache.DOCUMENT2_INT_PARSER, false);
+ final NumericDocValues ints = FieldCache.DEFAULT.getNumerics(r1, "number", FieldCache.DOCUMENT_INT_PARSER, false);
assertEquals(17, ints.get(0));
// Add new segment
@@ -64,7 +64,7 @@ public class TestFieldCacheReopen extend
assertNotNull(r2);
r.close();
LeafReader sub0 = r2.leaves().get(0).reader();
- final NumericDocValues ints2 = FieldCache.DEFAULT.getNumerics(sub0, "number", FieldCache.DOCUMENT2_INT_PARSER, false);
+ final NumericDocValues ints2 = FieldCache.DEFAULT.getNumerics(sub0, "number", FieldCache.DOCUMENT_INT_PARSER, false);
r2.close();
assertTrue(ints == ints2);
Modified: lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheSanityChecker.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheSanityChecker.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheSanityChecker.java (original)
+++ lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheSanityChecker.java Sun Dec 7 10:52:03 2014
@@ -106,11 +106,11 @@ public class TestFieldCacheSanityChecker
FieldCache cache = FieldCache.DEFAULT;
cache.purgeAllCaches();
- cache.getNumerics(readerA, "theDouble", FieldCache.DOCUMENT2_DOUBLE_PARSER, false);
- cache.getNumerics(readerAclone, "theDouble", FieldCache.DOCUMENT2_DOUBLE_PARSER, false);
- cache.getNumerics(readerB, "theDouble", FieldCache.DOCUMENT2_DOUBLE_PARSER, false);
+ cache.getNumerics(readerA, "theDouble", FieldCache.DOCUMENT_DOUBLE_PARSER, false);
+ cache.getNumerics(readerAclone, "theDouble", FieldCache.DOCUMENT_DOUBLE_PARSER, false);
+ cache.getNumerics(readerB, "theDouble", FieldCache.DOCUMENT_DOUBLE_PARSER, false);
- cache.getNumerics(readerX, "theInt", FieldCache.DOCUMENT2_INT_PARSER, false);
+ cache.getNumerics(readerX, "theInt", FieldCache.DOCUMENT_INT_PARSER, false);
// // //
@@ -129,7 +129,7 @@ public class TestFieldCacheSanityChecker
FieldCache cache = FieldCache.DEFAULT;
cache.purgeAllCaches();
- cache.getNumerics(readerX, "theInt", FieldCache.DOCUMENT2_INT_PARSER, false);
+ cache.getNumerics(readerX, "theInt", FieldCache.DOCUMENT_INT_PARSER, false);
cache.getTerms(readerX, "theInt", false);
// // //
Modified: lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheWithThreads.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheWithThreads.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheWithThreads.java (original)
+++ lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheWithThreads.java Sun Dec 7 10:52:03 2014
@@ -47,6 +47,7 @@ public class TestFieldCacheWithThreads e
Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy()));
FieldTypes fieldTypes = w.getFieldTypes();
+ // nocommit must also disable "number" and "sorted", but trunk is buggy here (indexes doc values)
fieldTypes.disableSorting("bytes");
final List<Long> numbers = new ArrayList<>();
final List<BytesRef> binary = new ArrayList<>();
@@ -82,9 +83,6 @@ public class TestFieldCacheWithThreads e
@Override
public void run() {
try {
- //NumericDocValues ndv = ar.getNumericDocValues("number");
- NumericDocValues ndv = FieldCache.DEFAULT.getNumerics(ar, "number", FieldCache.NUMERIC_UTILS_LONG_PARSER, false);
- //BinaryDocValues bdv = ar.getBinaryDocValues("bytes");
BinaryDocValues bdv = FieldCache.DEFAULT.getTerms(ar, "bytes", false);
SortedDocValues sdv = FieldCache.DEFAULT.getTermsIndex(ar, "sorted");
startingGun.await();
@@ -93,16 +91,16 @@ public class TestFieldCacheWithThreads e
int docID = threadRandom.nextInt(numDocs);
switch(threadRandom.nextInt(4)) {
case 0:
- assertEquals(numbers.get(docID).longValue(), FieldCache.DEFAULT.getNumerics(ar, "number", FieldCache.NUMERIC_UTILS_INT_PARSER, false).get(docID));
+ assertEquals(numbers.get(docID).longValue(), FieldCache.DEFAULT.getNumerics(ar, "number", FieldCache.DOCUMENT_INT_PARSER, false).get(docID));
break;
case 1:
- assertEquals(numbers.get(docID).longValue(), FieldCache.DEFAULT.getNumerics(ar, "number", FieldCache.NUMERIC_UTILS_LONG_PARSER, false).get(docID));
+ assertEquals(numbers.get(docID).longValue(), FieldCache.DEFAULT.getNumerics(ar, "number", FieldCache.DOCUMENT_LONG_PARSER, false).get(docID));
break;
case 2:
- assertEquals(numbers.get(docID).longValue(), FieldCache.DEFAULT.getNumerics(ar, "number", FieldCache.NUMERIC_UTILS_FLOAT_PARSER, false).get(docID));
+ assertEquals(numbers.get(docID).longValue(), FieldCache.DEFAULT.getNumerics(ar, "number", FieldCache.DOCUMENT_FLOAT_PARSER, false).get(docID));
break;
case 3:
- assertEquals(numbers.get(docID).longValue(), FieldCache.DEFAULT.getNumerics(ar, "number", FieldCache.NUMERIC_UTILS_DOUBLE_PARSER, false).get(docID));
+ assertEquals(numbers.get(docID).longValue(), FieldCache.DEFAULT.getNumerics(ar, "number", FieldCache.DOCUMENT_DOUBLE_PARSER, false).get(docID));
break;
}
BytesRef term = bdv.get(docID);
Modified: lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestNumericTerms32.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestNumericTerms32.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestNumericTerms32.java (original)
+++ lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestNumericTerms32.java Sun Dec 7 10:52:03 2014
@@ -103,7 +103,7 @@ public class TestNumericTerms32 extends
if (lower>upper) {
int a=lower; lower=upper; upper=a;
}
- Query tq = new ConstantScoreQuery(fieldTypes.newRangeFilter(field, lower, true, upper, true));
+ Query tq = new ConstantScoreQuery(fieldTypes.newIntRangeFilter(field, lower, true, upper, true));
TopDocs topDocs = searcher.search(tq, null, noDocs, new Sort(new SortField(field, SortField.Type.INT, true)));
if (topDocs.totalHits==0) continue;
ScoreDoc[] sd = topDocs.scoreDocs;
Modified: lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestNumericTerms64.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestNumericTerms64.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestNumericTerms64.java (original)
+++ lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestNumericTerms64.java Sun Dec 7 10:52:03 2014
@@ -99,7 +99,7 @@ public class TestNumericTerms64 extends
if (lower>upper) {
long a=lower; lower=upper; upper=a;
}
- Query tq = new ConstantScoreQuery(fieldTypes.newRangeFilter(field, lower, true, upper, true));
+ Query tq = new ConstantScoreQuery(fieldTypes.newLongRangeFilter(field, lower, true, upper, true));
TopDocs topDocs = searcher.search(tq, null, noDocs, new Sort(new SortField(field, SortField.Type.LONG, true)));
if (topDocs.totalHits==0) continue;
ScoreDoc[] sd = topDocs.scoreDocs;
Modified: lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestUninvertingReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestUninvertingReader.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestUninvertingReader.java (original)
+++ lucene/dev/branches/lucene6005/lucene/misc/src/test/org/apache/lucene/uninverting/TestUninvertingReader.java Sun Dec 7 10:52:03 2014
@@ -30,6 +30,7 @@ import org.apache.lucene.store.Directory
import org.apache.lucene.uninverting.UninvertingReader.Type;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.NumericUtils;
import org.apache.lucene.util.TestUtil;
public class TestUninvertingReader extends LuceneTestCase {
@@ -70,10 +71,10 @@ public class TestUninvertingReader exten
assertEquals(SortedSetDocValues.NO_MORE_ORDS, v.nextOrd());
BytesRef value = v.lookupOrd(0);
- assertEquals(-3, Document.bytesToInt(value));
+ assertEquals(-3, NumericUtils.bytesToInt(value));
value = v.lookupOrd(1);
- assertEquals(5, Document.bytesToInt(value));
+ assertEquals(5, NumericUtils.bytesToInt(value));
TestUtil.checkReader(ir);
ir.close();
dir.close();
@@ -115,10 +116,10 @@ public class TestUninvertingReader exten
assertEquals(SortedSetDocValues.NO_MORE_ORDS, v.nextOrd());
BytesRef value = v.lookupOrd(0);
- assertEquals(-3f, Document.bytesToFloat(value), 0.0f);
+ assertEquals(-3f, NumericUtils.bytesToFloat(value), 0.0f);
value = v.lookupOrd(1);
- assertEquals(5f, Document.bytesToFloat(value), 0.0f);
+ assertEquals(5f, NumericUtils.bytesToFloat(value), 0.0f);
TestUtil.checkReader(ir);
ir.close();
dir.close();
@@ -159,10 +160,10 @@ public class TestUninvertingReader exten
assertEquals(SortedSetDocValues.NO_MORE_ORDS, v.nextOrd());
BytesRef value = v.lookupOrd(0);
- assertEquals(-3, Document.bytesToLong(value));
+ assertEquals(-3, NumericUtils.bytesToLong(value));
value = v.lookupOrd(1);
- assertEquals(5, Document.bytesToLong(value));
+ assertEquals(5, NumericUtils.bytesToLong(value));
TestUtil.checkReader(ir);
ir.close();
dir.close();
@@ -203,10 +204,10 @@ public class TestUninvertingReader exten
assertEquals(SortedSetDocValues.NO_MORE_ORDS, v.nextOrd());
BytesRef value = v.lookupOrd(0);
- assertEquals(-3d, Document.bytesToDouble(value), 0.0);
+ assertEquals(-3d, NumericUtils.bytesToDouble(value), 0.0);
value = v.lookupOrd(1);
- assertEquals(5d, Document.bytesToDouble(value), 0.0);
+ assertEquals(5d, NumericUtils.bytesToDouble(value), 0.0);
TestUtil.checkReader(ir);
ir.close();
dir.close();
Modified: lucene/dev/branches/lucene6005/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleFieldSource.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleFieldSource.java (original)
+++ lucene/dev/branches/lucene6005/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleFieldSource.java Sun Dec 7 10:52:03 2014
@@ -20,13 +20,14 @@ package org.apache.lucene.queries.functi
import java.io.IOException;
import java.util.Map;
+import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.NumericDocValues;
import org.apache.lucene.queries.function.FunctionValues;
import org.apache.lucene.queries.function.docvalues.DoubleDocValues;
import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.NumericUtils;
import org.apache.lucene.util.mutable.MutableValue;
import org.apache.lucene.util.mutable.MutableValueDouble;
@@ -52,7 +53,7 @@ public class DoubleFieldSource extends F
return new DoubleDocValues(this) {
@Override
public double doubleVal(int doc) {
- return Double.longBitsToDouble(arr.get(doc));
+ return NumericUtils.longToDouble(arr.get(doc));
}
@Override
Modified: lucene/dev/branches/lucene6005/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/FloatFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/FloatFieldSource.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/FloatFieldSource.java (original)
+++ lucene/dev/branches/lucene6005/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/FloatFieldSource.java Sun Dec 7 10:52:03 2014
@@ -20,12 +20,13 @@ package org.apache.lucene.queries.functi
import java.io.IOException;
import java.util.Map;
-import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.DocValues;
+import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.NumericDocValues;
import org.apache.lucene.queries.function.FunctionValues;
import org.apache.lucene.queries.function.docvalues.FloatDocValues;
import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.NumericUtils;
import org.apache.lucene.util.mutable.MutableValue;
import org.apache.lucene.util.mutable.MutableValueFloat;
@@ -52,7 +53,7 @@ public class FloatFieldSource extends Fi
return new FloatDocValues(this) {
@Override
public float floatVal(int doc) {
- return Float.intBitsToFloat((int)arr.get(doc));
+ return NumericUtils.intToFloat((int)arr.get(doc));
}
@Override
Modified: lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/NumericRangeQueryNodeBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/NumericRangeQueryNodeBuilder.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/NumericRangeQueryNodeBuilder.java (original)
+++ lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/NumericRangeQueryNodeBuilder.java Sun Dec 7 10:52:03 2014
@@ -17,7 +17,7 @@ package org.apache.lucene.queryparser.fl
* limitations under the License.
*/
-import org.apache.lucene.document.NumericType;
+import org.apache.lucene.document.FieldTypes;
import org.apache.lucene.queryparser.flexible.core.QueryNodeException;
import org.apache.lucene.queryparser.flexible.core.messages.QueryParserMessages;
import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode;
@@ -26,7 +26,9 @@ import org.apache.lucene.queryparser.fle
import org.apache.lucene.queryparser.flexible.standard.config.NumericConfig;
import org.apache.lucene.queryparser.flexible.standard.nodes.NumericQueryNode;
import org.apache.lucene.queryparser.flexible.standard.nodes.NumericRangeQueryNode;
-import org.apache.lucene.search.NumericRangeQuery;
+import org.apache.lucene.search.ConstantScoreQuery;
+import org.apache.lucene.search.Filter;
+import org.apache.lucene.search.Query;
/**
* Builds {@link NumericRangeQuery}s out of {@link NumericRangeQueryNode}s.
@@ -44,7 +46,7 @@ public class NumericRangeQueryNodeBuilde
}
@Override
- public NumericRangeQuery<? extends Number> build(QueryNode queryNode)
+ public Query build(QueryNode queryNode)
throws QueryNodeException {
NumericRangeQueryNode numericRangeNode = (NumericRangeQueryNode) queryNode;
@@ -55,38 +57,46 @@ public class NumericRangeQueryNodeBuilde
Number upperNumber = upperNumericNode.getValue();
NumericConfig numericConfig = numericRangeNode.getNumericConfig();
- NumericType numberType = numericConfig.getType();
+ FieldTypes fieldTypes = numericConfig.getFieldTypes();
String field = StringUtils.toString(numericRangeNode.getField());
boolean minInclusive = numericRangeNode.isLowerInclusive();
boolean maxInclusive = numericRangeNode.isUpperInclusive();
- int precisionStep = numericConfig.getPrecisionStep();
-
- switch (numberType) {
-
- case LONG:
- return NumericRangeQuery.newLongRange(field, precisionStep,
- (Long) lowerNumber, (Long) upperNumber, minInclusive, maxInclusive);
-
- case INT:
- return NumericRangeQuery.newIntRange(field, precisionStep,
- (Integer) lowerNumber, (Integer) upperNumber, minInclusive,
- maxInclusive);
-
- case FLOAT:
- return NumericRangeQuery.newFloatRange(field, precisionStep,
- (Float) lowerNumber, (Float) upperNumber, minInclusive,
- maxInclusive);
-
- case DOUBLE:
- return NumericRangeQuery.newDoubleRange(field, precisionStep,
- (Double) lowerNumber, (Double) upperNumber, minInclusive,
- maxInclusive);
-
- default :
- throw new QueryNodeException(new MessageImpl(
- QueryParserMessages.UNSUPPORTED_NUMERIC_DATA_TYPE, numberType));
-
+
+ // TODO: we should here check that the incoming Number is correct type:
+ Filter filter;
+ switch (fieldTypes.getValueType(field)) {
+ case INT:
+ filter = fieldTypes.newIntRangeFilter(field,
+ lowerNumber == null ? null : Integer.valueOf(lowerNumber.intValue()),
+ minInclusive,
+ upperNumber == null ? null : Integer.valueOf(upperNumber.intValue()),
+ maxInclusive);
+ break;
+ case LONG:
+ filter = fieldTypes.newLongRangeFilter(field,
+ lowerNumber == null ? null : Long.valueOf(lowerNumber.longValue()),
+ minInclusive,
+ upperNumber == null ? null : Long.valueOf(upperNumber.longValue()),
+ maxInclusive);
+ break;
+ case FLOAT:
+ filter = fieldTypes.newFloatRangeFilter(field,
+ lowerNumber == null ? null : Float.valueOf(lowerNumber.floatValue()),
+ minInclusive,
+ upperNumber == null ? null : Float.valueOf(upperNumber.floatValue()),
+ maxInclusive);
+ break;
+ case DOUBLE:
+ filter = fieldTypes.newDoubleRangeFilter(field,
+ lowerNumber == null ? null : Double.valueOf(lowerNumber.doubleValue()),
+ minInclusive,
+ upperNumber == null ? null : Double.valueOf(upperNumber.doubleValue()),
+ maxInclusive);
+ break;
+ default:
+ throw new IllegalArgumentException("field \"" + field + "\": cannot create numeric query: unhandled valueType " + fieldTypes.getValueType(field));
}
+
+ return new ConstantScoreQuery(filter);
}
-
}
Modified: lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/config/NumericConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/config/NumericConfig.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/config/NumericConfig.java (original)
+++ lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/config/NumericConfig.java Sun Dec 7 10:52:03 2014
@@ -19,8 +19,7 @@ package org.apache.lucene.queryparser.fl
import java.text.NumberFormat;
-import org.apache.lucene.document.NumericType;
-import org.apache.lucene.search.NumericRangeQuery;
+import org.apache.lucene.document.FieldTypes;
/**
* This class holds the configuration used to parse numeric queries and create
@@ -31,56 +30,28 @@ import org.apache.lucene.search.NumericR
*/
public class NumericConfig {
- private int precisionStep;
-
private NumberFormat format;
- private NumericType type;
+ private final FieldTypes fieldTypes;
/**
* Constructs a {@link NumericConfig} object.
*
- * @param precisionStep
- * the precision used to index the numeric values
* @param format
* the {@link NumberFormat} used to parse a {@link String} to
* {@link Number}
* @param type
* the numeric type used to index the numeric values
*
- * @see NumericConfig#setPrecisionStep(int)
* @see NumericConfig#setNumberFormat(NumberFormat)
- * @see #setType(org.apache.lucene.document.FieldType.NumericType)
*/
- public NumericConfig(int precisionStep, NumberFormat format,
- NumericType type) {
- setPrecisionStep(precisionStep);
+ public NumericConfig(NumberFormat format, FieldTypes fieldTypes) {
setNumberFormat(format);
- setType(type);
-
- }
-
- /**
- * Returns the precision used to index the numeric values
- *
- * @return the precision used to index the numeric values
- *
- * @see NumericRangeQuery#getPrecisionStep()
- */
- public int getPrecisionStep() {
- return precisionStep;
+ this.fieldTypes = fieldTypes;
}
-
- /**
- * Sets the precision used to index the numeric values
- *
- * @param precisionStep
- * the precision used to index the numeric values
- *
- * @see NumericRangeQuery#getPrecisionStep()
- */
- public void setPrecisionStep(int precisionStep) {
- this.precisionStep = precisionStep;
+
+ public FieldTypes getFieldTypes() {
+ return fieldTypes;
}
/**
@@ -93,31 +64,7 @@ public class NumericConfig {
public NumberFormat getNumberFormat() {
return format;
}
-
- /**
- * Returns the numeric type used to index the numeric values
- *
- * @return the numeric type used to index the numeric values
- */
- public NumericType getType() {
- return type;
- }
-
- /**
- * Sets the numeric type used to index the numeric values
- *
- * @param type the numeric type used to index the numeric values
- */
- public void setType(NumericType type) {
-
- if (type == null) {
- throw new IllegalArgumentException("type cannot be null!");
- }
-
- this.type = type;
-
- }
-
+
/**
* Sets the {@link NumberFormat} used to parse a {@link String} to
* {@link Number}
@@ -144,9 +91,7 @@ public class NumericConfig {
if (obj instanceof NumericConfig) {
NumericConfig other = (NumericConfig) obj;
- if (this.precisionStep == other.precisionStep
- && this.type == other.type
- && (this.format == other.format || (this.format.equals(other.format)))) {
+ if (this.format == other.format || (this.format.equals(other.format))) {
return true;
}
Modified: lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/NumericRangeQueryNode.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/NumericRangeQueryNode.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/NumericRangeQueryNode.java (original)
+++ lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/NumericRangeQueryNode.java Sun Dec 7 10:52:03 2014
@@ -17,7 +17,6 @@ package org.apache.lucene.queryparser.fl
* the License.
*/
-import org.apache.lucene.document.NumericType;
import org.apache.lucene.queryparser.flexible.core.QueryNodeException;
import org.apache.lucene.queryparser.flexible.core.messages.QueryParserMessages;
import org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode;
@@ -53,25 +52,6 @@ public class NumericRangeQueryNode exten
setBounds(lower, upper, lowerInclusive, upperInclusive, numericConfig);
}
- private static NumericType getNumericDataType(Number number) throws QueryNodeException {
-
- if (number instanceof Long) {
- return NumericType.LONG;
- } else if (number instanceof Integer) {
- return NumericType.INT;
- } else if (number instanceof Double) {
- return NumericType.DOUBLE;
- } else if (number instanceof Float) {
- return NumericType.FLOAT;
- } else {
- throw new QueryNodeException(
- new MessageImpl(
- QueryParserMessages.NUMBER_CLASS_NOT_SUPPORTED_BY_NUMERIC_RANGE_QUERY,
- number.getClass()));
- }
-
- }
-
/**
* Sets the upper and lower bounds of this range query node and the
* {@link NumericConfig} associated with these bounds.
@@ -90,34 +70,6 @@ public class NumericRangeQueryNode exten
throw new IllegalArgumentException("numericConfig cannot be null!");
}
- NumericType lowerNumberType, upperNumberType;
-
- if (lower != null && lower.getValue() != null) {
- lowerNumberType = getNumericDataType(lower.getValue());
- } else {
- lowerNumberType = null;
- }
-
- if (upper != null && upper.getValue() != null) {
- upperNumberType = getNumericDataType(upper.getValue());
- } else {
- upperNumberType = null;
- }
-
- if (lowerNumberType != null
- && !lowerNumberType.equals(numericConfig.getType())) {
- throw new IllegalArgumentException(
- "lower value's type should be the same as numericConfig type: "
- + lowerNumberType + " != " + numericConfig.getType());
- }
-
- if (upperNumberType != null
- && !upperNumberType.equals(numericConfig.getType())) {
- throw new IllegalArgumentException(
- "upper value's type should be the same as numericConfig type: "
- + upperNumberType + " != " + numericConfig.getType());
- }
-
super.setBounds(lower, upper, lowerInclusive, upperInclusive);
this.numericConfig = numericConfig;
@@ -137,9 +89,7 @@ public class NumericRangeQueryNode exten
StringBuilder sb = new StringBuilder("<numericRange lowerInclusive='");
sb.append(isLowerInclusive()).append("' upperInclusive='").append(
- isUpperInclusive()).append(
- "' precisionStep='" + numericConfig.getPrecisionStep()).append(
- "' type='" + numericConfig.getType()).append("'>\n");
+ isUpperInclusive()).append("'>\n");
sb.append(getLowerBound()).append('\n');
sb.append(getUpperBound()).append('\n');
Modified: lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/NumericQueryNodeProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/NumericQueryNodeProcessor.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/NumericQueryNodeProcessor.java (original)
+++ lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/NumericQueryNodeProcessor.java Sun Dec 7 10:52:03 2014
@@ -100,20 +100,6 @@ public class NumericQueryNodeProcessor e
.getCanonicalName()), e);
}
- switch (numericConfig.getType()) {
- case LONG:
- number = number.longValue();
- break;
- case INT:
- number = number.intValue();
- break;
- case DOUBLE:
- number = number.doubleValue();
- break;
- case FLOAT:
- number = number.floatValue();
- }
-
} else {
throw new QueryNodeParseException(new MessageImpl(
QueryParserMessages.NUMERIC_CANNOT_BE_EMPTY, fieldNode.getFieldAsString()));
Modified: lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/NumericRangeQueryNodeProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/NumericRangeQueryNodeProcessor.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/NumericRangeQueryNodeProcessor.java (original)
+++ lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/NumericRangeQueryNodeProcessor.java Sun Dec 7 10:52:03 2014
@@ -114,24 +114,6 @@ public class NumericRangeQueryNodeProces
}
- switch (numericConfig.getType()) {
- case LONG:
- if (upperNumber != null) upperNumber = upperNumber.longValue();
- if (lowerNumber != null) lowerNumber = lowerNumber.longValue();
- break;
- case INT:
- if (upperNumber != null) upperNumber = upperNumber.intValue();
- if (lowerNumber != null) lowerNumber = lowerNumber.intValue();
- break;
- case DOUBLE:
- if (upperNumber != null) upperNumber = upperNumber.doubleValue();
- if (lowerNumber != null) lowerNumber = lowerNumber.doubleValue();
- break;
- case FLOAT:
- if (upperNumber != null) upperNumber = upperNumber.floatValue();
- if (lowerNumber != null) lowerNumber = lowerNumber.floatValue();
- }
-
NumericQueryNode lowerNode = new NumericQueryNode(
termRangeNode.getField(), lowerNumber, numberFormat);
NumericQueryNode upperNode = new NumericQueryNode(
Modified: lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/CoreParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/CoreParser.java?rev=1643659&r1=1643658&r2=1643659&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/CoreParser.java (original)
+++ lucene/dev/branches/lucene6005/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/CoreParser.java Sun Dec 7 10:52:03 2014
@@ -1,16 +1,17 @@
package org.apache.lucene.queryparser.xml;
+import java.io.InputStream;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.document.FieldTypes;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.queryparser.xml.builders.*;
import org.apache.lucene.search.Query;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import java.io.InputStream;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -37,6 +38,8 @@ public class CoreParser implements Query
protected QueryParser parser;
protected QueryBuilderFactory queryFactory;
protected FilterBuilderFactory filterFactory;
+ protected final FieldTypes fieldTypes;
+
//Controls the max size of the LRU cache used for QueryFilter objects parsed.
public static int maxNumCachedFilters = 20;
@@ -47,8 +50,8 @@ public class CoreParser implements Query
*
* @param parser A QueryParser which will be synchronized on during parse calls.
*/
- public CoreParser(Analyzer analyzer, QueryParser parser) {
- this(null, analyzer, parser);
+ public CoreParser(FieldTypes fieldTypes, Analyzer analyzer, QueryParser parser) {
+ this(fieldTypes, null, analyzer, parser);
}
/**
@@ -56,13 +59,14 @@ public class CoreParser implements Query
*
* @param defaultField The default field name used by QueryParsers constructed for UserQuery tags
*/
- public CoreParser(String defaultField, Analyzer analyzer) {
- this(defaultField, analyzer, null);
+ public CoreParser(FieldTypes fieldTypes, String defaultField, Analyzer analyzer) {
+ this(fieldTypes, defaultField, analyzer, null);
}
- protected CoreParser(String defaultField, Analyzer analyzer, QueryParser parser) {
+ protected CoreParser(FieldTypes fieldTypes, String defaultField, Analyzer analyzer, QueryParser parser) {
this.analyzer = analyzer;
this.parser = parser;
+ this.fieldTypes = fieldTypes;
filterFactory = new FilterBuilderFactory();
filterFactory.addBuilder("RangeFilter", new RangeFilterBuilder());
filterFactory.addBuilder("NumericRangeFilter", new NumericRangeFilterBuilder());
@@ -118,7 +122,7 @@ public class CoreParser implements Query
}
public Query parse(InputStream xmlStream) throws ParserException {
- return getQuery(parseXML(xmlStream).getDocumentElement());
+ return getQuery(fieldTypes, parseXML(xmlStream).getDocumentElement());
}
public void addQueryBuilder(String nodeName, QueryBuilder builder) {
@@ -150,7 +154,7 @@ public class CoreParser implements Query
@Override
- public Query getQuery(Element e) throws ParserException {
- return queryFactory.getQuery(e);
+ public Query getQuery(FieldTypes fieldTypes, Element e) throws ParserException {
+ return queryFactory.getQuery(fieldTypes, e);
}
}