use of org.opensearch.index.IndexSettings in project OpenSearch by opensearch-project.
the class SynonymsAnalysisTests method testSynonymWordDeleteByAnalyzer.
public void testSynonymWordDeleteByAnalyzer() throws IOException {
Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).put("path.home", createTempDir().toString()).put("index.analysis.filter.synonym.type", "synonym").putList("index.analysis.filter.synonym.synonyms", "foobar => fred", "dude => opensearch", "abides => man!").put("index.analysis.filter.stop_within_synonym.type", "stop").putList("index.analysis.filter.stop_within_synonym.stopwords", "foobar", "opensearch").put("index.analysis.analyzer.synonymAnalyzerWithStopSynonymBeforeSynonym.tokenizer", "whitespace").putList("index.analysis.analyzer.synonymAnalyzerWithStopSynonymBeforeSynonym.filter", "stop_within_synonym", "synonym").build();
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);
try {
indexAnalyzers = createTestAnalysis(idxSettings, settings, new CommonAnalysisPlugin()).indexAnalyzers;
fail("fail! due to synonym word deleted by analyzer");
} catch (Exception e) {
assertThat(e, instanceOf(IllegalArgumentException.class));
assertThat(e.getMessage(), startsWith("failed to build synonyms"));
}
}
use of org.opensearch.index.IndexSettings in project OpenSearch by opensearch-project.
the class SynonymsAnalysisTests method testExpandSynonymWordDeleteByAnalyzer.
public void testExpandSynonymWordDeleteByAnalyzer() throws IOException {
Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).put("path.home", createTempDir().toString()).put("index.analysis.filter.synonym_expand.type", "synonym").putList("index.analysis.filter.synonym_expand.synonyms", "foobar, fred", "dude, opensearch", "abides, man!").put("index.analysis.filter.stop_within_synonym.type", "stop").putList("index.analysis.filter.stop_within_synonym.stopwords", "foobar", "opensearch").put("index.analysis.analyzer.synonymAnalyzerExpandWithStopBeforeSynonym.tokenizer", "whitespace").putList("index.analysis.analyzer.synonymAnalyzerExpandWithStopBeforeSynonym.filter", "stop_within_synonym", "synonym_expand").build();
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);
try {
indexAnalyzers = createTestAnalysis(idxSettings, settings, new CommonAnalysisPlugin()).indexAnalyzers;
fail("fail! due to synonym word deleted by analyzer");
} catch (Exception e) {
assertThat(e, instanceOf(IllegalArgumentException.class));
assertThat(e.getMessage(), startsWith("failed to build synonyms"));
}
}
use of org.opensearch.index.IndexSettings in project OpenSearch by opensearch-project.
the class SynonymsAnalysisTests method testSynonymsWrappedByMultiplexer.
public void testSynonymsWrappedByMultiplexer() throws IOException {
Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).put("path.home", createTempDir().toString()).put("index.analysis.filter.synonyms.type", "synonym").putList("index.analysis.filter.synonyms.synonyms", "programmer, developer").put("index.analysis.filter.my_english.type", "stemmer").put("index.analysis.filter.my_english.language", "porter2").put("index.analysis.filter.stem_repeat.type", "multiplexer").putList("index.analysis.filter.stem_repeat.filters", "my_english, synonyms").put("index.analysis.analyzer.synonymAnalyzer.tokenizer", "standard").putList("index.analysis.analyzer.synonymAnalyzer.filter", "lowercase", "stem_repeat").build();
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);
indexAnalyzers = createTestAnalysis(idxSettings, settings, new CommonAnalysisPlugin()).indexAnalyzers;
BaseTokenStreamTestCase.assertAnalyzesTo(indexAnalyzers.get("synonymAnalyzer"), "Some developers are odd", new String[] { "some", "developers", "develop", "programm", "are", "odd" }, new int[] { 1, 1, 0, 0, 1, 1 });
}
use of org.opensearch.index.IndexSettings in project OpenSearch by opensearch-project.
the class SynonymsAnalysisTests method testShingleFilters.
public void testShingleFilters() {
Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, VersionUtils.randomVersionBetween(random(), LegacyESVersion.V_7_0_0, Version.CURRENT)).put("path.home", createTempDir().toString()).put("index.analysis.filter.synonyms.type", "synonym").putList("index.analysis.filter.synonyms.synonyms", "programmer, developer").put("index.analysis.filter.my_shingle.type", "shingle").put("index.analysis.analyzer.my_analyzer.tokenizer", "standard").putList("index.analysis.analyzer.my_analyzer.filter", "my_shingle", "synonyms").build();
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);
expectThrows(IllegalArgumentException.class, () -> {
indexAnalyzers = createTestAnalysis(idxSettings, settings, new CommonAnalysisPlugin()).indexAnalyzers;
});
}
use of org.opensearch.index.IndexSettings in project OpenSearch by opensearch-project.
the class HighlighterWithAnalyzersTests method testSynonyms.
public void testSynonyms() throws IOException {
Settings.Builder builder = Settings.builder().put(indexSettings()).put("index.analysis.analyzer.synonym.tokenizer", "standard").putList("index.analysis.analyzer.synonym.filter", "synonym", "lowercase").put("index.analysis.filter.synonym.type", "synonym").putList("index.analysis.filter.synonym.synonyms", "fast,quick");
assertAcked(prepareCreate("test").setSettings(builder.build()).addMapping("type1", "field1", "type=text,term_vector=with_positions_offsets,search_analyzer=synonym," + "analyzer=standard,index_options=offsets"));
ensureGreen();
client().prepareIndex("test").setId("0").setSource("field1", "The quick brown fox jumps over the lazy dog").get();
refresh();
for (String highlighterType : new String[] { "plain", "fvh", "unified" }) {
logger.info("--> highlighting (type=" + highlighterType + ") and searching on field1");
SearchSourceBuilder source = searchSource().query(matchQuery("field1", "quick brown fox").operator(Operator.AND)).highlighter(highlight().field("field1").order("score").preTags("<x>").postTags("</x>").highlighterType(highlighterType));
SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet();
assertHighlight(searchResponse, 0, "field1", 0, 1, equalTo("The <x>quick</x> <x>brown</x> <x>fox</x> jumps over the lazy dog"));
source = searchSource().query(matchQuery("field1", "fast brown fox").operator(Operator.AND)).highlighter(highlight().field("field1").order("score").preTags("<x>").postTags("</x>"));
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
assertHighlight(searchResponse, 0, "field1", 0, 1, equalTo("The <x>quick</x> <x>brown</x> <x>fox</x> jumps over the lazy dog"));
}
}
Aggregations