|
@@ -48,6 +48,7 @@ import org.apache.lucene.analysis.sv.SwedishAnalyzer;
|
|
import org.apache.lucene.analysis.th.ThaiAnalyzer;
|
|
import org.apache.lucene.analysis.th.ThaiAnalyzer;
|
|
import org.apache.lucene.analysis.tr.TurkishAnalyzer;
|
|
import org.apache.lucene.analysis.tr.TurkishAnalyzer;
|
|
import org.apache.lucene.analysis.util.CSVUtil;
|
|
import org.apache.lucene.analysis.util.CSVUtil;
|
|
|
|
+import org.elasticsearch.ResourceNotFoundException;
|
|
import org.elasticsearch.action.support.PlainActionFuture;
|
|
import org.elasticsearch.action.support.PlainActionFuture;
|
|
import org.elasticsearch.common.Strings;
|
|
import org.elasticsearch.common.Strings;
|
|
import org.elasticsearch.common.settings.Settings;
|
|
import org.elasticsearch.common.settings.Settings;
|
|
@@ -353,10 +354,39 @@ public class Analysis {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static Reader getReaderFromIndex(String synonymsSet, SynonymsManagementAPIService synonymsManagementAPIService) {
|
|
|
|
|
|
+ public static Reader getReaderFromIndex(
|
|
|
|
+ String synonymsSet,
|
|
|
|
+ SynonymsManagementAPIService synonymsManagementAPIService,
|
|
|
|
+ boolean ignoreMissing
|
|
|
|
+ ) {
|
|
final PlainActionFuture<PagedResult<SynonymRule>> synonymsLoadingFuture = new PlainActionFuture<>();
|
|
final PlainActionFuture<PagedResult<SynonymRule>> synonymsLoadingFuture = new PlainActionFuture<>();
|
|
synonymsManagementAPIService.getSynonymSetRules(synonymsSet, synonymsLoadingFuture);
|
|
synonymsManagementAPIService.getSynonymSetRules(synonymsSet, synonymsLoadingFuture);
|
|
- PagedResult<SynonymRule> results = synonymsLoadingFuture.actionGet();
|
|
|
|
|
|
+
|
|
|
|
+ PagedResult<SynonymRule> results;
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ results = synonymsLoadingFuture.actionGet();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ if (ignoreMissing == false) {
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ boolean notFound = e instanceof ResourceNotFoundException;
|
|
|
|
+ String message = String.format(
|
|
|
|
+ Locale.ROOT,
|
|
|
|
+ "Synonyms set %s %s. Synonyms will not be applied to search results on indices that use this synonym set",
|
|
|
|
+ synonymsSet,
|
|
|
|
+ notFound ? "not found" : "could not be loaded"
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ if (notFound) {
|
|
|
|
+ logger.warn(message);
|
|
|
|
+ } else {
|
|
|
|
+ logger.error(message, e);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ results = new PagedResult<>(0, new SynonymRule[0]);
|
|
|
|
+ }
|
|
|
|
|
|
SynonymRule[] synonymRules = results.pageResults();
|
|
SynonymRule[] synonymRules = results.pageResults();
|
|
StringBuilder sb = new StringBuilder();
|
|
StringBuilder sb = new StringBuilder();
|