Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.handler.designer;
import static org.apache.solr.common.params.CommonParams.VERSION_FIELD;
import static org.apache.solr.update.processor.ParseDateFieldUpdateProcessorFactory.validateFormatter;
import java.io.IOException;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.text.ParsePosition;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.ResolverStyle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.ManagedIndexSchema;
import org.apache.solr.schema.NumberType;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.schema.TextField;
import org.apache.solr.update.processor.ParseBooleanFieldUpdateProcessorFactory;
import org.apache.solr.update.processor.ParseDateFieldUpdateProcessorFactory;
import org.apache.solr.update.processor.ParseDoubleFieldUpdateProcessorFactory;
import org.apache.solr.update.processor.ParseLongFieldUpdateProcessorFactory;
import org.apache.solr.util.LocaleUtils;
// Just a quick hack to flush out the design, more intelligence is needed
public class DefaultSchemaSuggester implements SchemaSuggester {
private static final List DEFAULT_DATE_TIME_PATTERNS =
Arrays.asList(
"yyyy-MM-dd['T'[HH:mm[:ss[.SSS]][z",
"yyyy-MM-dd['T'[HH:mm[:ss[,SSS]][z",
"yyyy-MM-dd HH:mm[:ss[.SSS]][z",
"yyyy-MM-dd HH:mm[:ss[,SSS]][z",
"[EEE, ]dd MMM yyyy HH:mm[:ss] z",
"EEEE, dd-MMM-yy HH:mm:ss z",
"EEE MMM ppd HH:mm:ss [z ]yyyy");
private static final String FORMATS_PARAM = "format";
private static final String DEFAULT_TIME_ZONE_PARAM = "defaultTimeZone";
private static final String LOCALE_PARAM = "locale";
private static final String TRUE_VALUES_PARAM = "trueValue";
private static final String FALSE_VALUES_PARAM = "falseValue";
private static final String CASE_SENSITIVE_PARAM = "caseSensitive";
private static final String TYPE_CHANGE_ERROR =
"Failed to parse all sample values as %s for changing type for field %s to %s";
// boolean parsing
private final Set trueValues = Set.of("true");
private final Set falseValues = Set.of("false");
private final List dateTimeFormatters = new ArrayList<>();
private boolean caseSensitive = false;
@Override
public void validateTypeChange(SchemaField field, FieldType toType, List docs)
throws IOException {
final NumberType toNumType = toType.getNumberType();
if (toNumType != null) {
validateNumericTypeChange(field, toType, docs, toNumType);
}
}
protected void validateNumericTypeChange(
SchemaField field,
FieldType toType,
List docs,
final NumberType toNumType) {
// desired type is numeric, make sure all the sample values are numbers
List