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.
/*
* Copyright 2012-2024 CodeLibs Project and the Others.
*
* Licensed 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.codelibs.fess.suggest.settings;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.codelibs.core.lang.StringUtil;
import org.codelibs.fess.suggest.exception.SuggestSettingsException;
import org.codelibs.fess.suggest.exception.SuggesterException;
import org.opensearch.action.get.GetResponse;
import org.opensearch.client.Client;
import org.opensearch.common.collect.Tuple;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.index.IndexNotFoundException;
public class SuggestSettings {
private static final Logger logger = LogManager.getLogger(SuggestSettings.class);
protected final String settingsId;
protected final Client client;
protected final String settingsIndexName;
protected final Map initialSettings;
protected boolean initialized = false;
protected final String badWordIndexName;
protected final String elevateWordIndexName;
protected TimeoutSettings timeoutSettings;
public static class TimeoutSettings {
protected String searchTimeout = "15s";
protected String indexTimeout = "1m";
protected String bulkTimeout = "1m";
protected String indicesTimeout = "1m";
protected String clusterTimeout = "1m";
protected String scrollTimeout = "1m";
}
public SuggestSettings(final Client client, final String settingsId, final Map initialSettings,
final String settingsIndexName, final TimeoutSettings timeoutSettings) {
this.client = client;
this.settingsId = settingsId;
this.settingsIndexName = settingsIndexName;
this.initialSettings = initialSettings;
this.timeoutSettings = timeoutSettings;
badWordIndexName = settingsIndexName + "-badword";
elevateWordIndexName = settingsIndexName + "-elevateword";
}
public void init() {
if (initialized) {
return;
}
initialized = true;
initialize(initialSettings);
new AnalyzerSettings(client, this, settingsIndexName).init();
}
private void initialize(final Map initialSettings) {
boolean doIndexCreate = false;
boolean doCreate = false;
try {
final GetResponse getResponse =
client.prepareGet().setIndex(settingsIndexName).setId(settingsId).execute().actionGet(getSearchTimeout());
if (!getResponse.isExists()) {
doCreate = true;
}
} catch (final IndexNotFoundException e) {
doIndexCreate = true;
doCreate = true;
}
if (doCreate) {
if (doIndexCreate) {
try {
client.admin().indices().prepareCreate(settingsIndexName).setSettings(loadIndexSettings(), XContentType.JSON).execute()
.actionGet(getIndicesTimeout());
} catch (final IOException e) {
throw new SuggesterException(e);
}
}
final List> arraySettings = new ArrayList<>();
final Map defaultSettings = defaultSettings();
initialSettings.forEach((key, value) -> {
if (value instanceof Collection) {
@SuppressWarnings("unchecked")
final Collection