|
20 | 20 |
|
21 | 21 | import org.apache.lucene.analysis.Tokenizer;
|
22 | 22 | import org.apache.lucene.analysis.core.WhitespaceTokenizer;
|
| 23 | +import org.elasticsearch.Version; |
| 24 | +import org.elasticsearch.cluster.metadata.IndexMetaData; |
23 | 25 | import org.elasticsearch.common.settings.Settings;
|
24 | 26 | import org.elasticsearch.env.Environment;
|
| 27 | +import org.elasticsearch.env.TestEnvironment; |
| 28 | +import org.elasticsearch.index.IndexSettings; |
25 | 29 | import org.elasticsearch.index.analysis.AnalysisTestsHelper;
|
| 30 | +import org.elasticsearch.index.analysis.IndexAnalyzers; |
| 31 | +import org.elasticsearch.index.analysis.NamedAnalyzer; |
26 | 32 | import org.elasticsearch.index.analysis.TokenFilterFactory;
|
| 33 | +import org.elasticsearch.indices.analysis.AnalysisModule; |
27 | 34 | import org.elasticsearch.test.ESTestCase;
|
| 35 | +import org.elasticsearch.test.IndexSettingsModule; |
| 36 | +import org.elasticsearch.test.VersionUtils; |
28 | 37 |
|
29 | 38 | import java.io.IOException;
|
30 | 39 | import java.io.StringReader;
|
| 40 | +import java.util.Collections; |
31 | 41 |
|
32 | 42 | public class WordDelimiterGraphTokenFilterFactoryTests
|
33 | 43 | extends BaseWordDelimiterTokenFilterFactoryTestCase {
|
@@ -107,4 +117,51 @@ public void testAdjustingOffsets() throws IOException {
|
107 | 117 | assertTokenStreamContents(tokenFilter.create(tokenizer), expected, expectedStartOffsets, expectedEndOffsets, null,
|
108 | 118 | expectedIncr, expectedPosLen, null);
|
109 | 119 | }
|
| 120 | + |
| 121 | + public void testPreconfiguredFilter() throws IOException { |
| 122 | + // Before 7.3 we don't adjust offsets |
| 123 | + { |
| 124 | + Settings settings = Settings.builder() |
| 125 | + .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()) |
| 126 | + .build(); |
| 127 | + Settings indexSettings = Settings.builder() |
| 128 | + .put(IndexMetaData.SETTING_VERSION_CREATED, |
| 129 | + VersionUtils.randomVersionBetween(random(), Version.V_7_0_0, VersionUtils.getPreviousVersion(Version.V_7_3_0))) |
| 130 | + .put("index.analysis.analyzer.my_analyzer.tokenizer", "standard") |
| 131 | + .putList("index.analysis.analyzer.my_analyzer.filter", "word_delimiter_graph") |
| 132 | + .build(); |
| 133 | + IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", indexSettings); |
| 134 | + |
| 135 | + try (IndexAnalyzers indexAnalyzers = new AnalysisModule(TestEnvironment.newEnvironment(settings), |
| 136 | + Collections.singletonList(new CommonAnalysisPlugin())).getAnalysisRegistry().build(idxSettings)) { |
| 137 | + |
| 138 | + NamedAnalyzer analyzer = indexAnalyzers.get("my_analyzer"); |
| 139 | + assertNotNull(analyzer); |
| 140 | + assertAnalyzesTo(analyzer, "h100", new String[]{"h", "100"}, new int[]{ 0, 0 }, new int[]{ 4, 4 }); |
| 141 | + |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + // Afger 7.3 we do adjust offsets |
| 146 | + { |
| 147 | + Settings settings = Settings.builder() |
| 148 | + .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()) |
| 149 | + .build(); |
| 150 | + Settings indexSettings = Settings.builder() |
| 151 | + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) |
| 152 | + .put("index.analysis.analyzer.my_analyzer.tokenizer", "standard") |
| 153 | + .putList("index.analysis.analyzer.my_analyzer.filter", "word_delimiter_graph") |
| 154 | + .build(); |
| 155 | + IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", indexSettings); |
| 156 | + |
| 157 | + try (IndexAnalyzers indexAnalyzers = new AnalysisModule(TestEnvironment.newEnvironment(settings), |
| 158 | + Collections.singletonList(new CommonAnalysisPlugin())).getAnalysisRegistry().build(idxSettings)) { |
| 159 | + |
| 160 | + NamedAnalyzer analyzer = indexAnalyzers.get("my_analyzer"); |
| 161 | + assertNotNull(analyzer); |
| 162 | + assertAnalyzesTo(analyzer, "h100", new String[]{"h", "100"}, new int[]{ 0, 1 }, new int[]{ 1, 4 }); |
| 163 | + |
| 164 | + } |
| 165 | + } |
| 166 | + } |
110 | 167 | }
|
0 commit comments