Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-17698: Remove deprecated EnumField (#3256)

Eric Pugh733bf41ec29d
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 275a8f734fe..a4bd16c5311 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -131,6 +131,8 @@ Deprecation Removals
* SOLR-17634: Removed the "version" parameter that the SolrJ client would add to almost all Solr
requests in relation to the version of the response format parsing ("wt" param). (David Smiley)
+* SOLR-17698: Removed deprecated EnumField field type. (Eric Pugh, David Smiley)
+
Dependency Upgrades
---------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/component/StatsValuesFactory.java b/solr/core/src/java/org/apache/solr/handler/component/StatsValuesFactory.java
index 1c29502b935..5a5a9b0dc97 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/StatsValuesFactory.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/StatsValuesFactory.java
@@ -37,8 +37,8 @@ import org.apache.solr.common.SolrException;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.handler.component.StatsField.Stat;
-import org.apache.solr.schema.AbstractEnumField;
import org.apache.solr.schema.DatePointField;
+import org.apache.solr.schema.EnumFieldType;
import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.PointField;
import org.apache.solr.schema.SchemaField;
@@ -85,7 +85,7 @@ public class StatsValuesFactory {
return statsValue;
} else if (StrField.class.isInstance(fieldType)) {
return new StringStatsValues(statsField);
- } else if (AbstractEnumField.class.isInstance(fieldType)) {
+ } else if (EnumFieldType.class.isInstance(fieldType)) {
return new EnumStatsValues(statsField);
} else {
throw new SolrException(
diff --git a/solr/core/src/java/org/apache/solr/schema/AbstractEnumField.java b/solr/core/src/java/org/apache/solr/schema/AbstractEnumField.java
deleted file mode 100644
index 7ae2a578dc8..00000000000
--- a/solr/core/src/java/org/apache/solr/schema/AbstractEnumField.java
+++ /dev/null
@@ -1,360 +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.solr.schema;
-
-import java.io.IOException;
-import java.lang.invoke.MethodHandles;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
-import org.apache.lucene.index.IndexableField;
-import org.apache.lucene.queries.function.ValueSource;
-import org.apache.lucene.queries.function.valuesource.EnumFieldSource;
-import org.apache.lucene.search.SortField;
-import org.apache.lucene.util.BytesRefBuilder;
-import org.apache.solr.common.EnumFieldValue;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.core.SolrResourceLoader;
-import org.apache.solr.response.TextResponseWriter;
-import org.apache.solr.search.QParser;
-import org.apache.solr.util.SafeXMLParsing;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
-/** Abstract Field type for support of string values with custom sort order. */
-public abstract class AbstractEnumField extends PrimitiveFieldType {
- protected EnumMapping enumMapping;
-
- @Override
- protected void init(IndexSchema schema, Map<String, String> args) {
- super.init(schema, args);
- enumMapping = new EnumMapping(schema, this, args);
- }
-
- public EnumMapping getEnumMapping() {
- return enumMapping;
- }
-
- /**
- * Models all the info contained in an enums config XML file
- *
- * @lucene.internal
- */
- public static final class EnumMapping {
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
- public static final String PARAM_ENUMS_CONFIG = "enumsConfig";
- public static final String PARAM_ENUM_NAME = "enumName";
- public static final Integer DEFAULT_VALUE = -1;
-
- public final Map<String, Integer> enumStringToIntMap;
- public final Map<Integer, String> enumIntToStringMap;
-
- private final String enumsConfigFile;
- private final String enumName;
-
- /**
- * Takes in a FieldType and the initArgs Map used for that type, removing the keys that specify
- * the enum.
- *
- * @param schema for opening resources
- * @param fieldType Used for logging or error messages
- * @param args the init args to consume the enum name + config file from
- */
- public EnumMapping(IndexSchema schema, FieldType fieldType, Map<String, String> args) {
- final String ftName = fieldType.getTypeName();
-
- // NOTE: ghosting member variables for most of constructor
- final Map<String, Integer> enumStringToIntMap = new HashMap<>();
- final Map<Integer, String> enumIntToStringMap = new HashMap<>();
-
- enumsConfigFile = args.get(PARAM_ENUMS_CONFIG);
- if (enumsConfigFile == null) {
- throw new SolrException(
- SolrException.ErrorCode.NOT_FOUND, ftName + ": No enums config file was configured.");
- }
- enumName = args.get(PARAM_ENUM_NAME);
- if (enumName == null) {
- throw new SolrException(
- SolrException.ErrorCode.NOT_FOUND, ftName + ": No enum name was configured.");
- }
-
- final SolrResourceLoader loader = schema.getResourceLoader();
- try {
- log.debug("Reloading enums config file from {}", enumsConfigFile);
- Document doc = SafeXMLParsing.parseConfigXML(log, loader, enumsConfigFile);
- final XPathFactory xpathFactory = XPathFactory.newInstance();
- final XPath xpath = xpathFactory.newXPath();
- final String xpathStr =
- String.format(Locale.ROOT, "/enumsConfig/enum[@name='%s']", enumName);
- final NodeList nodes = (NodeList) xpath.evaluate(xpathStr, doc, XPathConstants.NODESET);
- final int nodesLength = nodes.getLength();
- if (nodesLength == 0) {
- String exceptionMessage =
- String.format(
- Locale.ENGLISH,
- "%s: No enum configuration found for enum '%s' in %s.",
- ftName,
- enumName,
- enumsConfigFile);
- throw new SolrException(SolrException.ErrorCode.NOT_FOUND, exceptionMessage);
- }
- if (nodesLength > 1) {
- log.warn(
- "{}: More than one enum configuration found for enum '{}' in {}. The last one was taken.",
- ftName,
- enumName,
- enumsConfigFile);
- }
- final Node enumNode = nodes.item(nodesLength - 1);
- final NodeList valueNodes =
- (NodeList) xpath.evaluate("value", enumNode, XPathConstants.NODESET);
- for (int i = 0; i < valueNodes.getLength(); i++) {
- final Node valueNode = valueNodes.item(i);
- final String valueStr = valueNode.getTextContent();
- if ((valueStr == null) || (valueStr.length() == 0)) {
- final String exceptionMessage =
- String.format(
- Locale.ENGLISH,
- "%s: A value was defined with an no value in enum '%s' in %s.",
- ftName,
- enumName,
- enumsConfigFile);
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, exceptionMessage);
- }
- if (enumStringToIntMap.containsKey(valueStr)) {
- final String exceptionMessage =
- String.format(
- Locale.ENGLISH,
- "%s: A duplicated definition was found for value '%s' in enum '%s' in %s.",
- ftName,
- valueStr,
- enumName,
- enumsConfigFile);
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, exceptionMessage);
- }
- enumIntToStringMap.put(i, valueStr);
- enumStringToIntMap.put(valueStr, i);
- }
- } catch (IOException | SAXException | XPathExpressionException e) {
- throw new SolrException(
- SolrException.ErrorCode.BAD_REQUEST, ftName + ": Error while parsing enums config.", e);
- }
-
- if ((enumStringToIntMap.size() == 0) || (enumIntToStringMap.size() == 0)) {
- String exceptionMessage =
- String.format(
- Locale.ENGLISH,
- "%s: Invalid configuration was defined for enum '%s' in %s.",
- ftName,
- enumName,
- enumsConfigFile);
- throw new SolrException(SolrException.ErrorCode.NOT_FOUND, exceptionMessage);
- }
-
- this.enumStringToIntMap = Collections.unmodifiableMap(enumStringToIntMap);
- this.enumIntToStringMap = Collections.unmodifiableMap(enumIntToStringMap);
-
- args.remove(PARAM_ENUMS_CONFIG);
- args.remove(PARAM_ENUM_NAME);
- }
-
- /**
- * Converting the (internal) integer value (indicating the sort order) to string (displayed)
- * value
- *
- * @param intVal integer value
- * @return string value
- */
- public String intValueToStringValue(Integer intVal) {
- if (intVal == null) return null;
-
- final String enumString = enumIntToStringMap.get(intVal);
- if (enumString != null) return enumString;
- // can't find matching enum name - return DEFAULT_VALUE.toString()
- return DEFAULT_VALUE.toString();
- }
-
- /**
- * Converting the string (displayed) value (internal) to integer value (indicating the sort
- * order)
- *
- * @param stringVal string value
- * @return integer value
- */
- public Integer stringValueToIntValue(String stringVal) {
- if (stringVal == null) return null;
-
- Integer intValue;
- final Integer enumInt = enumStringToIntMap.get(stringVal);
- if (enumInt != null) { // enum int found for string
- return enumInt;
- }
-
- // enum int not found for string
- intValue = tryParseInt(stringVal);
- if (intValue == null) { // not Integer
- intValue = DEFAULT_VALUE;
- }
- final String enumString = enumIntToStringMap.get(intValue);
- if (enumString != null) { // has matching string
- return intValue;
- }
-
- return DEFAULT_VALUE;
- }
-
- private static Integer tryParseInt(String valueStr) {
- Integer intValue = null;
- try {
- intValue = Integer.parseInt(valueStr);
- } catch (NumberFormatException ignore) {
- }
- return intValue;
- }
- }
-
- @Override
- public EnumFieldValue toObject(IndexableField f) {
- Integer intValue = null;
- String stringValue = null;
- final Number val = f.numericValue();
- if (val != null) {
- intValue = val.intValue();
- stringValue = enumMapping.intValueToStringValue(intValue);
- }
- return new EnumFieldValue(intValue, stringValue);
- }
-
- @Override
- public SortField getSortField(SchemaField field, boolean top) {
- if (field.multiValued()) {
- MultiValueSelector selector = field.type.getDefaultMultiValueSelectorForSort(field, top);
- if (null != selector) {
- final SortField result =
- getSortedSetSortField(
- field,
- selector.getSortedSetSelectorType(),
- // yes: Strings, it's how SortedSetSortField works
- top,
- SortField.STRING_FIRST,
- SortField.STRING_LAST);
- if (null == result.getMissingValue()) {
- // special case 'enum' default behavior: assume missing values are "below" all enum values
- result.setMissingValue(SortField.STRING_FIRST);
- }
- return result;
- }
- }
-
- // else...
- // either single valued, or don't support implicit multi selector
- // (in which case let getSortField() give the error)
- final SortField result =
- getSortField(field, SortField.Type.INT, top, Integer.MIN_VALUE, Integer.MAX_VALUE);
-
- if (null == result.getMissingValue()) {
- // special case 'enum' default behavior: assume missing values are "below" all enum values
- result.setMissingValue(Integer.MIN_VALUE);
- }
- return result;
- }
-
- @Override
- public ValueSource getValueSource(SchemaField field, QParser qparser) {
- field.checkFieldCacheSource();
- return new EnumFieldSource(
- field.getName(), enumMapping.enumIntToStringMap, enumMapping.enumStringToIntMap);
- }
-
- @Override
- public void write(TextResponseWriter writer, String name, IndexableField f) throws IOException {
- final Number val = f.numericValue();
- if (val == null) {
- writer.writeNull(name);
- return;
- }
-
- final String readableValue = enumMapping.intValueToStringValue(val.intValue());
- writer.writeStr(name, readableValue, true);
- }
-
- @Override
- public boolean isTokenized() {
- return false;
- }
-
- @Override
- public NumberType getNumberType() {
- return NumberType.INTEGER;
- }
-
- @Override
- public String readableToIndexed(String val) {
- if (val == null) return null;
-
- final BytesRefBuilder bytes = new BytesRefBuilder();
- readableToIndexed(val, bytes);
- return bytes.get().utf8ToString();
- }
-
- @Override
- public String toInternal(String val) {
- return readableToIndexed(val);
- }
-
- @Override
- public String toExternal(IndexableField f) {
- final Number val = f.numericValue();
- if (val == null) return null;
-
- return enumMapping.intValueToStringValue(val.intValue());
- }
-
- @Override
- public Object toNativeType(Object val) {
- if (val instanceof CharSequence) {
- final String str = val.toString();
- final Integer entry = enumMapping.enumStringToIntMap.get(str);
- if (entry != null) {
- return new EnumFieldValue(entry, str);
- } else {
- try {
- final int num = Integer.parseInt(str);
- return new EnumFieldValue(num, enumMapping.enumIntToStringMap.get(num));
- } catch (NumberFormatException ignore) {
- // Could not convert to Integer so fall through.
- }
- }
- } else if (val instanceof Number) {
- final int num = ((Number) val).intValue();
- return new EnumFieldValue(num, enumMapping.enumIntToStringMap.get(num));
- }
-
- return super.toNativeType(val);
- }
-}
diff --git a/solr/core/src/java/org/apache/solr/schema/EnumField.java b/solr/core/src/java/org/apache/solr/schema/EnumField.java
deleted file mode 100644
index 6a9633dc454..00000000000
--- a/solr/core/src/java/org/apache/solr/schema/EnumField.java
+++ /dev/null
@@ -1,217 +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.solr.schema;
-
-import java.lang.invoke.MethodHandles;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
-import org.apache.lucene.document.NumericDocValuesField;
-import org.apache.lucene.document.SortedSetDocValuesField;
-import org.apache.lucene.index.IndexableField;
-import org.apache.lucene.search.ConstantScoreQuery;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.BytesRefBuilder;
-import org.apache.lucene.util.CharsRef;
-import org.apache.lucene.util.CharsRefBuilder;
-import org.apache.solr.common.EnumFieldValue;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.legacy.LegacyFieldType;
-import org.apache.solr.legacy.LegacyIntField;
-import org.apache.solr.legacy.LegacyNumericRangeQuery;
-import org.apache.solr.legacy.LegacyNumericType;
-import org.apache.solr.legacy.LegacyNumericUtils;
-import org.apache.solr.search.QParser;
-import org.apache.solr.uninverting.UninvertingReader.Type;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Field type for support of string values with custom sort order.
- *
- * @deprecated use {@link EnumFieldType} instead.
- */
-@Deprecated
-public class EnumField extends AbstractEnumField {
-
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- protected static final int DEFAULT_PRECISION_STEP = Integer.MAX_VALUE;
-
- @Override
- public Type getUninversionType(SchemaField sf) {
- if (sf.multiValued()) {
- return Type.SORTED_SET_INTEGER;
- } else {
- return Type.LEGACY_INTEGER;
- }
- }
-
- @Override
- protected Query getSpecializedRangeQuery(
- QParser parser,
- SchemaField field,
- String min,
- String max,
- boolean minInclusive,
- boolean maxInclusive) {
- Integer minValue = enumMapping.stringValueToIntValue(min);
- Integer maxValue = enumMapping.stringValueToIntValue(max);
-
- if (field.multiValued() && field.hasDocValues() && !field.indexed()) {
- // for the multi-valued dv-case, the default rangeimpl over toInternal is correct
- return super.getSpecializedRangeQuery(
- parser, field, minValue.toString(), maxValue.toString(), minInclusive, maxInclusive);
- }
- Query query = null;
- final boolean matchOnly = field.hasDocValues() && !field.indexed();
- if (matchOnly) {
- long lowerValue = Long.MIN_VALUE;
- long upperValue = Long.MAX_VALUE;
- if (minValue != null) {
- lowerValue = minValue.longValue();
- if (minInclusive == false) {
- ++lowerValue;
- }
- }
- if (maxValue != null) {
- upperValue = maxValue.longValue();
- if (maxInclusive == false) {
- --upperValue;
- }
- }
- query =
- new ConstantScoreQuery(
- NumericDocValuesField.newSlowRangeQuery(field.getName(), lowerValue, upperValue));
- } else {
- query =
- LegacyNumericRangeQuery.newIntRange(
- field.getName(),
- DEFAULT_PRECISION_STEP,
- min == null ? null : minValue,
- max == null ? null : maxValue,
- minInclusive,
- maxInclusive);
- }
-
- return query;
- }
-
- @Override
- public void readableToIndexed(CharSequence val, BytesRefBuilder result) {
- final String s = val.toString();
- if (s == null) return;
-
- final Integer intValue = enumMapping.stringValueToIntValue(s);
- LegacyNumericUtils.intToPrefixCoded(intValue, 0, result);
- }
-
- @Override
- public String indexedToReadable(String indexedForm) {
- if (indexedForm == null) return null;
- final BytesRef bytesRef = new BytesRef(indexedForm);
- final Integer intValue = LegacyNumericUtils.prefixCodedToInt(bytesRef);
- return enumMapping.intValueToStringValue(intValue);
- }
-
- @Override
- public CharsRef indexedToReadable(BytesRef input, CharsRefBuilder output) {
- final Integer intValue = LegacyNumericUtils.prefixCodedToInt(input);
- final String stringValue = enumMapping.intValueToStringValue(intValue);
- output.grow(stringValue.length());
- output.setLength(stringValue.length());
- stringValue.getChars(0, output.length(), output.chars(), 0);
- return output.get();
- }
-
- @Override
- public EnumFieldValue toObject(SchemaField sf, BytesRef term) {
- final Integer intValue = LegacyNumericUtils.prefixCodedToInt(term);
- final String stringValue = enumMapping.intValueToStringValue(intValue);
- return new EnumFieldValue(intValue, stringValue);
- }
-
- @Override
- public String storedToIndexed(IndexableField f) {
- final Number val = f.numericValue();
- if (val == null) return null;
- final BytesRefBuilder bytes = new BytesRefBuilder();
- LegacyNumericUtils.intToPrefixCoded(val.intValue(), 0, bytes);
- return bytes.get().utf8ToString();
- }
-
- @Override
- public IndexableField createField(SchemaField field, Object value) {
- final boolean indexed = field.indexed();
- final boolean stored = field.stored();
- final boolean docValues = field.hasDocValues();
-
- if (!indexed && !stored && !docValues) {
- if (log.isTraceEnabled()) {
- log.trace("Ignoring unindexed/unstored field: {}", field);
- }
- return null;
- }
- final Integer intValue = enumMapping.stringValueToIntValue(value.toString());
- if (intValue == null || intValue.equals(EnumMapping.DEFAULT_VALUE)) {
- String exceptionMessage =
- String.format(
- Locale.ENGLISH,
- "Unknown value for enum field: %s, value: %s",
- field.getName(),
- value.toString());
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, exceptionMessage);
- }
-
- final LegacyFieldType newType = new LegacyFieldType();
-
- newType.setTokenized(field.isTokenized());
- newType.setStored(field.stored());
- newType.setOmitNorms(field.omitNorms());
- newType.setIndexOptions(field.indexOptions());
- newType.setStoreTermVectors(field.storeTermVector());
- newType.setStoreTermVectorOffsets(field.storeTermOffsets());
- newType.setStoreTermVectorPositions(field.storeTermPositions());
- newType.setStoreTermVectorPayloads(field.storeTermPayloads());
- newType.setNumericType(LegacyNumericType.INT);
- newType.setNumericPrecisionStep(DEFAULT_PRECISION_STEP);
-
- return new LegacyIntField(field.getName(), intValue.intValue(), newType);
- }
-
- @Override
- public List<IndexableField> createFields(SchemaField sf, Object value) {
- if (sf.hasDocValues()) {
- List<IndexableField> fields = new ArrayList<>();
- final IndexableField field = createField(sf, value);
- fields.add(field);
-
- if (sf.multiValued()) {
- BytesRefBuilder bytes = new BytesRefBuilder();
- readableToIndexed(enumMapping.stringValueToIntValue(value.toString()).toString(), bytes);
- fields.add(new SortedSetDocValuesField(sf.getName(), bytes.toBytesRef()));
- } else {
- final long bits = field.numericValue().intValue();
- fields.add(new NumericDocValuesField(sf.getName(), bits));
- }
- return fields;
- } else {
- return Collections.singletonList(createField(sf, value));
- }
- }
-}
diff --git a/solr/core/src/java/org/apache/solr/schema/EnumFieldType.java b/solr/core/src/java/org/apache/solr/schema/EnumFieldType.java
index 7e290a434f4..47aaf472d46 100644
--- a/solr/core/src/java/org/apache/solr/schema/EnumFieldType.java
+++ b/solr/core/src/java/org/apache/solr/schema/EnumFieldType.java
@@ -17,16 +17,25 @@
package org.apache.solr.schema;
+import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.SortedNumericDocValuesField;
import org.apache.lucene.document.StoredValue;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.valuesource.EnumFieldSource;
import org.apache.lucene.queries.function.valuesource.MultiValuedIntFieldSource;
import org.apache.lucene.search.ConstantScoreQuery;
import org.apache.lucene.search.Query;
@@ -40,14 +49,210 @@ import org.apache.lucene.util.CharsRefBuilder;
import org.apache.lucene.util.NumericUtils;
import org.apache.solr.common.EnumFieldValue;
import org.apache.solr.common.SolrException;
+import org.apache.solr.core.SolrResourceLoader;
+import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.search.QParser;
import org.apache.solr.uninverting.UninvertingReader.Type;
+import org.apache.solr.util.SafeXMLParsing;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
-/** Field type for support of string values with custom sort order. */
-public class EnumFieldType extends AbstractEnumField {
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+/** Field type supporting string values with custom sort order. */
+public class EnumFieldType extends PrimitiveFieldType {
+ protected EnumMapping enumMapping;
+
+ @Override
+ protected void init(IndexSchema schema, Map<String, String> args) {
+ super.init(schema, args);
+ enumMapping = new EnumMapping(schema, this, args);
+ }
+
+ public EnumMapping getEnumMapping() {
+ return enumMapping;
+ }
+
+ /**
+ * Models all the info contained in an enums config XML file
+ *
+ * @lucene.internal
+ */
+ public static final class EnumMapping {
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ public static final String PARAM_ENUMS_CONFIG = "enumsConfig";
+ public static final String PARAM_ENUM_NAME = "enumName";
+ public static final Integer DEFAULT_VALUE = -1;
+
+ public final Map<String, Integer> enumStringToIntMap;
+ public final Map<Integer, String> enumIntToStringMap;
+
+ private final String enumsConfigFile;
+ private final String enumName;
+
+ /**
+ * Takes in a FieldType and the initArgs Map used for that type, removing the keys that specify
+ * the enum.
+ *
+ * @param schema for opening resources
+ * @param fieldType Used for logging or error messages
+ * @param args the init args to consume the enum name + config file from
+ */
+ public EnumMapping(IndexSchema schema, FieldType fieldType, Map<String, String> args) {
+ final String ftName = fieldType.getTypeName();
+
+ // NOTE: ghosting member variables for most of constructor
+ final Map<String, Integer> enumStringToIntMap = new HashMap<>();
+ final Map<Integer, String> enumIntToStringMap = new HashMap<>();
+
+ enumsConfigFile = args.get(PARAM_ENUMS_CONFIG);
+ if (enumsConfigFile == null) {
+ throw new SolrException(
+ SolrException.ErrorCode.NOT_FOUND, ftName + ": No enums config file was configured.");
+ }
+ enumName = args.get(PARAM_ENUM_NAME);
+ if (enumName == null) {
+ throw new SolrException(
+ SolrException.ErrorCode.NOT_FOUND, ftName + ": No enum name was configured.");
+ }
+
+ final SolrResourceLoader loader = schema.getResourceLoader();
+ try {
+ log.debug("Reloading enums config file from {}", enumsConfigFile);
+ Document doc = SafeXMLParsing.parseConfigXML(log, loader, enumsConfigFile);
+ final XPathFactory xpathFactory = XPathFactory.newInstance();
+ final XPath xpath = xpathFactory.newXPath();
+ final String xpathStr =
+ String.format(Locale.ROOT, "/enumsConfig/enum[@name='%s']", enumName);
+ final NodeList nodes = (NodeList) xpath.evaluate(xpathStr, doc, XPathConstants.NODESET);
+ final int nodesLength = nodes.getLength();
+ if (nodesLength == 0) {
+ String exceptionMessage =
+ String.format(
+ Locale.ENGLISH,
+ "%s: No enum configuration found for enum '%s' in %s.",
+ ftName,
+ enumName,
+ enumsConfigFile);
+ throw new SolrException(SolrException.ErrorCode.NOT_FOUND, exceptionMessage);
+ }
+ if (nodesLength > 1) {
+ log.warn(
+ "{}: More than one enum configuration found for enum '{}' in {}. The last one was taken.",
+ ftName,
+ enumName,
+ enumsConfigFile);
+ }
+ final Node enumNode = nodes.item(nodesLength - 1);
+ final NodeList valueNodes =
+ (NodeList) xpath.evaluate("value", enumNode, XPathConstants.NODESET);
+ for (int i = 0; i < valueNodes.getLength(); i++) {
+ final Node valueNode = valueNodes.item(i);
+ final String valueStr = valueNode.getTextContent();
+ if ((valueStr == null) || (valueStr.length() == 0)) {
+ final String exceptionMessage =
+ String.format(
+ Locale.ENGLISH,
+ "%s: A value was defined with an no value in enum '%s' in %s.",
+ ftName,
+ enumName,
+ enumsConfigFile);
+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, exceptionMessage);
+ }
+ if (enumStringToIntMap.containsKey(valueStr)) {
+ final String exceptionMessage =
+ String.format(
+ Locale.ENGLISH,
+ "%s: A duplicated definition was found for value '%s' in enum '%s' in %s.",
+ ftName,
+ valueStr,
+ enumName,
+ enumsConfigFile);
+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, exceptionMessage);
+ }
+ enumIntToStringMap.put(i, valueStr);
+ enumStringToIntMap.put(valueStr, i);
+ }
+ } catch (IOException | SAXException | XPathExpressionException e) {
+ throw new SolrException(
+ SolrException.ErrorCode.BAD_REQUEST, ftName + ": Error while parsing enums config.", e);
+ }
+
+ if ((enumStringToIntMap.size() == 0) || (enumIntToStringMap.size() == 0)) {
+ String exceptionMessage =
+ String.format(
+ Locale.ENGLISH,
+ "%s: Invalid configuration was defined for enum '%s' in %s.",
+ ftName,
+ enumName,
+ enumsConfigFile);
+ throw new SolrException(SolrException.ErrorCode.NOT_FOUND, exceptionMessage);
+ }
+
+ this.enumStringToIntMap = Collections.unmodifiableMap(enumStringToIntMap);
+ this.enumIntToStringMap = Collections.unmodifiableMap(enumIntToStringMap);
+
+ args.remove(PARAM_ENUMS_CONFIG);
+ args.remove(PARAM_ENUM_NAME);
+ }
+
+ /**
+ * Converting the (internal) integer value (indicating the sort order) to string (displayed)
+ * value
+ *
+ * @param intVal integer value
+ * @return string value
+ */
+ public String intValueToStringValue(Integer intVal) {
+ if (intVal == null) return null;
+
+ final String enumString = enumIntToStringMap.get(intVal);
+ if (enumString != null) return enumString;
+ // can't find matching enum name - return DEFAULT_VALUE.toString()
+ return DEFAULT_VALUE.toString();
+ }
+
+ /**
+ * Converting the string (displayed) value (internal) to integer value (indicating the sort
+ * order)
+ *
+ * @param stringVal string value
+ * @return integer value
+ */
+ public Integer stringValueToIntValue(String stringVal) {
+ if (stringVal == null) return null;
+
+ Integer intValue;
+ final Integer enumInt = enumStringToIntMap.get(stringVal);
+ if (enumInt != null) { // enum int found for string
+ return enumInt;
+ }
+
+ // enum int not found for string
+ intValue = tryParseInt(stringVal);
+ if (intValue == null) { // not Integer
+ intValue = DEFAULT_VALUE;
+ }
+ final String enumString = enumIntToStringMap.get(intValue);
+ if (enumString != null) { // has matching string
+ return intValue;
+ }
+
+ return DEFAULT_VALUE;
+ }
+
+ private static Integer tryParseInt(String valueStr) {
+ Integer intValue = null;
+ try {
+ intValue = Integer.parseInt(valueStr);
+ } catch (NumberFormatException ignore) {
+ }
+ return intValue;
+ }
+ }
@Override
public Type getUninversionType(SchemaField sf) {
@@ -141,6 +346,18 @@ public class EnumFieldType extends AbstractEnumField {
return new EnumFieldValue(intValue, stringValue);
}
+ @Override
+ public EnumFieldValue toObject(IndexableField f) {
+ Integer intValue = null;
+ String stringValue = null;
+ final Number val = f.numericValue();
+ if (val != null) {
+ intValue = val.intValue();
+ stringValue = enumMapping.intValueToStringValue(intValue);
+ }
+ return new EnumFieldValue(intValue, stringValue);
+ }
+
@Override
public String storedToIndexed(IndexableField f) {
final Number val = f.numericValue();
@@ -239,4 +456,78 @@ public class EnumFieldType extends AbstractEnumField {
}
return result;
}
+
+ @Override
+ public ValueSource getValueSource(SchemaField field, QParser qparser) {
+ field.checkFieldCacheSource();
+ return new EnumFieldSource(
+ field.getName(), enumMapping.enumIntToStringMap, enumMapping.enumStringToIntMap);
+ }
+
+ @Override
+ public void write(TextResponseWriter writer, String name, IndexableField f) throws IOException {
+ final Number val = f.numericValue();
+ if (val == null) {
+ writer.writeNull(name);
+ return;
+ }
+
+ final String readableValue = enumMapping.intValueToStringValue(val.intValue());
+ writer.writeStr(name, readableValue, true);
+ }
+
+ @Override
+ public boolean isTokenized() {
+ return false;
+ }
+
+ @Override
+ public NumberType getNumberType() {
+ return NumberType.INTEGER;
+ }
+
+ @Override
+ public String readableToIndexed(String val) {
+ if (val == null) return null;
+
+ final BytesRefBuilder bytes = new BytesRefBuilder();
+ readableToIndexed(val, bytes);
+ return bytes.get().utf8ToString();
+ }
+
+ @Override
+ public String toInternal(String val) {
+ return readableToIndexed(val);
+ }
+
+ @Override
+ public String toExternal(IndexableField f) {
+ final Number val = f.numericValue();
+ if (val == null) return null;
+
+ return enumMapping.intValueToStringValue(val.intValue());
+ }
+
+ @Override
+ public Object toNativeType(Object val) {
+ if (val instanceof CharSequence) {
+ final String str = val.toString();
+ final Integer entry = enumMapping.enumStringToIntMap.get(str);
+ if (entry != null) {
+ return new EnumFieldValue(entry, str);
+ } else {
+ try {
+ final int num = Integer.parseInt(str);
+ return new EnumFieldValue(num, enumMapping.enumIntToStringMap.get(num));
+ } catch (NumberFormatException ignore) {
+ // Could not convert to Integer so fall through.
+ }
+ }
+ } else if (val instanceof Number) {
+ final int num = ((Number) val).intValue();
+ return new EnumFieldValue(num, enumMapping.enumIntToStringMap.get(num));
+ }
+
+ return super.toNativeType(val);
+ }
}
diff --git a/solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java b/solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java
index 2497742a112..efd382a0fce 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java
@@ -67,8 +67,8 @@ import org.apache.solr.common.SolrException;
import org.apache.solr.core.SolrConfig;
import org.apache.solr.response.DocsStreamer;
import org.apache.solr.response.ResultContext;
-import org.apache.solr.schema.AbstractEnumField;
import org.apache.solr.schema.BoolField;
+import org.apache.solr.schema.EnumFieldType;
import org.apache.solr.schema.LatLonPointSpatialField;
import org.apache.solr.schema.NumberType;
import org.apache.solr.schema.SchemaField;
@@ -716,8 +716,8 @@ public class SolrDocumentFetcher {
switch (schemaField.getType().getNumberType()) {
case INTEGER:
final int raw = (int) value;
- if (schemaField.getType() instanceof AbstractEnumField) {
- return ((AbstractEnumField) schemaField.getType())
+ if (schemaField.getType() instanceof EnumFieldType) {
+ return ((EnumFieldType) schemaField.getType())
.getEnumMapping()
.intValueToStringValue(raw);
} else {
diff --git a/solr/core/src/java/org/apache/solr/search/facet/FacetRangeProcessor.java b/solr/core/src/java/org/apache/solr/search/facet/FacetRangeProcessor.java
index 0192027055b..08b034bc0cb 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/FacetRangeProcessor.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/FacetRangeProcessor.java
@@ -31,11 +31,11 @@ import org.apache.solr.common.EnumFieldValue;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.FacetParams;
import org.apache.solr.common.util.SimpleOrderedMap;
-import org.apache.solr.schema.AbstractEnumField;
-import org.apache.solr.schema.AbstractEnumField.EnumMapping;
import org.apache.solr.schema.CurrencyFieldType;
import org.apache.solr.schema.CurrencyValue;
import org.apache.solr.schema.DateRangeField;
+import org.apache.solr.schema.EnumFieldType;
+import org.apache.solr.schema.EnumFieldType.EnumMapping;
import org.apache.solr.schema.ExchangeRateProvider;
import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.SchemaField;
@@ -170,7 +170,7 @@ class FacetRangeProcessor extends FacetProcessor<FacetRange> {
final FieldType ft = sf.getType();
if (ft.getNumberType() != null) {
- if (ft instanceof AbstractEnumField) {
+ if (ft instanceof EnumFieldType) {
return new EnumCalc(sf);
}
switch (ft.getNumberType()) {
@@ -844,7 +844,7 @@ class FacetRangeProcessor extends FacetProcessor<FacetRange> {
public EnumCalc(final SchemaField f) {
super(f);
- mapping = ((AbstractEnumField) field.getType()).getEnumMapping();
+ mapping = ((EnumFieldType) field.getType()).getEnumMapping();
}
@Override
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-enums.xml b/solr/core/src/test-files/solr/collection1/conf/schema-enums.xml
index c9067dff946..3a201fc3ea6 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema-enums.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema-enums.xml
@@ -19,7 +19,7 @@
<field name="id" type="string" indexed="true" stored="true" required="true"/>
<field name="_version_" type="long" indexed="true" stored="true" multiValued="false"/>
- <!-- Test EnumField and EnumFieldType -->
+ <!-- Test EnumFieldType -->
<field name="severity" type="severityType" indexed="${solr.tests.EnumFieldTest.indexed}" stored="true" multiValued="false" docValues="${solr.tests.numeric.dv}" uninvertible="${solr.tests.EnumFieldTest.indexed}"/>
<!-- NOTE: because these test sortMissingLast/sortMissingFirst, we force indexed="true" so we don't get
random errors on schema init about inconsistent properties -->
@@ -42,7 +42,7 @@
</fieldType>
<!-- note: you cannot change the order/existing values in enum without reindexing.
but you can always add new values to the end. -->
- <fieldType name="severityType" class="${solr.tests.EnumFieldType}" enumsConfig="enumsConfig.xml" enumName="severity"/>
+ <fieldType name="severityType" class="solr.EnumFieldType" enumsConfig="enumsConfig.xml" enumName="severity"/>
<fieldType name="string" class="solr.StrField"/>
<fieldType name="long" class="${solr.tests.LongFieldType}" docValues="${solr.tests.numeric.dv}" precisionStep="0" omitNorms="true" positionIncrementGap="0" uninvertible="true"/>
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-non-stored-docvalues.xml b/solr/core/src/test-files/solr/collection1/conf/schema-non-stored-docvalues.xml
index c78d388f418..aa9a3a9ea51 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema-non-stored-docvalues.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema-non-stored-docvalues.xml
@@ -26,7 +26,7 @@
<fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>
<fieldType name="string" class="solr.StrField" sortMissingLast="true"/>
<fieldType name="date" class="${solr.tests.DateFieldType}" precisionStep="0"/>
- <fieldType name="enumField" class="${solr.tests.EnumFieldType}" enumsConfig="enumsConfig.xml" enumName="severity"/>
+ <fieldType name="enumField" class="solr.EnumFieldType" docValues="true" enumsConfig="enumsConfig.xml" enumName="severity"/>
<field name="id" type="string" indexed="true" stored="true" multiValued="false" required="false"/>
@@ -69,6 +69,3 @@
<uniqueKey>id</uniqueKey>
</schema>
-
-
-
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-sorts.xml b/solr/core/src/test-files/solr/collection1/conf/schema-sorts.xml
index 01fc7e8792d..8f63a7541c3 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema-sorts.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema-sorts.xml
@@ -306,13 +306,13 @@ NOTE: Tests expect every field in this schema to be sortable.
<fieldType name="bool_last" class="solr.BoolField" stored="true" indexed="true" sortMissingLast="true"/>
<fieldType name="bool_first" class="solr.BoolField" stored="true" indexed="true" sortMissingFirst="true"/>
- <fieldType name="enum" class="solr.EnumField" enumsConfig="enumsConfig.xml" enumName="severity"/>
- <fieldType name="enum_last" class="solr.EnumField" enumsConfig="enumsConfig.xml" enumName="severity"
+ <fieldType name="enum" class="solr.EnumFieldType" docValues="true" enumsConfig="enumsConfig.xml" enumName="severity"/>
+ <fieldType name="enum_last" class="solr.EnumFieldType" docValues="true" enumsConfig="enumsConfig.xml" enumName="severity"
sortMissingLast="true"/>
- <fieldType name="enum_first" class="solr.EnumField" enumsConfig="enumsConfig.xml" enumName="severity"
+ <fieldType name="enum_first" class="solr.EnumFieldType" docValues="true" enumsConfig="enumsConfig.xml" enumName="severity"
sortMissingFirst="true"/>
- <fieldType name="enum_dv" class="${solr.tests.EnumFieldType}" enumsConfig="enumsConfig.xml" enumName="severity" docValues="true"/>
- <fieldType name="enum_dv_last" class="${solr.tests.EnumFieldType}" enumsConfig="enumsConfig.xml" enumName="severity" docValues="true" sortMissingLast="true"/>
- <fieldType name="enum_dv_first" class="${solr.tests.EnumFieldType}" enumsConfig="enumsConfig.xml" enumName="severity" docValues="true" sortMissingFirst="true"/>
+ <fieldType name="enum_dv" class="solr.EnumFieldType" docValues="true" enumsConfig="enumsConfig.xml" enumName="severity"/>
+ <fieldType name="enum_dv_last" class="solr.EnumFieldType" docValues="true" enumsConfig="enumsConfig.xml" enumName="severity" sortMissingLast="true"/>
+ <fieldType name="enum_dv_first" class="solr.EnumFieldType" docValues="true" enumsConfig="enumsConfig.xml" enumName="severity" sortMissingFirst="true"/>
</schema>
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-vector-catchall.xml b/solr/core/src/test-files/solr/collection1/conf/schema-vector-catchall.xml
index f7031ce3f85..37bb2b98557 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema-vector-catchall.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema-vector-catchall.xml
@@ -504,9 +504,7 @@
</analyzer>
</fieldType>
<copyField source="*_commongrams" dest="*_commongrams_stop" />
-
- <fieldType name="severityType" class="${solr.tests.EnumFieldType}" enumsConfig="enumsConfig.xml" enumName="severity"/>
-
+
<fieldType name="binary" class="solr.BinaryField" />
<fieldType name="collation" class="solr.CollationField" language="en" />
<fieldType name="icuCollation" class="solr.ICUCollationField" locale="en" />
@@ -667,9 +665,6 @@
<field name="sortabuse_not_uninvertible" type="string" indexed="true" multiValued="false" uninvertible="false" />
- <!-- EnumType -->
- <field name="severity" type="severityType" docValues="true" indexed="true" stored="true" multiValued="false"/>
-
<field name="max_chars" type="string" indexed="false" stored="true"/>
<field name="no_max_chars" type="string" indexed="false" stored="true"/>
<field name="large_max_chars" type="string" indexed="false" stored="true"/>
@@ -764,8 +759,6 @@
<dynamicField name="*_ancestor" type="ancestor_path" indexed="true" stored="true" omitNorms="true"
multiValued="true"/>
- <dynamicField name="*_sev_enum" type="severityType" indexed="true" stored="true" docValues="true" multiValued="true"/>
-
<!-- With DocValues=true -->
<dynamicField name="*_i_dv" type="int" indexed="true" stored="true" docValues="true"/>
<dynamicField name="*_l_dv" type="long" indexed="true" stored="true" docValues="true"/>
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema.xml b/solr/core/src/test-files/solr/collection1/conf/schema.xml
index 49470766818..5e4ba701336 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema.xml
@@ -520,7 +520,7 @@
</fieldType>
<copyField source="*_commongrams" dest="*_commongrams_stop" />
- <fieldType name="severityType" class="${solr.tests.EnumFieldType}" enumsConfig="enumsConfig.xml" enumName="severity"/>
+ <fieldType name="severityType" class="solr.EnumFieldType" enumsConfig="enumsConfig.xml" enumName="severity"/>
<fieldType name="binary" class="solr.BinaryField" />
<fieldType name="collation" class="solr.CollationField" language="en" />
@@ -689,7 +689,7 @@
<!-- EnumType -->
<field name="severity" type="severityType" docValues="true" indexed="true" stored="true" multiValued="false"/>
-
+
<field name="max_chars" type="string" indexed="false" stored="true"/>
<field name="no_max_chars" type="string" indexed="false" stored="true"/>
<field name="large_max_chars" type="string" indexed="false" stored="true"/>
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema11.xml b/solr/core/src/test-files/solr/collection1/conf/schema11.xml
index a974e7e5579..434711d301e 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema11.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema11.xml
@@ -243,10 +243,9 @@
<filter class="solr.LengthFilterFactory" min="2" max="32768"/>
</analyzer>
</fieldType>
-
-
+
<!-- Enum type -->
- <fieldType name="severityType" class="${solr.tests.EnumFieldType}" enumsConfig="enumsConfig.xml" enumName="severity"/>
+ <fieldType name="severityType" class="solr.EnumFieldType" enumsConfig="enumsConfig.xml" enumName="severity"/>
<!-- Valid attributes for fields:
name: mandatory - the name for the field
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema_latest.xml b/solr/core/src/test-files/solr/collection1/conf/schema_latest.xml
index fcd25960ec6..c5fe34b92bb 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema_latest.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema_latest.xml
@@ -732,7 +732,6 @@
-->
<fieldType name="currency" class="solr.CurrencyFieldType" amountLongSuffix="_l_ns" codeStrSuffix="_s_ns" defaultCurrency="USD"
currencyConfig="currency.xml"/>
-
<fieldType name="severityType" class="solr.EnumFieldType" enumsConfig="enumsConfig.xml" enumName="severity"/>
<field name="severity_mv" type="severityType" indexed="true" stored="true" multiValued="true" docValues="true" />
diff --git a/solr/core/src/test/org/apache/solr/schema/EnumFieldTest.java b/solr/core/src/test/org/apache/solr/schema/EnumFieldTest.java
index c6ec5772899..4bf3f14b8b1 100644
--- a/solr/core/src/test/org/apache/solr/schema/EnumFieldTest.java
+++ b/solr/core/src/test/org/apache/solr/schema/EnumFieldTest.java
@@ -20,8 +20,6 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.EnumFieldValue;
import org.apache.solr.common.SolrException;
@@ -43,13 +41,6 @@ public class EnumFieldTest extends SolrTestCaseJ4 {
System.setProperty(
"solr.tests.EnumFieldTest.indexed", Boolean.toString(random().nextBoolean()));
doInitCore();
-
- // System.out.println("solr.tests.numeric.dv: " +
- // System.getProperty("solr.tests.numeric.dv"));
- // System.out.println("solr.tests.EnumFieldTest.indexed: " +
- // System.getProperty("solr.tests.EnumFieldTest.indexed"));
- // System.out.println("solr.tests.EnumFieldType: " +
- // System.getProperty("solr.tests.EnumFieldType"));
}
private static void doInitCore() throws Exception {
@@ -60,8 +51,7 @@ public class EnumFieldTest extends SolrTestCaseJ4 {
public void testEnumSchema() {
assumeFalse(
"Skipping testing of EnumFieldType without docValues, which is unsupported.",
- System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumFieldType")
- && System.getProperty("solr.tests.numeric.dv").equals("false"));
+ System.getProperty("solr.tests.numeric.dv").equals("false"));
IndexSchema schema = h.getCore().getLatestSchema();
@@ -75,13 +65,7 @@ public class EnumFieldTest extends SolrTestCaseJ4 {
public void testEnumRangeSearch() {
assumeFalse(
"Skipping testing of EnumFieldType without docValues, which is unsupported.",
- System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumFieldType")
- && System.getProperty("solr.tests.numeric.dv").equals("false"));
- assumeFalse(
- "Skipping testing of unindexed EnumField without docValues, which is unsupported.",
- System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumField")
- && System.getProperty("solr.tests.EnumFieldTest.indexed").equals("false")
- && System.getProperty("solr.tests.numeric.dv").equals("false"));
+ System.getProperty("solr.tests.numeric.dv").equals("false"));
clearIndex();
@@ -145,11 +129,7 @@ public class EnumFieldTest extends SolrTestCaseJ4 {
public void testMultivaluedEnumRangeSearch() {
assumeFalse(
"Skipping testing of EnumFieldType without docValues, which is unsupported.",
- System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumFieldType")
- && System.getProperty("solr.tests.numeric.dv").equals("false"));
- assumeFalse(
- "Skipping testing of range searching over multivalued EnumField - see SOLR-11193",
- System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumField"));
+ System.getProperty("solr.tests.numeric.dv").equals("false"));
clearIndex();
@@ -232,8 +212,7 @@ public class EnumFieldTest extends SolrTestCaseJ4 {
public void testBogusEnumSearch() {
assumeFalse(
"Skipping testing of EnumFieldType without docValues, which is unsupported.",
- System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumFieldType")
- && System.getProperty("solr.tests.numeric.dv").equals("false"));
+ System.getProperty("solr.tests.numeric.dv").equals("false"));
clearIndex();
@@ -261,8 +240,7 @@ public class EnumFieldTest extends SolrTestCaseJ4 {
public void testMultivaluedBogusEnumSearch() {
assumeFalse(
"Skipping testing of EnumFieldType without docValues, which is unsupported.",
- System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumFieldType")
- && System.getProperty("solr.tests.numeric.dv").equals("false"));
+ System.getProperty("solr.tests.numeric.dv").equals("false"));
clearIndex();
@@ -290,8 +268,7 @@ public class EnumFieldTest extends SolrTestCaseJ4 {
public void testBogusEnumIndexing() {
assumeFalse(
"Skipping testing of EnumFieldType without docValues, which is unsupported.",
- System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumFieldType")
- && System.getProperty("solr.tests.numeric.dv").equals("false"));
+ System.getProperty("solr.tests.numeric.dv").equals("false"));
ignoreException("Unknown value for enum field: " + FIELD_NAME + ", value: blabla");
ignoreException("Unknown value for enum field: " + FIELD_NAME + ", value: 145");
@@ -308,8 +285,7 @@ public class EnumFieldTest extends SolrTestCaseJ4 {
public void testMultivaluedBogusEnumIndexing() {
assumeFalse(
"Skipping testing of EnumFieldType without docValues, which is unsupported.",
- System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumFieldType")
- && System.getProperty("solr.tests.numeric.dv").equals("false"));
+ System.getProperty("solr.tests.numeric.dv").equals("false"));
ignoreException("Unknown value for enum field: " + MV_FIELD_NAME + ", value: blabla");
ignoreException("Unknown value for enum field: " + MV_FIELD_NAME + ", value: 145");
@@ -326,8 +302,7 @@ public class EnumFieldTest extends SolrTestCaseJ4 {
public void testKnownIntegerEnumIndexing() {
assumeFalse(
"Skipping testing of EnumFieldType without docValues, which is unsupported.",
- System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumFieldType")
- && System.getProperty("solr.tests.numeric.dv").equals("false"));
+ System.getProperty("solr.tests.numeric.dv").equals("false"));
clearIndex();
@@ -346,8 +321,7 @@ public class EnumFieldTest extends SolrTestCaseJ4 {
public void testMultivaluedKnownIntegerEnumIndexing() {
assumeFalse(
"Skipping testing of EnumFieldType without docValues, which is unsupported.",
- System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumFieldType")
- && System.getProperty("solr.tests.numeric.dv").equals("false"));
+ System.getProperty("solr.tests.numeric.dv").equals("false"));
clearIndex();
@@ -370,12 +344,10 @@ public class EnumFieldTest extends SolrTestCaseJ4 {
public void testEnumSort() {
assumeFalse(
"Skipping testing of EnumFieldType without docValues, which is unsupported.",
- System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumFieldType")
- && System.getProperty("solr.tests.numeric.dv").equals("false"));
+ System.getProperty("solr.tests.numeric.dv").equals("false"));
assumeFalse(
"Skipping testing of unindexed EnumField without docValues, which is unsupported.",
- System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumField")
- && System.getProperty("solr.tests.EnumFieldTest.indexed").equals("false")
+ System.getProperty("solr.tests.EnumFieldTest.indexed").equals("false")
&& System.getProperty("solr.tests.numeric.dv").equals("false"));
clearIndex();
@@ -442,11 +414,7 @@ public class EnumFieldTest extends SolrTestCaseJ4 {
public void testMultivaluedEnumSort() {
assumeFalse(
"Skipping testing of EnumFieldType without docValues, which is unsupported.",
- System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumFieldType")
- && System.getProperty("solr.tests.numeric.dv").equals("false"));
- assumeFalse(
- "Skipping testing of sorting over multivalued EnumField - see SOLR-11193",
- System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumField"));
+ System.getProperty("solr.tests.numeric.dv").equals("false"));
clearIndex();
assertU(adoc("id", "0", MV_FIELD_NAME, "Not Available")); // Single value
@@ -529,19 +497,17 @@ public class EnumFieldTest extends SolrTestCaseJ4 {
public void testSetQuery() {
assumeFalse(
"Skipping testing of EnumFieldType without docValues, which is unsupported.",
- System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumFieldType")
- && System.getProperty("solr.tests.numeric.dv").equals("false"));
+ System.getProperty("solr.tests.numeric.dv").equals("false"));
assumeFalse(
- "Skipping testing of unindexed EnumField without docValues, which is unsupported.",
- System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumField")
- && System.getProperty("solr.tests.EnumFieldTest.indexed").equals("false")
+ "Skipping testing of unindexed EnumFieldType without docValues, which is unsupported.",
+ System.getProperty("solr.tests.EnumFieldTest.indexed").equals("false")
&& System.getProperty("solr.tests.numeric.dv").equals("false"));
clearIndex();
SchemaField sf = h.getCore().getLatestSchema().getField(FIELD_NAME);
Set<String> enumStrs =
- ((AbstractEnumField) sf.getType()).getEnumMapping().enumStringToIntMap.keySet();
+ ((EnumFieldType) sf.getType()).getEnumMapping().enumStringToIntMap.keySet();
assertTrue(enumStrs.size() > SolrQueryParser.TERMS_QUERY_THRESHOLD);
Iterator<String> enumStrIter = enumStrs.iterator();
@@ -556,18 +522,6 @@ public class EnumFieldTest extends SolrTestCaseJ4 {
if (sf.indexed()) { // SolrQueryParser should also be generating a TermInSetQuery if indexed
String setQuery = sf.getType().getSetQuery(null, sf, enumStrs).toString();
- if (sf.getType()
- instanceof
- EnumField) { // Trie field TermInSetQuery non-XML chars serialize with "#XX;" syntax
- Pattern nonXMLCharPattern = Pattern.compile("[\u0000-\u0008\u000B\u000C\u000E-\u0019]");
- StringBuffer munged = new StringBuffer();
- Matcher matcher = nonXMLCharPattern.matcher(setQuery);
- while (matcher.find()) {
- matcher.appendReplacement(munged, "#" + (int) matcher.group(0).charAt(0) + ";");
- }
- matcher.appendTail(munged);
- setQuery = munged.toString();
- }
assertQ(
req(
CommonParams.DEBUG,
@@ -608,19 +562,17 @@ public class EnumFieldTest extends SolrTestCaseJ4 {
public void testMultivaluedSetQuery() {
assumeFalse(
"Skipping testing of EnumFieldType without docValues, which is unsupported.",
- System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumFieldType")
- && System.getProperty("solr.tests.numeric.dv").equals("false"));
+ System.getProperty("solr.tests.numeric.dv").equals("false"));
assumeFalse(
- "Skipping testing of unindexed EnumField without docValues, which is unsupported.",
- System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumField")
- && System.getProperty("solr.tests.EnumFieldTest.indexed").equals("false")
+ "Skipping testing of unindexed EnumFieldType without docValues, which is unsupported.",
+ System.getProperty("solr.tests.EnumFieldTest.indexed").equals("false")
&& System.getProperty("solr.tests.numeric.dv").equals("false"));
clearIndex();
SchemaField sf = h.getCore().getLatestSchema().getField(MV_FIELD_NAME);
Set<String> enumStrs =
- ((AbstractEnumField) sf.getType()).getEnumMapping().enumStringToIntMap.keySet();
+ ((EnumFieldType) sf.getType()).getEnumMapping().enumStringToIntMap.keySet();
assertTrue(enumStrs.size() > SolrQueryParser.TERMS_QUERY_THRESHOLD);
Iterator<String> enumStrIter = enumStrs.iterator();
@@ -638,17 +590,6 @@ public class EnumFieldTest extends SolrTestCaseJ4 {
if (sf.indexed()) { // SolrQueryParser should also be generating a TermInSetQuery if indexed
String setQuery = sf.getType().getSetQuery(null, sf, enumStrs).toString();
- // Trie field TermInSetQuery non-XML chars serialize with "#XX;" syntax
- if (sf.getType() instanceof EnumField) {
- Pattern nonXMLCharPattern = Pattern.compile("[\u0000-\u0008\u000B\u000C\u000E-\u0019]");
- StringBuffer munged = new StringBuffer();
- Matcher matcher = nonXMLCharPattern.matcher(setQuery);
- while (matcher.find()) {
- matcher.appendReplacement(munged, "#" + (int) matcher.group(0).charAt(0) + ";");
- }
- matcher.appendTail(munged);
- setQuery = munged.toString();
- }
assertQ(
req(
CommonParams.DEBUG,
@@ -689,8 +630,7 @@ public class EnumFieldTest extends SolrTestCaseJ4 {
public void testEnumFieldTypeWithoutDocValues() throws Exception {
assumeTrue(
"Only testing EnumFieldType without docValues.",
- System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumFieldType")
- && System.getProperty("solr.tests.numeric.dv").equals("false"));
+ System.getProperty("solr.tests.numeric.dv").equals("false"));
try {
deleteCore();
diff --git a/solr/solr-ref-guide/modules/indexing-guide/pages/docvalues.adoc b/solr/solr-ref-guide/modules/indexing-guide/pages/docvalues.adoc
index 34b836def78..30b138277a4 100644
--- a/solr/solr-ref-guide/modules/indexing-guide/pages/docvalues.adoc
+++ b/solr/solr-ref-guide/modules/indexing-guide/pages/docvalues.adoc
@@ -81,7 +81,7 @@ Entries are kept in sorted order and duplicates are removed.
** If the field is single-valued (i.e., multi-valued is false), Lucene will use the `NUMERIC` type.
** If the field is multi-valued, Lucene will use the `SORTED_NUMERIC` type.
Entries are kept in sorted order and duplicates are kept.
-* Any of the deprecated `Trie*` Numeric or Date fields, `EnumField` and `CurrencyField`:
+* Any of the deprecated `Trie*` Numeric or Date fields, and `CurrencyField`:
** If the field is single-valued (i.e., multi-valued is false), Lucene will use the `NUMERIC` type.
** If the field is multi-valued, Lucene will use the `SORTED_SET` type.
Entries are kept in sorted order and duplicates are removed.
diff --git a/solr/solr-ref-guide/modules/indexing-guide/pages/enum-fields.adoc b/solr/solr-ref-guide/modules/indexing-guide/pages/enum-fields.adoc
index fdb199ae5d1..6b75e9b2320 100644
--- a/solr/solr-ref-guide/modules/indexing-guide/pages/enum-fields.adoc
+++ b/solr/solr-ref-guide/modules/indexing-guide/pages/enum-fields.adoc
@@ -19,12 +19,6 @@
The EnumFieldType allows defining a field whose values are a closed set, and the sort order is pre-determined but is not alphabetic nor numeric.
Examples of this are severity lists, or risk definitions.
-.EnumField has been Deprecated
-[WARNING]
-====
-EnumField has been deprecated in favor of EnumFieldType; all configuration examples below use EnumFieldType.
-====
-
== Defining an EnumFieldType in the Schema
The EnumFieldType type definition is quite simple, as in this example defining field types for "priorityLevel" and "riskLevel" enumerations:
diff --git a/solr/solr-ref-guide/modules/indexing-guide/pages/field-types-included-with-solr.adoc b/solr/solr-ref-guide/modules/indexing-guide/pages/field-types-included-with-solr.adoc
index 101e391f7ae..e7f42d8ec45 100644
--- a/solr/solr-ref-guide/modules/indexing-guide/pages/field-types-included-with-solr.adoc
+++ b/solr/solr-ref-guide/modules/indexing-guide/pages/field-types-included-with-solr.adoc
@@ -73,7 +73,7 @@ Configuration and usage of PreAnalyzedField is documented in the section xref:e
|SpatialRecursivePrefixTreeFieldType |(RPT for short) Accepts latitude comma longitude strings or other shapes in WKT format. See xref:query-guide:spatial-search.adoc[] for more information.
-|StrField |String (UTF-8 encoded string or Unicode). Indexed `indexed="true"` strings are intended for small fields and are _not_ tokenized or analyzed in any way. They have a hard limit of slightly less than 32K. Non-indexed `indexed="false"` and non-DocValues `docValues="false"` strings are suitable for storing large strings.
+|StrField |String (UTF-8 encoded string or Unicode). Indexed `indexed="true"` strings are intended for small fields and are _not_ tokenized or analyzed in any way. They have a hard limit of slightly less than 32K. Non-indexed `indexed="false"` and non-DocValues `docValues="false"` strings are suitable for storing large strings.
|TextField |Text, usually multiple words or tokens. In normal usage, only fields of type TextField or SortableTextField will specify an xref:analyzers.adoc[analyzer].
@@ -93,6 +93,8 @@ This shortcoming may be addressed in a future release.
|===
|Class |Description
+|CurrencyField |Use CurrencyFieldType instead.
+
|EnumField |Use EnumFieldType instead.
|TrieDateField |Use DatePointField instead.
diff --git a/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-10.adoc b/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-10.adoc
index 3c69e27773c..2740511a1b8 100644
--- a/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-10.adoc
+++ b/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-10.adoc
@@ -114,9 +114,12 @@ Users who that don't need to vary JAR access on a per-core basis have several op
* The `addHttpRequestToContext` option in `solrconfig.xml` has been removed; it's obsolete.
Nowadays, the HTTP request is available via internal APIs: `SolrQueryRequest.getHttpSolrCall().getReq()`.
+* EnumField has been removed. Users should migrate to the `EnumFieldType` implementation.
+
+
=== Security
* There is no longer a distinction between trusted and untrusted configSets; all configSets are now considered trusted. To ensure security, Solr should be properly protected using authentication and authorization mechanisms, allowing only authorized users with administrative privileges to publish them.
=== Upgrade to Jetty 12.x
-Solr upgraded to Jetty 12.x from 10.x as Jetty 10 and 11 have reached end-of-life support. Jetty 12.x requires Java 17 or newer and is fully compatible with Solr's new minimum requirement of Java 21. This upgrade brings support for modern HTTP protocols and adopts the Jakarta EE 10 namespace. For more details, see https://webtide.com/jetty-12-has-arrived/.
\ No newline at end of file
+Solr upgraded to Jetty 12.x from 10.x as Jetty 10 and 11 have reached end-of-life support. Jetty 12.x requires Java 17 or newer and is fully compatible with Solr's new minimum requirement of Java 21. This upgrade brings support for modern HTTP protocols and adopts the Jakarta EE 10 namespace. For more details, see https://webtide.com/jetty-12-has-arrived/.
diff --git a/solr/test-framework/src/test-files/solr/collection1/conf/schema.xml b/solr/test-framework/src/test-files/solr/collection1/conf/schema.xml
index 7728826d311..02a57b65445 100644
--- a/solr/test-framework/src/test-files/solr/collection1/conf/schema.xml
+++ b/solr/test-framework/src/test-files/solr/collection1/conf/schema.xml
@@ -520,8 +520,7 @@
</fieldType>
<copyField source="*_commongrams" dest="*_commongrams_stop" />
- <fieldType name="severityType" class="${solr.tests.EnumFieldType}" enumsConfig="enumsConfig.xml" enumName="severity"/>
-
+ <fieldType name="severityType" class="solr.EnumFieldType" docValues="true" enumsConfig="enumsConfig.xml" enumName="severity"/>
<fieldType name="binary" class="solr.BinaryField" />
<fieldType name="collation" class="solr.CollationField" language="en" />
<fieldType name="icuCollation" class="solr.ICUCollationField" locale="en" />