mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 09:28:55 -04:00
Don't extend AbstractIndexComponent in AbstractCharFilterFactory (#88125)
Same as #88113 but for AbstractCharFilterFactory.
This commit is contained in:
parent
6847c0b7f5
commit
eda1c511dd
13 changed files with 19 additions and 36 deletions
|
@ -25,7 +25,7 @@ public class HtmlStripCharFilterFactory extends AbstractCharFilterFactory {
|
|||
private final Set<String> escapedTags;
|
||||
|
||||
HtmlStripCharFilterFactory(IndexSettings indexSettings, Environment env, String name, Settings settings) {
|
||||
super(indexSettings, name);
|
||||
super(name);
|
||||
List<String> escapedTagsList = settings.getAsList("escaped_tags");
|
||||
if (escapedTagsList.size() > 0) {
|
||||
this.escapedTags = unmodifiableSet(newHashSet(escapedTagsList));
|
||||
|
|
|
@ -27,7 +27,7 @@ public class MappingCharFilterFactory extends AbstractCharFilterFactory implemen
|
|||
private final NormalizeCharMap normMap;
|
||||
|
||||
MappingCharFilterFactory(IndexSettings indexSettings, Environment env, String name, Settings settings) {
|
||||
super(indexSettings, name);
|
||||
super(name);
|
||||
|
||||
List<String> rules = Analysis.getWordList(env, settings, "mappings");
|
||||
if (rules == null) {
|
||||
|
|
|
@ -25,7 +25,7 @@ public class PatternReplaceCharFilterFactory extends AbstractCharFilterFactory i
|
|||
private final String replacement;
|
||||
|
||||
PatternReplaceCharFilterFactory(IndexSettings indexSettings, Environment env, String name, Settings settings) {
|
||||
super(indexSettings, name);
|
||||
super(name);
|
||||
|
||||
String sPattern = settings.get("pattern");
|
||||
if (Strings.hasLength(sPattern) == false) {
|
||||
|
|
|
@ -40,7 +40,7 @@ public class IcuAnalyzerProvider extends AbstractIndexAnalyzerProvider<Analyzer>
|
|||
method,
|
||||
"compose".equals(mode) ? Normalizer2.Mode.COMPOSE : Normalizer2.Mode.DECOMPOSE
|
||||
);
|
||||
this.normalizer = IcuNormalizerTokenFilterFactory.wrapWithUnicodeSetFilter(indexSettings, normalizerInstance, settings);
|
||||
this.normalizer = IcuNormalizerTokenFilterFactory.wrapWithUnicodeSetFilter(normalizerInstance, settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -39,7 +39,7 @@ public class IcuFoldingTokenFilterFactory extends AbstractTokenFilterFactory imp
|
|||
|
||||
public IcuFoldingTokenFilterFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
|
||||
super(name, settings);
|
||||
this.normalizer = IcuNormalizerTokenFilterFactory.wrapWithUnicodeSetFilter(indexSettings, ICU_FOLDING_NORMALIZER, settings);
|
||||
this.normalizer = IcuNormalizerTokenFilterFactory.wrapWithUnicodeSetFilter(ICU_FOLDING_NORMALIZER, settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -30,7 +30,7 @@ public class IcuNormalizerCharFilterFactory extends AbstractCharFilterFactory im
|
|||
private final Normalizer2 normalizer;
|
||||
|
||||
public IcuNormalizerCharFilterFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
|
||||
super(indexSettings, name);
|
||||
super(name);
|
||||
String method = settings.get("name", "nfkc_cf");
|
||||
String mode = settings.get("mode");
|
||||
if ("compose".equals(mode) == false && "decompose".equals(mode) == false) {
|
||||
|
@ -41,7 +41,7 @@ public class IcuNormalizerCharFilterFactory extends AbstractCharFilterFactory im
|
|||
method,
|
||||
"compose".equals(mode) ? Normalizer2.Mode.COMPOSE : Normalizer2.Mode.DECOMPOSE
|
||||
);
|
||||
this.normalizer = IcuNormalizerTokenFilterFactory.wrapWithUnicodeSetFilter(indexSettings, normalizerInstance, settings);
|
||||
this.normalizer = IcuNormalizerTokenFilterFactory.wrapWithUnicodeSetFilter(normalizerInstance, settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,7 +32,7 @@ public class IcuNormalizerTokenFilterFactory extends AbstractTokenFilterFactory
|
|||
super(name, settings);
|
||||
String method = settings.get("name", "nfkc_cf");
|
||||
Normalizer2 normalizerInstance = Normalizer2.getInstance(null, method, Normalizer2.Mode.COMPOSE);
|
||||
this.normalizer = wrapWithUnicodeSetFilter(indexSettings, normalizerInstance, settings);
|
||||
this.normalizer = wrapWithUnicodeSetFilter(normalizerInstance, settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -40,7 +40,7 @@ public class IcuNormalizerTokenFilterFactory extends AbstractTokenFilterFactory
|
|||
return new org.apache.lucene.analysis.icu.ICUNormalizer2Filter(tokenStream, normalizer);
|
||||
}
|
||||
|
||||
static Normalizer2 wrapWithUnicodeSetFilter(final IndexSettings indexSettings, final Normalizer2 normalizer, final Settings settings) {
|
||||
static Normalizer2 wrapWithUnicodeSetFilter(final Normalizer2 normalizer, final Settings settings) {
|
||||
String unicodeSetFilter = settings.get("unicode_set_filter");
|
||||
if (unicodeSetFilter != null) {
|
||||
UnicodeSet unicodeSet = new UnicodeSet(unicodeSetFilter);
|
||||
|
|
|
@ -13,8 +13,6 @@ import org.apache.lucene.tests.analysis.BaseTokenStreamTestCase;
|
|||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetadata;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.IndexSettings;
|
||||
import org.elasticsearch.test.IndexSettingsModule;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -24,13 +22,10 @@ public class IcuAnalyzerTests extends BaseTokenStreamTestCase {
|
|||
|
||||
public void testMixedAlphabetTokenization() throws IOException {
|
||||
|
||||
Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).build();
|
||||
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);
|
||||
|
||||
String input = "안녕은하철도999극장판2.1981년8월8일.일본개봉작1999년재더빙video판";
|
||||
|
||||
AnalysisICUPlugin plugin = new AnalysisICUPlugin();
|
||||
Analyzer analyzer = plugin.getAnalyzers().get("icu_analyzer").get(idxSettings, null, "icu", settings).get();
|
||||
Analyzer analyzer = plugin.getAnalyzers().get("icu_analyzer").get(null, null, "icu", Settings.EMPTY).get();
|
||||
assertAnalyzesTo(
|
||||
analyzer,
|
||||
input,
|
||||
|
@ -40,34 +35,26 @@ public class IcuAnalyzerTests extends BaseTokenStreamTestCase {
|
|||
}
|
||||
|
||||
public void testMiddleDots() throws IOException {
|
||||
Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).build();
|
||||
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);
|
||||
|
||||
String input = "경승지·산악·협곡·해협·곶·심연·폭포·호수·급류";
|
||||
|
||||
Analyzer analyzer = new IcuAnalyzerProvider(idxSettings, null, "icu", settings).get();
|
||||
Analyzer analyzer = new IcuAnalyzerProvider(null, null, "icu", Settings.EMPTY).get();
|
||||
assertAnalyzesTo(analyzer, input, new String[] { "경승지", "산악", "협곡", "해협", "곶", "심연", "폭포", "호수", "급류" });
|
||||
}
|
||||
|
||||
public void testUnicodeNumericCharacters() throws IOException {
|
||||
|
||||
Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).build();
|
||||
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);
|
||||
|
||||
String input = "① ② ③ ⑴ ⑵ ⑶ ¼ ⅓ ⅜ ¹ ² ³ ₁ ₂ ₃";
|
||||
|
||||
Analyzer analyzer = new IcuAnalyzerProvider(idxSettings, null, "icu", settings).get();
|
||||
Analyzer analyzer = new IcuAnalyzerProvider(null, null, "icu", Settings.EMPTY).get();
|
||||
assertAnalyzesTo(analyzer, input, new String[] { "1", "2", "3", "1", "2", "3", "1/4", "1/3", "3/8", "1", "2", "3", "1", "2", "3" });
|
||||
}
|
||||
|
||||
public void testBadSettings() {
|
||||
|
||||
Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).put("mode", "wrong").build();
|
||||
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);
|
||||
|
||||
IllegalArgumentException e = expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> { new IcuAnalyzerProvider(idxSettings, null, "icu", settings); }
|
||||
() -> new IcuAnalyzerProvider(null, null, "icu", settings)
|
||||
);
|
||||
|
||||
assertThat(e.getMessage(), containsString("Unknown mode [wrong] in analyzer [icu], expected one of [compose, decompose]"));
|
||||
|
|
|
@ -23,7 +23,7 @@ public class KuromojiIterationMarkCharFilterFactory extends AbstractCharFilterFa
|
|||
private final boolean normalizeKana;
|
||||
|
||||
public KuromojiIterationMarkCharFilterFactory(IndexSettings indexSettings, Environment env, String name, Settings settings) {
|
||||
super(indexSettings, name);
|
||||
super(name);
|
||||
normalizeKanji = settings.getAsBoolean("normalize_kanji", JapaneseIterationMarkCharFilter.NORMALIZE_KANJI_DEFAULT);
|
||||
normalizeKana = settings.getAsBoolean("normalize_kana", JapaneseIterationMarkCharFilter.NORMALIZE_KANA_DEFAULT);
|
||||
}
|
||||
|
|
|
@ -8,15 +8,11 @@
|
|||
|
||||
package org.elasticsearch.index.analysis;
|
||||
|
||||
import org.elasticsearch.index.AbstractIndexComponent;
|
||||
import org.elasticsearch.index.IndexSettings;
|
||||
|
||||
public abstract class AbstractCharFilterFactory extends AbstractIndexComponent implements CharFilterFactory {
|
||||
public abstract class AbstractCharFilterFactory implements CharFilterFactory {
|
||||
|
||||
private final String name;
|
||||
|
||||
public AbstractCharFilterFactory(IndexSettings indexSettings, String name) {
|
||||
super(indexSettings);
|
||||
public AbstractCharFilterFactory(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ public class TransportAnalyzeActionTests extends ESTestCase {
|
|||
final String suffix;
|
||||
|
||||
AppendCharFilterFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
|
||||
super(indexSettings, name);
|
||||
super(name);
|
||||
this.suffix = settings.get("suffix", "bar");
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import java.io.Reader;
|
|||
public class FirstLineWithLettersCharFilterFactory extends AbstractCharFilterFactory {
|
||||
|
||||
public FirstLineWithLettersCharFilterFactory(IndexSettings indexSettings, Environment env, String name, Settings settings) {
|
||||
super(indexSettings, name);
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,7 +17,7 @@ import java.io.Reader;
|
|||
public class FirstNonBlankLineCharFilterFactory extends AbstractCharFilterFactory {
|
||||
|
||||
public FirstNonBlankLineCharFilterFactory(IndexSettings indexSettings, Environment env, String name, Settings settings) {
|
||||
super(indexSettings, name);
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue