fabriziofortino commented on code in PR #860: URL: https://github.com/apache/jackrabbit-oak/pull/860#discussion_r1127637218
########## oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticCustomAnalyzer.java: ########## @@ -0,0 +1,254 @@ +/* + * 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.jackrabbit.oak.plugins.index.elastic.index; + +import co.elastic.clients.elasticsearch._types.analysis.Analyzer; +import co.elastic.clients.elasticsearch._types.analysis.CharFilterDefinition; +import co.elastic.clients.elasticsearch._types.analysis.CustomAnalyzer; +import co.elastic.clients.elasticsearch._types.analysis.TokenFilterDefinition; +import co.elastic.clients.elasticsearch._types.analysis.TokenizerDefinition; +import co.elastic.clients.elasticsearch.indices.IndexSettingsAnalysis; +import co.elastic.clients.json.JsonData; +import com.google.common.base.CaseFormat; +import org.apache.commons.io.IOUtils; +import org.apache.jackrabbit.JcrConstants; +import org.apache.jackrabbit.oak.api.Blob; +import org.apache.jackrabbit.oak.api.Tree; +import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants; +import org.apache.jackrabbit.oak.plugins.index.search.util.ConfigUtil; +import org.apache.jackrabbit.oak.plugins.tree.factories.TreeFactory; +import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry; +import org.apache.jackrabbit.oak.spi.state.NodeState; +import org.apache.jackrabbit.oak.spi.state.NodeStateUtils; +import org.apache.lucene.analysis.charfilter.MappingCharFilterFactory; +import org.apache.lucene.analysis.en.AbstractWordsFileFilterFactory; +import org.apache.lucene.analysis.util.AbstractAnalysisFactory; +import org.apache.lucene.analysis.util.CharFilterFactory; +import org.apache.lucene.analysis.util.TokenFilterFactory; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.Spliterator; +import java.util.Spliterators; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +/** + * Loads custom analysis index settings from a JCR NodeState. It also takes care of required transformations from lucene + * to elasticsearch configuration options. + */ +public class ElasticCustomAnalyzer { + + private static final Logger LOG = LoggerFactory.getLogger(ElasticCustomAnalyzer.class); + + private static final String ANALYZER_TYPE = "type"; + + private static final Set<String> IGNORE_PROP_NAMES = new HashSet<>(Arrays.asList( + AbstractAnalysisFactory.LUCENE_MATCH_VERSION_PARAM, + FulltextIndexConstants.ANL_CLASS, + FulltextIndexConstants.ANL_NAME, + JcrConstants.JCR_PRIMARYTYPE) + ); + + /* + * Mappings for lucene options not available anymore to supported elastic counterparts + */ + private static final Map<Class<? extends AbstractAnalysisFactory>, Map<String, String>> CONFIGURATION_MAPPING; + + static { + CONFIGURATION_MAPPING = new LinkedHashMap<>(); + CONFIGURATION_MAPPING.put(AbstractWordsFileFilterFactory.class, Collections.singletonMap("words", "stopwords")); + CONFIGURATION_MAPPING.put(MappingCharFilterFactory.class, Collections.singletonMap("mapping", "mappings")); + } Review Comment: `Map.of()` was introduced in Java 9. Is it okay to include it? There is currently no use of it in the repo. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
