You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2016/08/17 13:29:55 UTC
[4/7] lucene-solr:master: LUCENE-7413: move legacy numeric support to
backwards module
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/105c7eae/lucene/core/src/java/org/apache/lucene/document/LegacyFloatField.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/document/LegacyFloatField.java b/lucene/core/src/java/org/apache/lucene/document/LegacyFloatField.java
deleted file mode 100644
index e24bf30..0000000
--- a/lucene/core/src/java/org/apache/lucene/document/LegacyFloatField.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * 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.
- */
-package org.apache.lucene.document;
-
-
-import org.apache.lucene.index.IndexOptions;
-import org.apache.lucene.util.LegacyNumericUtils;
-
-/**
- * <p>
- * Field that indexes <code>float</code> values
- * for efficient range filtering and sorting. Here's an example usage:
- *
- * <pre class="prettyprint">
- * document.add(new LegacyFloatField(name, 6.0F, Field.Store.NO));
- * </pre>
- *
- * For optimal performance, re-use the <code>LegacyFloatField</code> and
- * {@link Document} instance for more than one document:
- *
- * <pre class="prettyprint">
- * LegacyFloatField field = new LegacyFloatField(name, 0.0F, Field.Store.NO);
- * Document document = new Document();
- * document.add(field);
- *
- * for(all documents) {
- * ...
- * field.setFloatValue(value)
- * writer.addDocument(document);
- * ...
- * }
- * </pre>
- *
- * See also {@link LegacyIntField}, {@link LegacyLongField}, {@link
- * LegacyDoubleField}.
- *
- * <p>To perform range querying or filtering against a
- * <code>LegacyFloatField</code>, use {@link org.apache.lucene.search.LegacyNumericRangeQuery}.
- * To sort according to a
- * <code>LegacyFloatField</code>, use the normal numeric sort types, eg
- * {@link org.apache.lucene.search.SortField.Type#FLOAT}. <code>LegacyFloatField</code>
- * values can also be loaded directly from {@link org.apache.lucene.index.LeafReader#getNumericDocValues}.</p>
- *
- * <p>You may add the same field name as an <code>LegacyFloatField</code> to
- * the same document more than once. Range querying and
- * filtering will be the logical OR of all values; so a range query
- * will hit all documents that have at least one value in
- * the range. However sort behavior is not defined. If you need to sort,
- * you should separately index a single-valued <code>LegacyFloatField</code>.</p>
- *
- * <p>A <code>LegacyFloatField</code> will consume somewhat more disk space
- * in the index than an ordinary single-valued field.
- * However, for a typical index that includes substantial
- * textual content per document, this increase will likely
- * be in the noise. </p>
- *
- * <p>Within Lucene, each numeric value is indexed as a
- * <em>trie</em> structure, where each term is logically
- * assigned to larger and larger pre-defined brackets (which
- * are simply lower-precision representations of the value).
- * The step size between each successive bracket is called the
- * <code>precisionStep</code>, measured in bits. Smaller
- * <code>precisionStep</code> values result in larger number
- * of brackets, which consumes more disk space in the index
- * but may result in faster range search performance. The
- * default value, 8, was selected for a reasonable tradeoff
- * of disk space consumption versus performance. You can
- * create a custom {@link FieldType} and invoke the {@link
- * FieldType#setNumericPrecisionStep} method if you'd
- * like to change the value. Note that you must also
- * specify a congruent value when creating {@link
- * org.apache.lucene.search.LegacyNumericRangeQuery}.
- * For low cardinality fields larger precision steps are good.
- * If the cardinality is < 100, it is fair
- * to use {@link Integer#MAX_VALUE}, which produces one
- * term per value.
- *
- * <p>For more information on the internals of numeric trie
- * indexing, including the <a
- * href="../search/LegacyNumericRangeQuery.html#precisionStepDesc"><code>precisionStep</code></a>
- * configuration, see {@link org.apache.lucene.search.LegacyNumericRangeQuery}. The format of
- * indexed values is described in {@link org.apache.lucene.util.LegacyNumericUtils}.
- *
- * <p>If you only need to sort by numeric value, and never
- * run range querying/filtering, you can index using a
- * <code>precisionStep</code> of {@link Integer#MAX_VALUE}.
- * This will minimize disk space consumed. </p>
- *
- * <p>More advanced users can instead use {@link
- * org.apache.lucene.analysis.LegacyNumericTokenStream} directly, when indexing numbers. This
- * class is a wrapper around this token stream type for
- * easier, more intuitive usage.</p>
- *
- * @deprecated Please use {@link FloatPoint} instead
- *
- * @since 2.9
- */
-
-@Deprecated
-public final class LegacyFloatField extends Field {
-
- /**
- * Type for a LegacyFloatField that is not stored:
- * normalization factors, frequencies, and positions are omitted.
- */
- public static final FieldType TYPE_NOT_STORED = new FieldType();
- static {
- TYPE_NOT_STORED.setTokenized(true);
- TYPE_NOT_STORED.setOmitNorms(true);
- TYPE_NOT_STORED.setIndexOptions(IndexOptions.DOCS);
- TYPE_NOT_STORED.setNumericType(FieldType.LegacyNumericType.FLOAT);
- TYPE_NOT_STORED.setNumericPrecisionStep(LegacyNumericUtils.PRECISION_STEP_DEFAULT_32);
- TYPE_NOT_STORED.freeze();
- }
-
- /**
- * Type for a stored LegacyFloatField:
- * normalization factors, frequencies, and positions are omitted.
- */
- public static final FieldType TYPE_STORED = new FieldType();
- static {
- TYPE_STORED.setTokenized(true);
- TYPE_STORED.setOmitNorms(true);
- TYPE_STORED.setIndexOptions(IndexOptions.DOCS);
- TYPE_STORED.setNumericType(FieldType.LegacyNumericType.FLOAT);
- TYPE_STORED.setNumericPrecisionStep(LegacyNumericUtils.PRECISION_STEP_DEFAULT_32);
- TYPE_STORED.setStored(true);
- TYPE_STORED.freeze();
- }
-
- /** Creates a stored or un-stored LegacyFloatField with the provided value
- * and default <code>precisionStep</code> {@link
- * org.apache.lucene.util.LegacyNumericUtils#PRECISION_STEP_DEFAULT_32} (8).
- * @param name field name
- * @param value 32-bit double value
- * @param stored Store.YES if the content should also be stored
- * @throws IllegalArgumentException if the field name is null.
- */
- public LegacyFloatField(String name, float value, Store stored) {
- super(name, stored == Store.YES ? TYPE_STORED : TYPE_NOT_STORED);
- fieldsData = Float.valueOf(value);
- }
-
- /** Expert: allows you to customize the {@link
- * FieldType}.
- * @param name field name
- * @param value 32-bit float value
- * @param type customized field type: must have {@link FieldType#numericType()}
- * of {@link org.apache.lucene.document.FieldType.LegacyNumericType#FLOAT}.
- * @throws IllegalArgumentException if the field name or type is null, or
- * if the field type does not have a FLOAT numericType()
- */
- public LegacyFloatField(String name, float value, FieldType type) {
- super(name, type);
- if (type.numericType() != FieldType.LegacyNumericType.FLOAT) {
- throw new IllegalArgumentException("type.numericType() must be FLOAT but got " + type.numericType());
- }
- fieldsData = Float.valueOf(value);
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/105c7eae/lucene/core/src/java/org/apache/lucene/document/LegacyIntField.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/document/LegacyIntField.java b/lucene/core/src/java/org/apache/lucene/document/LegacyIntField.java
deleted file mode 100644
index 6eb0376..0000000
--- a/lucene/core/src/java/org/apache/lucene/document/LegacyIntField.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * 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.
- */
-package org.apache.lucene.document;
-
-
-import org.apache.lucene.index.IndexOptions;
-import org.apache.lucene.util.LegacyNumericUtils;
-
-/**
- * <p>
- * Field that indexes <code>int</code> values
- * for efficient range filtering and sorting. Here's an example usage:
- *
- * <pre class="prettyprint">
- * document.add(new LegacyIntField(name, 6, Field.Store.NO));
- * </pre>
- *
- * For optimal performance, re-use the <code>LegacyIntField</code> and
- * {@link Document} instance for more than one document:
- *
- * <pre class="prettyprint">
- * LegacyIntField field = new LegacyIntField(name, 6, Field.Store.NO);
- * Document document = new Document();
- * document.add(field);
- *
- * for(all documents) {
- * ...
- * field.setIntValue(value)
- * writer.addDocument(document);
- * ...
- * }
- * </pre>
- *
- * See also {@link LegacyLongField}, {@link LegacyFloatField}, {@link
- * LegacyDoubleField}.
- *
- * <p>To perform range querying or filtering against a
- * <code>LegacyIntField</code>, use {@link org.apache.lucene.search.LegacyNumericRangeQuery}.
- * To sort according to a
- * <code>LegacyIntField</code>, use the normal numeric sort types, eg
- * {@link org.apache.lucene.search.SortField.Type#INT}. <code>LegacyIntField</code>
- * values can also be loaded directly from {@link org.apache.lucene.index.LeafReader#getNumericDocValues}.</p>
- *
- * <p>You may add the same field name as an <code>LegacyIntField</code> to
- * the same document more than once. Range querying and
- * filtering will be the logical OR of all values; so a range query
- * will hit all documents that have at least one value in
- * the range. However sort behavior is not defined. If you need to sort,
- * you should separately index a single-valued <code>LegacyIntField</code>.</p>
- *
- * <p>An <code>LegacyIntField</code> will consume somewhat more disk space
- * in the index than an ordinary single-valued field.
- * However, for a typical index that includes substantial
- * textual content per document, this increase will likely
- * be in the noise. </p>
- *
- * <p>Within Lucene, each numeric value is indexed as a
- * <em>trie</em> structure, where each term is logically
- * assigned to larger and larger pre-defined brackets (which
- * are simply lower-precision representations of the value).
- * The step size between each successive bracket is called the
- * <code>precisionStep</code>, measured in bits. Smaller
- * <code>precisionStep</code> values result in larger number
- * of brackets, which consumes more disk space in the index
- * but may result in faster range search performance. The
- * default value, 8, was selected for a reasonable tradeoff
- * of disk space consumption versus performance. You can
- * create a custom {@link FieldType} and invoke the {@link
- * FieldType#setNumericPrecisionStep} method if you'd
- * like to change the value. Note that you must also
- * specify a congruent value when creating {@link
- * org.apache.lucene.search.LegacyNumericRangeQuery}.
- * For low cardinality fields larger precision steps are good.
- * If the cardinality is < 100, it is fair
- * to use {@link Integer#MAX_VALUE}, which produces one
- * term per value.
- *
- * <p>For more information on the internals of numeric trie
- * indexing, including the <a
- * href="../search/LegacyNumericRangeQuery.html#precisionStepDesc"><code>precisionStep</code></a>
- * configuration, see {@link org.apache.lucene.search.LegacyNumericRangeQuery}. The format of
- * indexed values is described in {@link org.apache.lucene.util.LegacyNumericUtils}.
- *
- * <p>If you only need to sort by numeric value, and never
- * run range querying/filtering, you can index using a
- * <code>precisionStep</code> of {@link Integer#MAX_VALUE}.
- * This will minimize disk space consumed. </p>
- *
- * <p>More advanced users can instead use {@link
- * org.apache.lucene.analysis.LegacyNumericTokenStream} directly, when indexing numbers. This
- * class is a wrapper around this token stream type for
- * easier, more intuitive usage.</p>
- *
- * @deprecated Please use {@link IntPoint} instead
- *
- * @since 2.9
- */
-
-@Deprecated
-public final class LegacyIntField extends Field {
-
- /**
- * Type for an LegacyIntField that is not stored:
- * normalization factors, frequencies, and positions are omitted.
- */
- public static final FieldType TYPE_NOT_STORED = new FieldType();
- static {
- TYPE_NOT_STORED.setTokenized(true);
- TYPE_NOT_STORED.setOmitNorms(true);
- TYPE_NOT_STORED.setIndexOptions(IndexOptions.DOCS);
- TYPE_NOT_STORED.setNumericType(FieldType.LegacyNumericType.INT);
- TYPE_NOT_STORED.setNumericPrecisionStep(LegacyNumericUtils.PRECISION_STEP_DEFAULT_32);
- TYPE_NOT_STORED.freeze();
- }
-
- /**
- * Type for a stored LegacyIntField:
- * normalization factors, frequencies, and positions are omitted.
- */
- public static final FieldType TYPE_STORED = new FieldType();
- static {
- TYPE_STORED.setTokenized(true);
- TYPE_STORED.setOmitNorms(true);
- TYPE_STORED.setIndexOptions(IndexOptions.DOCS);
- TYPE_STORED.setNumericType(FieldType.LegacyNumericType.INT);
- TYPE_STORED.setNumericPrecisionStep(LegacyNumericUtils.PRECISION_STEP_DEFAULT_32);
- TYPE_STORED.setStored(true);
- TYPE_STORED.freeze();
- }
-
- /** Creates a stored or un-stored LegacyIntField with the provided value
- * and default <code>precisionStep</code> {@link
- * org.apache.lucene.util.LegacyNumericUtils#PRECISION_STEP_DEFAULT_32} (8).
- * @param name field name
- * @param value 32-bit integer value
- * @param stored Store.YES if the content should also be stored
- * @throws IllegalArgumentException if the field name is null.
- */
- public LegacyIntField(String name, int value, Store stored) {
- super(name, stored == Store.YES ? TYPE_STORED : TYPE_NOT_STORED);
- fieldsData = Integer.valueOf(value);
- }
-
- /** Expert: allows you to customize the {@link
- * FieldType}.
- * @param name field name
- * @param value 32-bit integer value
- * @param type customized field type: must have {@link FieldType#numericType()}
- * of {@link org.apache.lucene.document.FieldType.LegacyNumericType#INT}.
- * @throws IllegalArgumentException if the field name or type is null, or
- * if the field type does not have a INT numericType()
- */
- public LegacyIntField(String name, int value, FieldType type) {
- super(name, type);
- if (type.numericType() != FieldType.LegacyNumericType.INT) {
- throw new IllegalArgumentException("type.numericType() must be INT but got " + type.numericType());
- }
- fieldsData = Integer.valueOf(value);
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/105c7eae/lucene/core/src/java/org/apache/lucene/document/LegacyLongField.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/document/LegacyLongField.java b/lucene/core/src/java/org/apache/lucene/document/LegacyLongField.java
deleted file mode 100644
index fa1851f..0000000
--- a/lucene/core/src/java/org/apache/lucene/document/LegacyLongField.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * 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.
- */
-package org.apache.lucene.document;
-
-
-import org.apache.lucene.index.IndexOptions;
-
-
-/**
- * <p>
- * Field that indexes <code>long</code> values
- * for efficient range filtering and sorting. Here's an example usage:
- *
- * <pre class="prettyprint">
- * document.add(new LegacyLongField(name, 6L, Field.Store.NO));
- * </pre>
- *
- * For optimal performance, re-use the <code>LegacyLongField</code> and
- * {@link Document} instance for more than one document:
- *
- * <pre class="prettyprint">
- * LegacyLongField field = new LegacyLongField(name, 0L, Field.Store.NO);
- * Document document = new Document();
- * document.add(field);
- *
- * for(all documents) {
- * ...
- * field.setLongValue(value)
- * writer.addDocument(document);
- * ...
- * }
- * </pre>
- *
- * See also {@link LegacyIntField}, {@link LegacyFloatField}, {@link
- * LegacyDoubleField}.
- *
- * Any type that can be converted to long can also be
- * indexed. For example, date/time values represented by a
- * {@link java.util.Date} can be translated into a long
- * value using the {@link java.util.Date#getTime} method. If you
- * don't need millisecond precision, you can quantize the
- * value, either by dividing the result of
- * {@link java.util.Date#getTime} or using the separate getters
- * (for year, month, etc.) to construct an <code>int</code> or
- * <code>long</code> value.
- *
- * <p>To perform range querying or filtering against a
- * <code>LegacyLongField</code>, use {@link org.apache.lucene.search.LegacyNumericRangeQuery}.
- * To sort according to a
- * <code>LegacyLongField</code>, use the normal numeric sort types, eg
- * {@link org.apache.lucene.search.SortField.Type#LONG}. <code>LegacyLongField</code>
- * values can also be loaded directly from {@link org.apache.lucene.index.LeafReader#getNumericDocValues}.
- *
- * <p>You may add the same field name as an <code>LegacyLongField</code> to
- * the same document more than once. Range querying and
- * filtering will be the logical OR of all values; so a range query
- * will hit all documents that have at least one value in
- * the range. However sort behavior is not defined. If you need to sort,
- * you should separately index a single-valued <code>LegacyLongField</code>.
- *
- * <p>A <code>LegacyLongField</code> will consume somewhat more disk space
- * in the index than an ordinary single-valued field.
- * However, for a typical index that includes substantial
- * textual content per document, this increase will likely
- * be in the noise. </p>
- *
- * <p>Within Lucene, each numeric value is indexed as a
- * <em>trie</em> structure, where each term is logically
- * assigned to larger and larger pre-defined brackets (which
- * are simply lower-precision representations of the value).
- * The step size between each successive bracket is called the
- * <code>precisionStep</code>, measured in bits. Smaller
- * <code>precisionStep</code> values result in larger number
- * of brackets, which consumes more disk space in the index
- * but may result in faster range search performance. The
- * default value, 16, was selected for a reasonable tradeoff
- * of disk space consumption versus performance. You can
- * create a custom {@link FieldType} and invoke the {@link
- * FieldType#setNumericPrecisionStep} method if you'd
- * like to change the value. Note that you must also
- * specify a congruent value when creating {@link
- * org.apache.lucene.search.LegacyNumericRangeQuery}.
- * For low cardinality fields larger precision steps are good.
- * If the cardinality is < 100, it is fair
- * to use {@link Integer#MAX_VALUE}, which produces one
- * term per value.
- *
- * <p>For more information on the internals of numeric trie
- * indexing, including the <a
- * href="../search/LegacyNumericRangeQuery.html#precisionStepDesc"><code>precisionStep</code></a>
- * configuration, see {@link org.apache.lucene.search.LegacyNumericRangeQuery}. The format of
- * indexed values is described in {@link org.apache.lucene.util.LegacyNumericUtils}.
- *
- * <p>If you only need to sort by numeric value, and never
- * run range querying/filtering, you can index using a
- * <code>precisionStep</code> of {@link Integer#MAX_VALUE}.
- * This will minimize disk space consumed.
- *
- * <p>More advanced users can instead use {@link
- * org.apache.lucene.analysis.LegacyNumericTokenStream} directly, when indexing numbers. This
- * class is a wrapper around this token stream type for
- * easier, more intuitive usage.</p>
- *
- * @deprecated Please use {@link LongPoint} instead
- *
- * @since 2.9
- */
-
-@Deprecated
-public final class LegacyLongField extends Field {
-
- /**
- * Type for a LegacyLongField that is not stored:
- * normalization factors, frequencies, and positions are omitted.
- */
- public static final FieldType TYPE_NOT_STORED = new FieldType();
- static {
- TYPE_NOT_STORED.setTokenized(true);
- TYPE_NOT_STORED.setOmitNorms(true);
- TYPE_NOT_STORED.setIndexOptions(IndexOptions.DOCS);
- TYPE_NOT_STORED.setNumericType(FieldType.LegacyNumericType.LONG);
- TYPE_NOT_STORED.freeze();
- }
-
- /**
- * Type for a stored LegacyLongField:
- * normalization factors, frequencies, and positions are omitted.
- */
- public static final FieldType TYPE_STORED = new FieldType();
- static {
- TYPE_STORED.setTokenized(true);
- TYPE_STORED.setOmitNorms(true);
- TYPE_STORED.setIndexOptions(IndexOptions.DOCS);
- TYPE_STORED.setNumericType(FieldType.LegacyNumericType.LONG);
- TYPE_STORED.setStored(true);
- TYPE_STORED.freeze();
- }
-
- /** Creates a stored or un-stored LegacyLongField with the provided value
- * and default <code>precisionStep</code> {@link
- * org.apache.lucene.util.LegacyNumericUtils#PRECISION_STEP_DEFAULT} (16).
- * @param name field name
- * @param value 64-bit long value
- * @param stored Store.YES if the content should also be stored
- * @throws IllegalArgumentException if the field name is null.
- */
- public LegacyLongField(String name, long value, Store stored) {
- super(name, stored == Store.YES ? TYPE_STORED : TYPE_NOT_STORED);
- fieldsData = Long.valueOf(value);
- }
-
- /** Expert: allows you to customize the {@link
- * FieldType}.
- * @param name field name
- * @param value 64-bit long value
- * @param type customized field type: must have {@link FieldType#numericType()}
- * of {@link org.apache.lucene.document.FieldType.LegacyNumericType#LONG}.
- * @throws IllegalArgumentException if the field name or type is null, or
- * if the field type does not have a LONG numericType()
- */
- public LegacyLongField(String name, long value, FieldType type) {
- super(name, type);
- if (type.numericType() != FieldType.LegacyNumericType.LONG) {
- throw new IllegalArgumentException("type.numericType() must be LONG but got " + type.numericType());
- }
- fieldsData = Long.valueOf(value);
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/105c7eae/lucene/core/src/java/org/apache/lucene/search/LegacyNumericRangeQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/LegacyNumericRangeQuery.java b/lucene/core/src/java/org/apache/lucene/search/LegacyNumericRangeQuery.java
deleted file mode 100644
index fe6c9e2..0000000
--- a/lucene/core/src/java/org/apache/lucene/search/LegacyNumericRangeQuery.java
+++ /dev/null
@@ -1,536 +0,0 @@
-/*
- * 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.
- */
-package org.apache.lucene.search;
-
-
-import java.io.IOException;
-import java.util.LinkedList;
-import java.util.Objects;
-
-import org.apache.lucene.document.DoublePoint;
-import org.apache.lucene.document.FieldType;
-import org.apache.lucene.document.FieldType.LegacyNumericType;
-import org.apache.lucene.document.FloatPoint;
-import org.apache.lucene.document.IntPoint;
-import org.apache.lucene.document.LongPoint;
-import org.apache.lucene.index.FilteredTermsEnum;
-import org.apache.lucene.index.PointValues;
-import org.apache.lucene.index.Terms;
-import org.apache.lucene.index.TermsEnum;
-import org.apache.lucene.util.AttributeSource;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.LegacyNumericUtils;
-import org.apache.lucene.util.NumericUtils;
-import org.apache.lucene.index.Term; // for javadocs
-
-/**
- * <p>A {@link Query} that matches numeric values within a
- * specified range. To use this, you must first index the
- * numeric values using {@link org.apache.lucene.document.LegacyIntField}, {@link
- * org.apache.lucene.document.LegacyFloatField}, {@link org.apache.lucene.document.LegacyLongField} or {@link org.apache.lucene.document.LegacyDoubleField} (expert: {@link
- * org.apache.lucene.analysis.LegacyNumericTokenStream}). If your terms are instead textual,
- * you should use {@link TermRangeQuery}.</p>
- *
- * <p>You create a new LegacyNumericRangeQuery with the static
- * factory methods, eg:
- *
- * <pre class="prettyprint">
- * Query q = LegacyNumericRangeQuery.newFloatRange("weight", 0.03f, 0.10f, true, true);
- * </pre>
- *
- * matches all documents whose float valued "weight" field
- * ranges from 0.03 to 0.10, inclusive.
- *
- * <p>The performance of LegacyNumericRangeQuery is much better
- * than the corresponding {@link TermRangeQuery} because the
- * number of terms that must be searched is usually far
- * fewer, thanks to trie indexing, described below.</p>
- *
- * <p>You can optionally specify a <a
- * href="#precisionStepDesc"><code>precisionStep</code></a>
- * when creating this query. This is necessary if you've
- * changed this configuration from its default (4) during
- * indexing. Lower values consume more disk space but speed
- * up searching. Suitable values are between <b>1</b> and
- * <b>8</b>. A good starting point to test is <b>4</b>,
- * which is the default value for all <code>Numeric*</code>
- * classes. See <a href="#precisionStepDesc">below</a> for
- * details.
- *
- * <p>This query defaults to {@linkplain
- * MultiTermQuery#CONSTANT_SCORE_REWRITE}.
- * With precision steps of ≤4, this query can be run with
- * one of the BooleanQuery rewrite methods without changing
- * BooleanQuery's default max clause count.
- *
- * <br><h3>How it works</h3>
- *
- * <p>See the publication about <a target="_blank" href="http://www.panfmp.org">panFMP</a>,
- * where this algorithm was described (referred to as <code>TrieRangeQuery</code>):
- *
- * <blockquote><strong>Schindler, U, Diepenbroek, M</strong>, 2008.
- * <em>Generic XML-based Framework for Metadata Portals.</em>
- * Computers & Geosciences 34 (12), 1947-1955.
- * <a href="http://dx.doi.org/10.1016/j.cageo.2008.02.023"
- * target="_blank">doi:10.1016/j.cageo.2008.02.023</a></blockquote>
- *
- * <p><em>A quote from this paper:</em> Because Apache Lucene is a full-text
- * search engine and not a conventional database, it cannot handle numerical ranges
- * (e.g., field value is inside user defined bounds, even dates are numerical values).
- * We have developed an extension to Apache Lucene that stores
- * the numerical values in a special string-encoded format with variable precision
- * (all numerical values like doubles, longs, floats, and ints are converted to
- * lexicographic sortable string representations and stored with different precisions
- * (for a more detailed description of how the values are stored,
- * see {@link org.apache.lucene.util.LegacyNumericUtils}). A range is then divided recursively into multiple intervals for searching:
- * The center of the range is searched only with the lowest possible precision in the <em>trie</em>,
- * while the boundaries are matched more exactly. This reduces the number of terms dramatically.</p>
- *
- * <p>For the variant that stores long values in 8 different precisions (each reduced by 8 bits) that
- * uses a lowest precision of 1 byte, the index contains only a maximum of 256 distinct values in the
- * lowest precision. Overall, a range could consist of a theoretical maximum of
- * <code>7*255*2 + 255 = 3825</code> distinct terms (when there is a term for every distinct value of an
- * 8-byte-number in the index and the range covers almost all of them; a maximum of 255 distinct values is used
- * because it would always be possible to reduce the full 256 values to one term with degraded precision).
- * In practice, we have seen up to 300 terms in most cases (index with 500,000 metadata records
- * and a uniform value distribution).</p>
- *
- * <h3><a name="precisionStepDesc">Precision Step</a></h3>
- * <p>You can choose any <code>precisionStep</code> when encoding values.
- * Lower step values mean more precisions and so more terms in index (and index gets larger). The number
- * of indexed terms per value is (those are generated by {@link org.apache.lucene.analysis.LegacyNumericTokenStream}):
- * <p style="font-family:serif">
- * indexedTermsPerValue = <b>ceil</b><big>(</big>bitsPerValue / precisionStep<big>)</big>
- * </p>
- * As the lower precision terms are shared by many values, the additional terms only
- * slightly grow the term dictionary (approx. 7% for <code>precisionStep=4</code>), but have a larger
- * impact on the postings (the postings file will have more entries, as every document is linked to
- * <code>indexedTermsPerValue</code> terms instead of one). The formula to estimate the growth
- * of the term dictionary in comparison to one term per value:
- * <p>
- * <!-- the formula in the alt attribute was transformed from latex to PNG with http://1.618034.com/latex.php (with 110 dpi): -->
- * <img src="doc-files/nrq-formula-1.png" alt="\mathrm{termDictOverhead} = \sum\limits_{i=0}^{\mathrm{indexedTermsPerValue}-1} \frac{1}{2^{\mathrm{precisionStep}\cdot i}}">
- * </p>
- * <p>On the other hand, if the <code>precisionStep</code> is smaller, the maximum number of terms to match reduces,
- * which optimizes query speed. The formula to calculate the maximum number of terms that will be visited while
- * executing the query is:
- * <p>
- * <!-- the formula in the alt attribute was transformed from latex to PNG with http://1.618034.com/latex.php (with 110 dpi): -->
- * <img src="doc-files/nrq-formula-2.png" alt="\mathrm{maxQueryTerms} = \left[ \left( \mathrm{indexedTermsPerValue} - 1 \right) \cdot \left(2^\mathrm{precisionStep} - 1 \right) \cdot 2 \right] + \left( 2^\mathrm{precisionStep} - 1 \right)">
- * </p>
- * <p>For longs stored using a precision step of 4, <code>maxQueryTerms = 15*15*2 + 15 = 465</code>, and for a precision
- * step of 2, <code>maxQueryTerms = 31*3*2 + 3 = 189</code>. But the faster search speed is reduced by more seeking
- * in the term enum of the index. Because of this, the ideal <code>precisionStep</code> value can only
- * be found out by testing. <b>Important:</b> You can index with a lower precision step value and test search speed
- * using a multiple of the original step value.</p>
- *
- * <p>Good values for <code>precisionStep</code> are depending on usage and data type:
- * <ul>
- * <li>The default for all data types is <b>4</b>, which is used, when no <code>precisionStep</code> is given.
- * <li>Ideal value in most cases for <em>64 bit</em> data types <em>(long, double)</em> is <b>6</b> or <b>8</b>.
- * <li>Ideal value in most cases for <em>32 bit</em> data types <em>(int, float)</em> is <b>4</b>.
- * <li>For low cardinality fields larger precision steps are good. If the cardinality is < 100, it is
- * fair to use {@link Integer#MAX_VALUE} (see below).
- * <li>Steps <b>≥64</b> for <em>long/double</em> and <b>≥32</b> for <em>int/float</em> produces one token
- * per value in the index and querying is as slow as a conventional {@link TermRangeQuery}. But it can be used
- * to produce fields, that are solely used for sorting (in this case simply use {@link Integer#MAX_VALUE} as
- * <code>precisionStep</code>). Using {@link org.apache.lucene.document.LegacyIntField},
- * {@link org.apache.lucene.document.LegacyLongField}, {@link org.apache.lucene.document.LegacyFloatField} or {@link org.apache.lucene.document.LegacyDoubleField} for sorting
- * is ideal, because building the field cache is much faster than with text-only numbers.
- * These fields have one term per value and therefore also work with term enumeration for building distinct lists
- * (e.g. facets / preselected values to search for).
- * Sorting is also possible with range query optimized fields using one of the above <code>precisionSteps</code>.
- * </ul>
- *
- * <p>Comparisons of the different types of RangeQueries on an index with about 500,000 docs showed
- * that {@link TermRangeQuery} in boolean rewrite mode (with raised {@link BooleanQuery} clause count)
- * took about 30-40 secs to complete, {@link TermRangeQuery} in constant score filter rewrite mode took 5 secs
- * and executing this class took <100ms to complete (on an Opteron64 machine, Java 1.5, 8 bit
- * precision step). This query type was developed for a geographic portal, where the performance for
- * e.g. bounding boxes or exact date/time stamps is important.</p>
- *
- * @deprecated Instead index with {@link IntPoint}, {@link LongPoint}, {@link FloatPoint}, {@link DoublePoint}, and
- * create range queries with {@link IntPoint#newRangeQuery(String, int, int) IntPoint.newRangeQuery()},
- * {@link LongPoint#newRangeQuery(String, long, long) LongPoint.newRangeQuery()},
- * {@link FloatPoint#newRangeQuery(String, float, float) FloatPoint.newRangeQuery()},
- * {@link DoublePoint#newRangeQuery(String, double, double) DoublePoint.newRangeQuery()} respectively.
- * See {@link PointValues} for background information on Points.
- *
- * @since 2.9
- **/
-
-@Deprecated
-public final class LegacyNumericRangeQuery<T extends Number> extends MultiTermQuery {
-
- private LegacyNumericRangeQuery(final String field, final int precisionStep, final LegacyNumericType dataType,
- T min, T max, final boolean minInclusive, final boolean maxInclusive) {
- super(field);
- if (precisionStep < 1)
- throw new IllegalArgumentException("precisionStep must be >=1");
- this.precisionStep = precisionStep;
- this.dataType = Objects.requireNonNull(dataType, "LegacyNumericType must not be null");
- this.min = min;
- this.max = max;
- this.minInclusive = minInclusive;
- this.maxInclusive = maxInclusive;
- }
-
- /**
- * Factory that creates a <code>LegacyNumericRangeQuery</code>, that queries a <code>long</code>
- * range using the given <a href="#precisionStepDesc"><code>precisionStep</code></a>.
- * You can have half-open ranges (which are in fact </≤ or >/≥ queries)
- * by setting the min or max value to <code>null</code>. By setting inclusive to false, it will
- * match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.
- */
- public static LegacyNumericRangeQuery<Long> newLongRange(final String field, final int precisionStep,
- Long min, Long max, final boolean minInclusive, final boolean maxInclusive
- ) {
- return new LegacyNumericRangeQuery<>(field, precisionStep, FieldType.LegacyNumericType.LONG, min, max, minInclusive, maxInclusive);
- }
-
- /**
- * Factory that creates a <code>LegacyNumericRangeQuery</code>, that queries a <code>long</code>
- * range using the default <code>precisionStep</code> {@link org.apache.lucene.util.LegacyNumericUtils#PRECISION_STEP_DEFAULT} (16).
- * You can have half-open ranges (which are in fact </≤ or >/≥ queries)
- * by setting the min or max value to <code>null</code>. By setting inclusive to false, it will
- * match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.
- */
- public static LegacyNumericRangeQuery<Long> newLongRange(final String field,
- Long min, Long max, final boolean minInclusive, final boolean maxInclusive
- ) {
- return new LegacyNumericRangeQuery<>(field, LegacyNumericUtils.PRECISION_STEP_DEFAULT, FieldType.LegacyNumericType.LONG, min, max, minInclusive, maxInclusive);
- }
-
- /**
- * Factory that creates a <code>LegacyNumericRangeQuery</code>, that queries a <code>int</code>
- * range using the given <a href="#precisionStepDesc"><code>precisionStep</code></a>.
- * You can have half-open ranges (which are in fact </≤ or >/≥ queries)
- * by setting the min or max value to <code>null</code>. By setting inclusive to false, it will
- * match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.
- */
- public static LegacyNumericRangeQuery<Integer> newIntRange(final String field, final int precisionStep,
- Integer min, Integer max, final boolean minInclusive, final boolean maxInclusive
- ) {
- return new LegacyNumericRangeQuery<>(field, precisionStep, FieldType.LegacyNumericType.INT, min, max, minInclusive, maxInclusive);
- }
-
- /**
- * Factory that creates a <code>LegacyNumericRangeQuery</code>, that queries a <code>int</code>
- * range using the default <code>precisionStep</code> {@link org.apache.lucene.util.LegacyNumericUtils#PRECISION_STEP_DEFAULT_32} (8).
- * You can have half-open ranges (which are in fact </≤ or >/≥ queries)
- * by setting the min or max value to <code>null</code>. By setting inclusive to false, it will
- * match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.
- */
- public static LegacyNumericRangeQuery<Integer> newIntRange(final String field,
- Integer min, Integer max, final boolean minInclusive, final boolean maxInclusive
- ) {
- return new LegacyNumericRangeQuery<>(field, LegacyNumericUtils.PRECISION_STEP_DEFAULT_32, FieldType.LegacyNumericType.INT, min, max, minInclusive, maxInclusive);
- }
-
- /**
- * Factory that creates a <code>LegacyNumericRangeQuery</code>, that queries a <code>double</code>
- * range using the given <a href="#precisionStepDesc"><code>precisionStep</code></a>.
- * You can have half-open ranges (which are in fact </≤ or >/≥ queries)
- * by setting the min or max value to <code>null</code>.
- * {@link Double#NaN} will never match a half-open range, to hit {@code NaN} use a query
- * with {@code min == max == Double.NaN}. By setting inclusive to false, it will
- * match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.
- */
- public static LegacyNumericRangeQuery<Double> newDoubleRange(final String field, final int precisionStep,
- Double min, Double max, final boolean minInclusive, final boolean maxInclusive
- ) {
- return new LegacyNumericRangeQuery<>(field, precisionStep, FieldType.LegacyNumericType.DOUBLE, min, max, minInclusive, maxInclusive);
- }
-
- /**
- * Factory that creates a <code>LegacyNumericRangeQuery</code>, that queries a <code>double</code>
- * range using the default <code>precisionStep</code> {@link org.apache.lucene.util.LegacyNumericUtils#PRECISION_STEP_DEFAULT} (16).
- * You can have half-open ranges (which are in fact </≤ or >/≥ queries)
- * by setting the min or max value to <code>null</code>.
- * {@link Double#NaN} will never match a half-open range, to hit {@code NaN} use a query
- * with {@code min == max == Double.NaN}. By setting inclusive to false, it will
- * match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.
- */
- public static LegacyNumericRangeQuery<Double> newDoubleRange(final String field,
- Double min, Double max, final boolean minInclusive, final boolean maxInclusive
- ) {
- return new LegacyNumericRangeQuery<>(field, LegacyNumericUtils.PRECISION_STEP_DEFAULT, FieldType.LegacyNumericType.DOUBLE, min, max, minInclusive, maxInclusive);
- }
-
- /**
- * Factory that creates a <code>LegacyNumericRangeQuery</code>, that queries a <code>float</code>
- * range using the given <a href="#precisionStepDesc"><code>precisionStep</code></a>.
- * You can have half-open ranges (which are in fact </≤ or >/≥ queries)
- * by setting the min or max value to <code>null</code>.
- * {@link Float#NaN} will never match a half-open range, to hit {@code NaN} use a query
- * with {@code min == max == Float.NaN}. By setting inclusive to false, it will
- * match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.
- */
- public static LegacyNumericRangeQuery<Float> newFloatRange(final String field, final int precisionStep,
- Float min, Float max, final boolean minInclusive, final boolean maxInclusive
- ) {
- return new LegacyNumericRangeQuery<>(field, precisionStep, FieldType.LegacyNumericType.FLOAT, min, max, minInclusive, maxInclusive);
- }
-
- /**
- * Factory that creates a <code>LegacyNumericRangeQuery</code>, that queries a <code>float</code>
- * range using the default <code>precisionStep</code> {@link org.apache.lucene.util.LegacyNumericUtils#PRECISION_STEP_DEFAULT_32} (8).
- * You can have half-open ranges (which are in fact </≤ or >/≥ queries)
- * by setting the min or max value to <code>null</code>.
- * {@link Float#NaN} will never match a half-open range, to hit {@code NaN} use a query
- * with {@code min == max == Float.NaN}. By setting inclusive to false, it will
- * match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.
- */
- public static LegacyNumericRangeQuery<Float> newFloatRange(final String field,
- Float min, Float max, final boolean minInclusive, final boolean maxInclusive
- ) {
- return new LegacyNumericRangeQuery<>(field, LegacyNumericUtils.PRECISION_STEP_DEFAULT_32, FieldType.LegacyNumericType.FLOAT, min, max, minInclusive, maxInclusive);
- }
-
- @Override @SuppressWarnings("unchecked")
- protected TermsEnum getTermsEnum(final Terms terms, AttributeSource atts) throws IOException {
- // very strange: java.lang.Number itself is not Comparable, but all subclasses used here are
- if (min != null && max != null && ((Comparable<T>) min).compareTo(max) > 0) {
- return TermsEnum.EMPTY;
- }
- return new NumericRangeTermsEnum(terms.iterator());
- }
-
- /** Returns <code>true</code> if the lower endpoint is inclusive */
- public boolean includesMin() { return minInclusive; }
-
- /** Returns <code>true</code> if the upper endpoint is inclusive */
- public boolean includesMax() { return maxInclusive; }
-
- /** Returns the lower value of this range query */
- public T getMin() { return min; }
-
- /** Returns the upper value of this range query */
- public T getMax() { return max; }
-
- /** Returns the precision step. */
- public int getPrecisionStep() { return precisionStep; }
-
- @Override
- public String toString(final String field) {
- final StringBuilder sb = new StringBuilder();
- if (!getField().equals(field)) sb.append(getField()).append(':');
- return sb.append(minInclusive ? '[' : '{')
- .append((min == null) ? "*" : min.toString())
- .append(" TO ")
- .append((max == null) ? "*" : max.toString())
- .append(maxInclusive ? ']' : '}')
- .toString();
- }
-
- @Override
- @SuppressWarnings({"unchecked","rawtypes"})
- public final boolean equals(final Object o) {
- if (o==this) return true;
- if (!super.equals(o))
- return false;
- if (o instanceof LegacyNumericRangeQuery) {
- final LegacyNumericRangeQuery q=(LegacyNumericRangeQuery)o;
- return (
- (q.min == null ? min == null : q.min.equals(min)) &&
- (q.max == null ? max == null : q.max.equals(max)) &&
- minInclusive == q.minInclusive &&
- maxInclusive == q.maxInclusive &&
- precisionStep == q.precisionStep
- );
- }
- return false;
- }
-
- @Override
- public final int hashCode() {
- int hash = super.hashCode();
- hash = 31 * hash + precisionStep;
- hash = 31 * hash + Objects.hashCode(min);
- hash = 31 * hash + Objects.hashCode(max);
- hash = 31 * hash + Objects.hashCode(minInclusive);
- hash = 31 * hash + Objects.hashCode(maxInclusive);
- return hash;
- }
-
- // members (package private, to be also fast accessible by NumericRangeTermEnum)
- final int precisionStep;
- final FieldType.LegacyNumericType dataType;
- final T min, max;
- final boolean minInclusive,maxInclusive;
-
- // used to handle float/double infinity correcty
- static final long LONG_NEGATIVE_INFINITY =
- NumericUtils.doubleToSortableLong(Double.NEGATIVE_INFINITY);
- static final long LONG_POSITIVE_INFINITY =
- NumericUtils.doubleToSortableLong(Double.POSITIVE_INFINITY);
- static final int INT_NEGATIVE_INFINITY =
- NumericUtils.floatToSortableInt(Float.NEGATIVE_INFINITY);
- static final int INT_POSITIVE_INFINITY =
- NumericUtils.floatToSortableInt(Float.POSITIVE_INFINITY);
-
- /**
- * Subclass of FilteredTermsEnum for enumerating all terms that match the
- * sub-ranges for trie range queries, using flex API.
- * <p>
- * WARNING: This term enumeration is not guaranteed to be always ordered by
- * {@link Term#compareTo}.
- * The ordering depends on how {@link org.apache.lucene.util.LegacyNumericUtils#splitLongRange} and
- * {@link org.apache.lucene.util.LegacyNumericUtils#splitIntRange} generates the sub-ranges. For
- * {@link MultiTermQuery} ordering is not relevant.
- */
- private final class NumericRangeTermsEnum extends FilteredTermsEnum {
-
- private BytesRef currentLowerBound, currentUpperBound;
-
- private final LinkedList<BytesRef> rangeBounds = new LinkedList<>();
-
- NumericRangeTermsEnum(final TermsEnum tenum) {
- super(tenum);
- switch (dataType) {
- case LONG:
- case DOUBLE: {
- // lower
- long minBound;
- if (dataType == FieldType.LegacyNumericType.LONG) {
- minBound = (min == null) ? Long.MIN_VALUE : min.longValue();
- } else {
- assert dataType == FieldType.LegacyNumericType.DOUBLE;
- minBound = (min == null) ? LONG_NEGATIVE_INFINITY
- : NumericUtils.doubleToSortableLong(min.doubleValue());
- }
- if (!minInclusive && min != null) {
- if (minBound == Long.MAX_VALUE) break;
- minBound++;
- }
-
- // upper
- long maxBound;
- if (dataType == FieldType.LegacyNumericType.LONG) {
- maxBound = (max == null) ? Long.MAX_VALUE : max.longValue();
- } else {
- assert dataType == FieldType.LegacyNumericType.DOUBLE;
- maxBound = (max == null) ? LONG_POSITIVE_INFINITY
- : NumericUtils.doubleToSortableLong(max.doubleValue());
- }
- if (!maxInclusive && max != null) {
- if (maxBound == Long.MIN_VALUE) break;
- maxBound--;
- }
-
- LegacyNumericUtils.splitLongRange(new LegacyNumericUtils.LongRangeBuilder() {
- @Override
- public final void addRange(BytesRef minPrefixCoded, BytesRef maxPrefixCoded) {
- rangeBounds.add(minPrefixCoded);
- rangeBounds.add(maxPrefixCoded);
- }
- }, precisionStep, minBound, maxBound);
- break;
- }
-
- case INT:
- case FLOAT: {
- // lower
- int minBound;
- if (dataType == FieldType.LegacyNumericType.INT) {
- minBound = (min == null) ? Integer.MIN_VALUE : min.intValue();
- } else {
- assert dataType == FieldType.LegacyNumericType.FLOAT;
- minBound = (min == null) ? INT_NEGATIVE_INFINITY
- : NumericUtils.floatToSortableInt(min.floatValue());
- }
- if (!minInclusive && min != null) {
- if (minBound == Integer.MAX_VALUE) break;
- minBound++;
- }
-
- // upper
- int maxBound;
- if (dataType == LegacyNumericType.INT) {
- maxBound = (max == null) ? Integer.MAX_VALUE : max.intValue();
- } else {
- assert dataType == FieldType.LegacyNumericType.FLOAT;
- maxBound = (max == null) ? INT_POSITIVE_INFINITY
- : NumericUtils.floatToSortableInt(max.floatValue());
- }
- if (!maxInclusive && max != null) {
- if (maxBound == Integer.MIN_VALUE) break;
- maxBound--;
- }
-
- LegacyNumericUtils.splitIntRange(new LegacyNumericUtils.IntRangeBuilder() {
- @Override
- public final void addRange(BytesRef minPrefixCoded, BytesRef maxPrefixCoded) {
- rangeBounds.add(minPrefixCoded);
- rangeBounds.add(maxPrefixCoded);
- }
- }, precisionStep, minBound, maxBound);
- break;
- }
-
- default:
- // should never happen
- throw new IllegalArgumentException("Invalid LegacyNumericType");
- }
- }
-
- private void nextRange() {
- assert rangeBounds.size() % 2 == 0;
-
- currentLowerBound = rangeBounds.removeFirst();
- assert currentUpperBound == null || currentUpperBound.compareTo(currentLowerBound) <= 0 :
- "The current upper bound must be <= the new lower bound";
-
- currentUpperBound = rangeBounds.removeFirst();
- }
-
- @Override
- protected final BytesRef nextSeekTerm(BytesRef term) {
- while (rangeBounds.size() >= 2) {
- nextRange();
-
- // if the new upper bound is before the term parameter, the sub-range is never a hit
- if (term != null && term.compareTo(currentUpperBound) > 0)
- continue;
- // never seek backwards, so use current term if lower bound is smaller
- return (term != null && term.compareTo(currentLowerBound) > 0) ?
- term : currentLowerBound;
- }
-
- // no more sub-range enums available
- assert rangeBounds.isEmpty();
- currentLowerBound = currentUpperBound = null;
- return null;
- }
-
- @Override
- protected final AcceptStatus accept(BytesRef term) {
- while (currentUpperBound == null || term.compareTo(currentUpperBound) > 0) {
- if (rangeBounds.isEmpty())
- return AcceptStatus.END;
- // peek next sub-range, only seek if the current term is smaller than next lower bound
- if (term.compareTo(rangeBounds.getFirst()) < 0)
- return AcceptStatus.NO_AND_SEEK;
- // step forward to next range without seeking, as next lower range bound is less or equal current term
- nextRange();
- }
- return AcceptStatus.YES;
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/105c7eae/lucene/core/src/java/org/apache/lucene/util/LegacyNumericUtils.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/util/LegacyNumericUtils.java b/lucene/core/src/java/org/apache/lucene/util/LegacyNumericUtils.java
deleted file mode 100644
index 9a26bfa..0000000
--- a/lucene/core/src/java/org/apache/lucene/util/LegacyNumericUtils.java
+++ /dev/null
@@ -1,508 +0,0 @@
-/*
- * 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.
- */
-package org.apache.lucene.util;
-
-
-import java.io.IOException;
-
-import org.apache.lucene.index.FilterLeafReader;
-import org.apache.lucene.index.FilteredTermsEnum;
-import org.apache.lucene.index.Terms;
-import org.apache.lucene.index.TermsEnum;
-
-/**
- * This is a helper class to generate prefix-encoded representations for numerical values
- * and supplies converters to represent float/double values as sortable integers/longs.
- *
- * <p>To quickly execute range queries in Apache Lucene, a range is divided recursively
- * into multiple intervals for searching: The center of the range is searched only with
- * the lowest possible precision in the trie, while the boundaries are matched
- * more exactly. This reduces the number of terms dramatically.
- *
- * <p>This class generates terms to achieve this: First the numerical integer values need to
- * be converted to bytes. For that integer values (32 bit or 64 bit) are made unsigned
- * and the bits are converted to ASCII chars with each 7 bit. The resulting byte[] is
- * sortable like the original integer value (even using UTF-8 sort order). Each value is also
- * prefixed (in the first char) by the <code>shift</code> value (number of bits removed) used
- * during encoding.
- *
- * <p>For easy usage, the trie algorithm is implemented for indexing inside
- * {@link org.apache.lucene.analysis.LegacyNumericTokenStream} that can index <code>int</code>, <code>long</code>,
- * <code>float</code>, and <code>double</code>. For querying,
- * {@link org.apache.lucene.search.LegacyNumericRangeQuery} implements the query part
- * for the same data types.
- *
- * @lucene.internal
- *
- * @deprecated Please use {@link org.apache.lucene.index.PointValues} instead.
- *
- * @since 2.9, API changed non backwards-compliant in 4.0
- */
-
-@Deprecated
-public final class LegacyNumericUtils {
-
- private LegacyNumericUtils() {} // no instance!
-
- /**
- * The default precision step used by {@link org.apache.lucene.document.LegacyLongField},
- * {@link org.apache.lucene.document.LegacyDoubleField}, {@link org.apache.lucene.analysis.LegacyNumericTokenStream}, {@link
- * org.apache.lucene.search.LegacyNumericRangeQuery}.
- */
- public static final int PRECISION_STEP_DEFAULT = 16;
-
- /**
- * The default precision step used by {@link org.apache.lucene.document.LegacyIntField} and
- * {@link org.apache.lucene.document.LegacyFloatField}.
- */
- public static final int PRECISION_STEP_DEFAULT_32 = 8;
-
- /**
- * Longs are stored at lower precision by shifting off lower bits. The shift count is
- * stored as <code>SHIFT_START_LONG+shift</code> in the first byte
- */
- public static final byte SHIFT_START_LONG = 0x20;
-
- /**
- * The maximum term length (used for <code>byte[]</code> buffer size)
- * for encoding <code>long</code> values.
- * @see #longToPrefixCoded
- */
- public static final int BUF_SIZE_LONG = 63/7 + 2;
-
- /**
- * Integers are stored at lower precision by shifting off lower bits. The shift count is
- * stored as <code>SHIFT_START_INT+shift</code> in the first byte
- */
- public static final byte SHIFT_START_INT = 0x60;
-
- /**
- * The maximum term length (used for <code>byte[]</code> buffer size)
- * for encoding <code>int</code> values.
- * @see #intToPrefixCoded
- */
- public static final int BUF_SIZE_INT = 31/7 + 2;
-
- /**
- * Returns prefix coded bits after reducing the precision by <code>shift</code> bits.
- * This is method is used by {@link org.apache.lucene.analysis.LegacyNumericTokenStream}.
- * After encoding, {@code bytes.offset} will always be 0.
- * @param val the numeric value
- * @param shift how many bits to strip from the right
- * @param bytes will contain the encoded value
- */
- public static void longToPrefixCoded(final long val, final int shift, final BytesRefBuilder bytes) {
- // ensure shift is 0..63
- if ((shift & ~0x3f) != 0) {
- throw new IllegalArgumentException("Illegal shift value, must be 0..63; got shift=" + shift);
- }
- int nChars = (((63-shift)*37)>>8) + 1; // i/7 is the same as (i*37)>>8 for i in 0..63
- bytes.setLength(nChars+1); // one extra for the byte that contains the shift info
- bytes.grow(BUF_SIZE_LONG);
- bytes.setByteAt(0, (byte)(SHIFT_START_LONG + shift));
- long sortableBits = val ^ 0x8000000000000000L;
- sortableBits >>>= shift;
- while (nChars > 0) {
- // Store 7 bits per byte for compatibility
- // with UTF-8 encoding of terms
- bytes.setByteAt(nChars--, (byte)(sortableBits & 0x7f));
- sortableBits >>>= 7;
- }
- }
-
- /**
- * Returns prefix coded bits after reducing the precision by <code>shift</code> bits.
- * This is method is used by {@link org.apache.lucene.analysis.LegacyNumericTokenStream}.
- * After encoding, {@code bytes.offset} will always be 0.
- * @param val the numeric value
- * @param shift how many bits to strip from the right
- * @param bytes will contain the encoded value
- */
- public static void intToPrefixCoded(final int val, final int shift, final BytesRefBuilder bytes) {
- // ensure shift is 0..31
- if ((shift & ~0x1f) != 0) {
- throw new IllegalArgumentException("Illegal shift value, must be 0..31; got shift=" + shift);
- }
- int nChars = (((31-shift)*37)>>8) + 1; // i/7 is the same as (i*37)>>8 for i in 0..63
- bytes.setLength(nChars+1); // one extra for the byte that contains the shift info
- bytes.grow(LegacyNumericUtils.BUF_SIZE_LONG); // use the max
- bytes.setByteAt(0, (byte)(SHIFT_START_INT + shift));
- int sortableBits = val ^ 0x80000000;
- sortableBits >>>= shift;
- while (nChars > 0) {
- // Store 7 bits per byte for compatibility
- // with UTF-8 encoding of terms
- bytes.setByteAt(nChars--, (byte)(sortableBits & 0x7f));
- sortableBits >>>= 7;
- }
- }
-
-
- /**
- * Returns the shift value from a prefix encoded {@code long}.
- * @throws NumberFormatException if the supplied {@link BytesRef} is
- * not correctly prefix encoded.
- */
- public static int getPrefixCodedLongShift(final BytesRef val) {
- final int shift = val.bytes[val.offset] - SHIFT_START_LONG;
- if (shift > 63 || shift < 0)
- throw new NumberFormatException("Invalid shift value (" + shift + ") in prefixCoded bytes (is encoded value really an INT?)");
- return shift;
- }
-
- /**
- * Returns the shift value from a prefix encoded {@code int}.
- * @throws NumberFormatException if the supplied {@link BytesRef} is
- * not correctly prefix encoded.
- */
- public static int getPrefixCodedIntShift(final BytesRef val) {
- final int shift = val.bytes[val.offset] - SHIFT_START_INT;
- if (shift > 31 || shift < 0)
- throw new NumberFormatException("Invalid shift value in prefixCoded bytes (is encoded value really an INT?)");
- return shift;
- }
-
- /**
- * Returns a long from prefixCoded bytes.
- * Rightmost bits will be zero for lower precision codes.
- * This method can be used to decode a term's value.
- * @throws NumberFormatException if the supplied {@link BytesRef} is
- * not correctly prefix encoded.
- * @see #longToPrefixCoded
- */
- public static long prefixCodedToLong(final BytesRef val) {
- long sortableBits = 0L;
- for (int i=val.offset+1, limit=val.offset+val.length; i<limit; i++) {
- sortableBits <<= 7;
- final byte b = val.bytes[i];
- if (b < 0) {
- throw new NumberFormatException(
- "Invalid prefixCoded numerical value representation (byte "+
- Integer.toHexString(b&0xff)+" at position "+(i-val.offset)+" is invalid)"
- );
- }
- sortableBits |= b;
- }
- return (sortableBits << getPrefixCodedLongShift(val)) ^ 0x8000000000000000L;
- }
-
- /**
- * Returns an int from prefixCoded bytes.
- * Rightmost bits will be zero for lower precision codes.
- * This method can be used to decode a term's value.
- * @throws NumberFormatException if the supplied {@link BytesRef} is
- * not correctly prefix encoded.
- * @see #intToPrefixCoded
- */
- public static int prefixCodedToInt(final BytesRef val) {
- int sortableBits = 0;
- for (int i=val.offset+1, limit=val.offset+val.length; i<limit; i++) {
- sortableBits <<= 7;
- final byte b = val.bytes[i];
- if (b < 0) {
- throw new NumberFormatException(
- "Invalid prefixCoded numerical value representation (byte "+
- Integer.toHexString(b&0xff)+" at position "+(i-val.offset)+" is invalid)"
- );
- }
- sortableBits |= b;
- }
- return (sortableBits << getPrefixCodedIntShift(val)) ^ 0x80000000;
- }
-
- /**
- * Splits a long range recursively.
- * You may implement a builder that adds clauses to a
- * {@link org.apache.lucene.search.BooleanQuery} for each call to its
- * {@link LongRangeBuilder#addRange(BytesRef,BytesRef)}
- * method.
- * <p>This method is used by {@link org.apache.lucene.search.LegacyNumericRangeQuery}.
- */
- public static void splitLongRange(final LongRangeBuilder builder,
- final int precisionStep, final long minBound, final long maxBound
- ) {
- splitRange(builder, 64, precisionStep, minBound, maxBound);
- }
-
- /**
- * Splits an int range recursively.
- * You may implement a builder that adds clauses to a
- * {@link org.apache.lucene.search.BooleanQuery} for each call to its
- * {@link IntRangeBuilder#addRange(BytesRef,BytesRef)}
- * method.
- * <p>This method is used by {@link org.apache.lucene.search.LegacyNumericRangeQuery}.
- */
- public static void splitIntRange(final IntRangeBuilder builder,
- final int precisionStep, final int minBound, final int maxBound
- ) {
- splitRange(builder, 32, precisionStep, minBound, maxBound);
- }
-
- /** This helper does the splitting for both 32 and 64 bit. */
- private static void splitRange(
- final Object builder, final int valSize,
- final int precisionStep, long minBound, long maxBound
- ) {
- if (precisionStep < 1)
- throw new IllegalArgumentException("precisionStep must be >=1");
- if (minBound > maxBound) return;
- for (int shift=0; ; shift += precisionStep) {
- // calculate new bounds for inner precision
- final long diff = 1L << (shift+precisionStep),
- mask = ((1L<<precisionStep) - 1L) << shift;
- final boolean
- hasLower = (minBound & mask) != 0L,
- hasUpper = (maxBound & mask) != mask;
- final long
- nextMinBound = (hasLower ? (minBound + diff) : minBound) & ~mask,
- nextMaxBound = (hasUpper ? (maxBound - diff) : maxBound) & ~mask;
- final boolean
- lowerWrapped = nextMinBound < minBound,
- upperWrapped = nextMaxBound > maxBound;
-
- if (shift+precisionStep>=valSize || nextMinBound>nextMaxBound || lowerWrapped || upperWrapped) {
- // We are in the lowest precision or the next precision is not available.
- addRange(builder, valSize, minBound, maxBound, shift);
- // exit the split recursion loop
- break;
- }
-
- if (hasLower)
- addRange(builder, valSize, minBound, minBound | mask, shift);
- if (hasUpper)
- addRange(builder, valSize, maxBound & ~mask, maxBound, shift);
-
- // recurse to next precision
- minBound = nextMinBound;
- maxBound = nextMaxBound;
- }
- }
-
- /** Helper that delegates to correct range builder */
- private static void addRange(
- final Object builder, final int valSize,
- long minBound, long maxBound,
- final int shift
- ) {
- // for the max bound set all lower bits (that were shifted away):
- // this is important for testing or other usages of the splitted range
- // (e.g. to reconstruct the full range). The prefixEncoding will remove
- // the bits anyway, so they do not hurt!
- maxBound |= (1L << shift) - 1L;
- // delegate to correct range builder
- switch(valSize) {
- case 64:
- ((LongRangeBuilder)builder).addRange(minBound, maxBound, shift);
- break;
- case 32:
- ((IntRangeBuilder)builder).addRange((int)minBound, (int)maxBound, shift);
- break;
- default:
- // Should not happen!
- throw new IllegalArgumentException("valSize must be 32 or 64.");
- }
- }
-
- /**
- * Callback for {@link #splitLongRange}.
- * You need to overwrite only one of the methods.
- * @lucene.internal
- * @since 2.9, API changed non backwards-compliant in 4.0
- */
- public static abstract class LongRangeBuilder {
-
- /**
- * Overwrite this method, if you like to receive the already prefix encoded range bounds.
- * You can directly build classical (inclusive) range queries from them.
- */
- public void addRange(BytesRef minPrefixCoded, BytesRef maxPrefixCoded) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Overwrite this method, if you like to receive the raw long range bounds.
- * You can use this for e.g. debugging purposes (print out range bounds).
- */
- public void addRange(final long min, final long max, final int shift) {
- final BytesRefBuilder minBytes = new BytesRefBuilder(), maxBytes = new BytesRefBuilder();
- longToPrefixCoded(min, shift, minBytes);
- longToPrefixCoded(max, shift, maxBytes);
- addRange(minBytes.get(), maxBytes.get());
- }
-
- }
-
- /**
- * Callback for {@link #splitIntRange}.
- * You need to overwrite only one of the methods.
- * @lucene.internal
- * @since 2.9, API changed non backwards-compliant in 4.0
- */
- public static abstract class IntRangeBuilder {
-
- /**
- * Overwrite this method, if you like to receive the already prefix encoded range bounds.
- * You can directly build classical range (inclusive) queries from them.
- */
- public void addRange(BytesRef minPrefixCoded, BytesRef maxPrefixCoded) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Overwrite this method, if you like to receive the raw int range bounds.
- * You can use this for e.g. debugging purposes (print out range bounds).
- */
- public void addRange(final int min, final int max, final int shift) {
- final BytesRefBuilder minBytes = new BytesRefBuilder(), maxBytes = new BytesRefBuilder();
- intToPrefixCoded(min, shift, minBytes);
- intToPrefixCoded(max, shift, maxBytes);
- addRange(minBytes.get(), maxBytes.get());
- }
-
- }
-
- /**
- * Filters the given {@link TermsEnum} by accepting only prefix coded 64 bit
- * terms with a shift value of <tt>0</tt>.
- *
- * @param termsEnum
- * the terms enum to filter
- * @return a filtered {@link TermsEnum} that only returns prefix coded 64 bit
- * terms with a shift value of <tt>0</tt>.
- */
- public static TermsEnum filterPrefixCodedLongs(TermsEnum termsEnum) {
- return new SeekingNumericFilteredTermsEnum(termsEnum) {
-
- @Override
- protected AcceptStatus accept(BytesRef term) {
- return LegacyNumericUtils.getPrefixCodedLongShift(term) == 0 ? AcceptStatus.YES : AcceptStatus.END;
- }
- };
- }
-
- /**
- * Filters the given {@link TermsEnum} by accepting only prefix coded 32 bit
- * terms with a shift value of <tt>0</tt>.
- *
- * @param termsEnum
- * the terms enum to filter
- * @return a filtered {@link TermsEnum} that only returns prefix coded 32 bit
- * terms with a shift value of <tt>0</tt>.
- */
- public static TermsEnum filterPrefixCodedInts(TermsEnum termsEnum) {
- return new SeekingNumericFilteredTermsEnum(termsEnum) {
-
- @Override
- protected AcceptStatus accept(BytesRef term) {
- return LegacyNumericUtils.getPrefixCodedIntShift(term) == 0 ? AcceptStatus.YES : AcceptStatus.END;
- }
- };
- }
-
- /** Just like FilteredTermsEnum, except it adds a limited
- * seekCeil implementation that only works with {@link
- * #filterPrefixCodedInts} and {@link
- * #filterPrefixCodedLongs}. */
- private static abstract class SeekingNumericFilteredTermsEnum extends FilteredTermsEnum {
- public SeekingNumericFilteredTermsEnum(final TermsEnum tenum) {
- super(tenum, false);
- }
-
- @Override
- @SuppressWarnings("fallthrough")
- public SeekStatus seekCeil(BytesRef term) throws IOException {
-
- // NOTE: This is not general!! It only handles YES
- // and END, because that's all we need for the numeric
- // case here
-
- SeekStatus status = tenum.seekCeil(term);
- if (status == SeekStatus.END) {
- return SeekStatus.END;
- }
-
- actualTerm = tenum.term();
-
- if (accept(actualTerm) == AcceptStatus.YES) {
- return status;
- } else {
- return SeekStatus.END;
- }
- }
- }
-
- private static Terms intTerms(Terms terms) {
- return new FilterLeafReader.FilterTerms(terms) {
- @Override
- public TermsEnum iterator() throws IOException {
- return filterPrefixCodedInts(in.iterator());
- }
- };
- }
-
- private static Terms longTerms(Terms terms) {
- return new FilterLeafReader.FilterTerms(terms) {
- @Override
- public TermsEnum iterator() throws IOException {
- return filterPrefixCodedLongs(in.iterator());
- }
- };
- }
-
- /**
- * Returns the minimum int value indexed into this
- * numeric field or null if no terms exist.
- */
- public static Integer getMinInt(Terms terms) throws IOException {
- // All shift=0 terms are sorted first, so we don't need
- // to filter the incoming terms; we can just get the
- // min:
- BytesRef min = terms.getMin();
- return (min != null) ? LegacyNumericUtils.prefixCodedToInt(min) : null;
- }
-
- /**
- * Returns the maximum int value indexed into this
- * numeric field or null if no terms exist.
- */
- public static Integer getMaxInt(Terms terms) throws IOException {
- BytesRef max = intTerms(terms).getMax();
- return (max != null) ? LegacyNumericUtils.prefixCodedToInt(max) : null;
- }
-
- /**
- * Returns the minimum long value indexed into this
- * numeric field or null if no terms exist.
- */
- public static Long getMinLong(Terms terms) throws IOException {
- // All shift=0 terms are sorted first, so we don't need
- // to filter the incoming terms; we can just get the
- // min:
- BytesRef min = terms.getMin();
- return (min != null) ? LegacyNumericUtils.prefixCodedToLong(min) : null;
- }
-
- /**
- * Returns the maximum long value indexed into this
- * numeric field or null if no terms exist.
- */
- public static Long getMaxLong(Terms terms) throws IOException {
- BytesRef max = longTerms(terms).getMax();
- return (max != null) ? LegacyNumericUtils.prefixCodedToLong(max) : null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/105c7eae/lucene/core/src/test/org/apache/lucene/analysis/TestNumericTokenStream.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/analysis/TestNumericTokenStream.java b/lucene/core/src/test/org/apache/lucene/analysis/TestNumericTokenStream.java
deleted file mode 100644
index dfaa20e..0000000
--- a/lucene/core/src/test/org/apache/lucene/analysis/TestNumericTokenStream.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * 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.
- */
-package org.apache.lucene.analysis;
-
-
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.LegacyNumericUtils;
-import org.apache.lucene.analysis.LegacyNumericTokenStream.LegacyNumericTermAttributeImpl;
-import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute;
-import org.apache.lucene.analysis.tokenattributes.TestCharTermAttributeImpl;
-import org.apache.lucene.analysis.tokenattributes.TypeAttribute;
-import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
-import org.apache.lucene.analysis.tokenattributes.CharTermAttributeImpl;
-
-@Deprecated
-public class TestNumericTokenStream extends BaseTokenStreamTestCase {
-
- final long lvalue = random().nextLong();
- final int ivalue = random().nextInt();
-
- public void testLongStream() throws Exception {
- @SuppressWarnings("resource")
- final LegacyNumericTokenStream stream=new LegacyNumericTokenStream().setLongValue(lvalue);
- final TermToBytesRefAttribute bytesAtt = stream.getAttribute(TermToBytesRefAttribute.class);
- assertNotNull(bytesAtt);
- final TypeAttribute typeAtt = stream.getAttribute(TypeAttribute.class);
- assertNotNull(typeAtt);
- final LegacyNumericTokenStream.LegacyNumericTermAttribute numericAtt = stream.getAttribute(LegacyNumericTokenStream.LegacyNumericTermAttribute.class);
- assertNotNull(numericAtt);
- stream.reset();
- assertEquals(64, numericAtt.getValueSize());
- for (int shift=0; shift<64; shift+= LegacyNumericUtils.PRECISION_STEP_DEFAULT) {
- assertTrue("New token is available", stream.incrementToken());
- assertEquals("Shift value wrong", shift, numericAtt.getShift());
- assertEquals("Term is incorrectly encoded", lvalue & ~((1L << shift) - 1L), LegacyNumericUtils.prefixCodedToLong(bytesAtt.getBytesRef()));
- assertEquals("Term raw value is incorrectly encoded", lvalue & ~((1L << shift) - 1L), numericAtt.getRawValue());
- assertEquals("Type incorrect", (shift == 0) ? LegacyNumericTokenStream.TOKEN_TYPE_FULL_PREC : LegacyNumericTokenStream.TOKEN_TYPE_LOWER_PREC, typeAtt.type());
- }
- assertFalse("More tokens available", stream.incrementToken());
- stream.end();
- stream.close();
- }
-
- public void testIntStream() throws Exception {
- @SuppressWarnings("resource")
- final LegacyNumericTokenStream stream=new LegacyNumericTokenStream().setIntValue(ivalue);
- final TermToBytesRefAttribute bytesAtt = stream.getAttribute(TermToBytesRefAttribute.class);
- assertNotNull(bytesAtt);
- final TypeAttribute typeAtt = stream.getAttribute(TypeAttribute.class);
- assertNotNull(typeAtt);
- final LegacyNumericTokenStream.LegacyNumericTermAttribute numericAtt = stream.getAttribute(LegacyNumericTokenStream.LegacyNumericTermAttribute.class);
- assertNotNull(numericAtt);
- stream.reset();
- assertEquals(32, numericAtt.getValueSize());
- for (int shift=0; shift<32; shift+= LegacyNumericUtils.PRECISION_STEP_DEFAULT) {
- assertTrue("New token is available", stream.incrementToken());
- assertEquals("Shift value wrong", shift, numericAtt.getShift());
- assertEquals("Term is incorrectly encoded", ivalue & ~((1 << shift) - 1), LegacyNumericUtils.prefixCodedToInt(bytesAtt.getBytesRef()));
- assertEquals("Term raw value is incorrectly encoded", ((long) ivalue) & ~((1L << shift) - 1L), numericAtt.getRawValue());
- assertEquals("Type incorrect", (shift == 0) ? LegacyNumericTokenStream.TOKEN_TYPE_FULL_PREC : LegacyNumericTokenStream.TOKEN_TYPE_LOWER_PREC, typeAtt.type());
- }
- assertFalse("More tokens available", stream.incrementToken());
- stream.end();
- stream.close();
- }
-
- public void testNotInitialized() throws Exception {
- final LegacyNumericTokenStream stream=new LegacyNumericTokenStream();
-
- expectThrows(IllegalStateException.class, () -> {
- stream.reset();
- });
-
- expectThrows(IllegalStateException.class, () -> {
- stream.incrementToken();
- });
-
- stream.close();
- }
-
- public static interface TestAttribute extends CharTermAttribute {}
- public static class TestAttributeImpl extends CharTermAttributeImpl implements TestAttribute {}
-
- public void testCTA() throws Exception {
- final LegacyNumericTokenStream stream=new LegacyNumericTokenStream();
- IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> {
- stream.addAttribute(CharTermAttribute.class);
- });
- assertTrue(e.getMessage().startsWith("LegacyNumericTokenStream does not support"));
-
- e = expectThrows(IllegalArgumentException.class, () -> {
- stream.addAttribute(TestAttribute.class);
- });
- assertTrue(e.getMessage().startsWith("LegacyNumericTokenStream does not support"));
- stream.close();
- }
-
- /** LUCENE-7027 */
- public void testCaptureStateAfterExhausted() throws Exception {
- // default precstep
- try (LegacyNumericTokenStream stream=new LegacyNumericTokenStream()) {
- // int
- stream.setIntValue(ivalue);
- stream.reset();
- while (stream.incrementToken());
- stream.captureState();
- stream.end();
- stream.captureState();
- // long
- stream.setLongValue(lvalue);
- stream.reset();
- while (stream.incrementToken());
- stream.captureState();
- stream.end();
- stream.captureState();
- }
- // huge precstep
- try (LegacyNumericTokenStream stream=new LegacyNumericTokenStream(Integer.MAX_VALUE)) {
- // int
- stream.setIntValue(ivalue);
- stream.reset();
- while (stream.incrementToken());
- stream.captureState();
- stream.end();
- stream.captureState();
- // long
- stream.setLongValue(lvalue);
- stream.reset();
- while (stream.incrementToken());
- stream.captureState();
- stream.end();
- stream.captureState();
- }
- }
-
- public void testAttributeClone() throws Exception {
- LegacyNumericTermAttributeImpl att = new LegacyNumericTermAttributeImpl();
- att.init(lvalue, 64, 8, 0); // set some value, to make getBytesRef() work
- LegacyNumericTermAttributeImpl copy = TestCharTermAttributeImpl.assertCloneIsEqual(att);
- assertNotSame(att.getBytesRef(), copy.getBytesRef());
- LegacyNumericTermAttributeImpl copy2 = TestCharTermAttributeImpl.assertCopyIsEqual(att);
- assertNotSame(att.getBytesRef(), copy2.getBytesRef());
-
- // LUCENE-7027 test
- att.init(lvalue, 64, 8, 64); // Exhausted TokenStream -> should return empty BytesRef
- assertEquals(new BytesRef(), att.getBytesRef());
- copy = TestCharTermAttributeImpl.assertCloneIsEqual(att);
- assertEquals(new BytesRef(), copy.getBytesRef());
- assertNotSame(att.getBytesRef(), copy.getBytesRef());
- copy2 = TestCharTermAttributeImpl.assertCopyIsEqual(att);
- assertEquals(new BytesRef(), copy2.getBytesRef());
- assertNotSame(att.getBytesRef(), copy2.getBytesRef());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/105c7eae/lucene/core/src/test/org/apache/lucene/document/TestField.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestField.java b/lucene/core/src/test/org/apache/lucene/document/TestField.java
index 92d6a83..4ef7ffb 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestField.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestField.java
@@ -79,29 +79,7 @@ public class TestField extends LuceneTestCase {
assertEquals("DoublePoint <foo:6.0,7.0>", field.toString());
}
- public void testLegacyDoubleField() throws Exception {
- Field fields[] = new Field[] {
- new LegacyDoubleField("foo", 5d, Field.Store.NO),
- new LegacyDoubleField("foo", 5d, Field.Store.YES)
- };
- for (Field field : fields) {
- trySetBoost(field);
- trySetByteValue(field);
- trySetBytesValue(field);
- trySetBytesRefValue(field);
- field.setDoubleValue(6d); // ok
- trySetIntValue(field);
- trySetFloatValue(field);
- trySetLongValue(field);
- trySetReaderValue(field);
- trySetShortValue(field);
- trySetStringValue(field);
- trySetTokenStreamValue(field);
-
- assertEquals(6d, field.numericValue().doubleValue(), 0.0d);
- }
- }
public void testDoubleDocValuesField() throws Exception {
DoubleDocValuesField field = new DoubleDocValuesField("foo", 5d);
@@ -185,30 +163,6 @@ public class TestField extends LuceneTestCase {
assertEquals("FloatPoint <foo:6.0,7.0>", field.toString());
}
- public void testLegacyFloatField() throws Exception {
- Field fields[] = new Field[] {
- new LegacyFloatField("foo", 5f, Field.Store.NO),
- new LegacyFloatField("foo", 5f, Field.Store.YES)
- };
-
- for (Field field : fields) {
- trySetBoost(field);
- trySetByteValue(field);
- trySetBytesValue(field);
- trySetBytesRefValue(field);
- trySetDoubleValue(field);
- trySetIntValue(field);
- field.setFloatValue(6f); // ok
- trySetLongValue(field);
- trySetReaderValue(field);
- trySetShortValue(field);
- trySetStringValue(field);
- trySetTokenStreamValue(field);
-
- assertEquals(6f, field.numericValue().floatValue(), 0.0f);
- }
- }
-
public void testIntPoint() throws Exception {
Field field = new IntPoint("foo", 5);
@@ -253,30 +207,6 @@ public class TestField extends LuceneTestCase {
assertEquals("IntPoint <foo:6,7>", field.toString());
}
- public void testLegacyIntField() throws Exception {
- Field fields[] = new Field[] {
- new LegacyIntField("foo", 5, Field.Store.NO),
- new LegacyIntField("foo", 5, Field.Store.YES)
- };
-
- for (Field field : fields) {
- trySetBoost(field);
- trySetByteValue(field);
- trySetBytesValue(field);
- trySetBytesRefValue(field);
- trySetDoubleValue(field);
- field.setIntValue(6); // ok
- trySetFloatValue(field);
- trySetLongValue(field);
- trySetReaderValue(field);
- trySetShortValue(field);
- trySetStringValue(field);
- trySetTokenStreamValue(field);
-
- assertEquals(6, field.numericValue().intValue());
- }
- }
-
public void testNumericDocValuesField() throws Exception {
NumericDocValuesField field = new NumericDocValuesField("foo", 5L);
@@ -340,30 +270,6 @@ public class TestField extends LuceneTestCase {
assertEquals("LongPoint <foo:6,7>", field.toString());
}
- public void testLegacyLongField() throws Exception {
- Field fields[] = new Field[] {
- new LegacyLongField("foo", 5L, Field.Store.NO),
- new LegacyLongField("foo", 5L, Field.Store.YES)
- };
-
- for (Field field : fields) {
- trySetBoost(field);
- trySetByteValue(field);
- trySetBytesValue(field);
- trySetBytesRefValue(field);
- trySetDoubleValue(field);
- trySetIntValue(field);
- trySetFloatValue(field);
- field.setLongValue(6); // ok
- trySetReaderValue(field);
- trySetShortValue(field);
- trySetStringValue(field);
- trySetTokenStreamValue(field);
-
- assertEquals(6L, field.numericValue().longValue());
- }
- }
-
public void testSortedBytesDocValuesField() throws Exception {
SortedDocValuesField field = new SortedDocValuesField("foo", new BytesRef("bar"));
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/105c7eae/lucene/core/src/test/org/apache/lucene/document/TestFieldType.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestFieldType.java b/lucene/core/src/test/org/apache/lucene/document/TestFieldType.java
index da76f40..9214cb9 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestFieldType.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestFieldType.java
@@ -18,7 +18,6 @@ package org.apache.lucene.document;
import java.lang.reflect.Method;
-import org.apache.lucene.document.FieldType.LegacyNumericType;
import org.apache.lucene.index.DocValuesType;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.PointValues;
@@ -58,14 +57,6 @@ public class TestFieldType extends LuceneTestCase {
ft7.setOmitNorms(true);
assertFalse(ft7.equals(ft));
- FieldType ft8 = new FieldType();
- ft8.setNumericType(LegacyNumericType.DOUBLE);
- assertFalse(ft8.equals(ft));
-
- FieldType ft9 = new FieldType();
- ft9.setNumericPrecisionStep(3);
- assertFalse(ft9.equals(ft));
-
FieldType ft10 = new FieldType();
ft10.setStoreTermVectors(true);
assertFalse(ft10.equals(ft));