Search in sources :

Example 81 with IndexSettings

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"));
    }
}
Also used : IndexSettings(org.opensearch.index.IndexSettings) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings) IOException(java.io.IOException)

Example 82 with IndexSettings

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"));
    }
}
Also used : IndexSettings(org.opensearch.index.IndexSettings) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings) IOException(java.io.IOException)

Example 83 with IndexSettings

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 });
}
Also used : IndexSettings(org.opensearch.index.IndexSettings) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

Example 84 with IndexSettings

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;
    });
}
Also used : IndexSettings(org.opensearch.index.IndexSettings) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

Example 85 with IndexSettings

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"));
    }
}
Also used : Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings) SearchSourceBuilder(org.opensearch.search.builder.SearchSourceBuilder) SearchResponse(org.opensearch.action.search.SearchResponse)

Aggregations

IndexSettings (org.opensearch.index.IndexSettings)195 Settings (org.opensearch.common.settings.Settings)137 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)72 IOException (java.io.IOException)39 Index (org.opensearch.index.Index)32 Matchers.containsString (org.hamcrest.Matchers.containsString)25 Version (org.opensearch.Version)23 Store (org.opensearch.index.store.Store)23 Map (java.util.Map)22 QueryShardContext (org.opensearch.index.query.QueryShardContext)22 OpenSearchException (org.opensearch.OpenSearchException)21 MapperService (org.opensearch.index.mapper.MapperService)20 ShardId (org.opensearch.index.shard.ShardId)19 HashMap (java.util.HashMap)18 ArrayList (java.util.ArrayList)17 List (java.util.List)17 IndexService (org.opensearch.index.IndexService)17 IndexShard (org.opensearch.index.shard.IndexShard)17 HashSet (java.util.HashSet)16 Query (org.apache.lucene.search.Query)16