Search in sources :

Example 1 with AnalysisRegistry

use of org.elasticsearch.index.analysis.AnalysisRegistry in project elasticsearch by elastic.

the class ESTestCase method createTestAnalysis.

/**
     * Creates an TestAnalysis with all the default analyzers configured.
     */
public static TestAnalysis createTestAnalysis(IndexSettings indexSettings, Settings nodeSettings, AnalysisPlugin... analysisPlugins) throws IOException {
    Environment env = new Environment(nodeSettings);
    AnalysisModule analysisModule = new AnalysisModule(env, Arrays.asList(analysisPlugins));
    AnalysisRegistry analysisRegistry = analysisModule.getAnalysisRegistry();
    return new TestAnalysis(analysisRegistry.build(indexSettings), analysisRegistry.buildTokenFilterFactories(indexSettings), analysisRegistry.buildTokenizerFactories(indexSettings), analysisRegistry.buildCharFilterFactories(indexSettings));
}
Also used : AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) Environment(org.elasticsearch.env.Environment) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) AnalysisModule(org.elasticsearch.indices.analysis.AnalysisModule)

Example 2 with AnalysisRegistry

use of org.elasticsearch.index.analysis.AnalysisRegistry in project elasticsearch by elastic.

the class IndexModuleTests method testSetupUnknownSimilarity.

public void testSetupUnknownSimilarity() throws IOException {
    Settings indexSettings = Settings.builder().put("index.similarity.my_similarity.type", "test_similarity").put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
    IndexModule module = new IndexModule(IndexSettingsModule.newIndexSettings("foo", indexSettings), new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
    Exception ex = expectThrows(IllegalArgumentException.class, () -> newIndexService(module));
    assertEquals("Unknown Similarity type [test_similarity] for [my_similarity]", ex.getMessage());
}
Also used : AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) Settings(org.elasticsearch.common.settings.Settings) ScriptSettings(org.elasticsearch.script.ScriptSettings) AlreadySetException(org.apache.lucene.util.SetOnce.AlreadySetException) EngineException(org.elasticsearch.index.engine.EngineException) IOException(java.io.IOException)

Example 3 with AnalysisRegistry

use of org.elasticsearch.index.analysis.AnalysisRegistry in project elasticsearch by elastic.

the class IndexModuleTests method testWrapperIsBound.

public void testWrapperIsBound() throws IOException {
    IndexModule module = new IndexModule(indexSettings, new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
    module.setSearcherWrapper((s) -> new Wrapper());
    module.engineFactory.set(new MockEngineFactory(AssertingDirectoryReader.class));
    IndexService indexService = newIndexService(module);
    assertTrue(indexService.getSearcherWrapper() instanceof Wrapper);
    assertSame(indexService.getEngineFactory(), module.engineFactory.get());
    indexService.close("simon says", false);
}
Also used : AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) IndexSearcherWrapper(org.elasticsearch.index.shard.IndexSearcherWrapper) MockEngineFactory(org.elasticsearch.test.engine.MockEngineFactory) AssertingDirectoryReader(org.apache.lucene.index.AssertingDirectoryReader)

Example 4 with AnalysisRegistry

use of org.elasticsearch.index.analysis.AnalysisRegistry in project elasticsearch by elastic.

the class IndexModuleTests method testOtherServiceBound.

public void testOtherServiceBound() throws IOException {
    final AtomicBoolean atomicBoolean = new AtomicBoolean(false);
    final IndexEventListener eventListener = new IndexEventListener() {

        @Override
        public void beforeIndexRemoved(IndexService indexService, IndexRemovalReason reason) {
            atomicBoolean.set(true);
        }
    };
    IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings);
    IndexModule module = new IndexModule(indexSettings, new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
    module.addIndexEventListener(eventListener);
    IndexService indexService = newIndexService(module);
    IndexSettings x = indexService.getIndexSettings();
    assertEquals(x.getSettings().getAsMap(), indexSettings.getSettings().getAsMap());
    assertEquals(x.getIndex(), index);
    indexService.getIndexEventListener().beforeIndexRemoved(null, null);
    assertTrue(atomicBoolean.get());
    indexService.close("simon says", false);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) IndexRemovalReason(org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason)

Example 5 with AnalysisRegistry

use of org.elasticsearch.index.analysis.AnalysisRegistry in project elasticsearch by elastic.

the class IndexModuleTests method testFrozen.

public void testFrozen() {
    IndexModule module = new IndexModule(IndexSettingsModule.newIndexSettings(index, settings), new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
    module.freeze();
    String msg = "Can't modify IndexModule once the index service has been created";
    assertEquals(msg, expectThrows(IllegalStateException.class, () -> module.addSearchOperationListener(null)).getMessage());
    assertEquals(msg, expectThrows(IllegalStateException.class, () -> module.addIndexEventListener(null)).getMessage());
    assertEquals(msg, expectThrows(IllegalStateException.class, () -> module.addIndexOperationListener(null)).getMessage());
    assertEquals(msg, expectThrows(IllegalStateException.class, () -> module.addSimilarity(null, null)).getMessage());
    assertEquals(msg, expectThrows(IllegalStateException.class, () -> module.setSearcherWrapper(null)).getMessage());
    assertEquals(msg, expectThrows(IllegalStateException.class, () -> module.forceQueryCacheProvider(null)).getMessage());
    assertEquals(msg, expectThrows(IllegalStateException.class, () -> module.addIndexStore("foo", null)).getMessage());
}
Also used : AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry)

Aggregations

AnalysisRegistry (org.elasticsearch.index.analysis.AnalysisRegistry)21 Settings (org.elasticsearch.common.settings.Settings)13 ScriptSettings (org.elasticsearch.script.ScriptSettings)7 IndexSettings (org.elasticsearch.index.IndexSettings)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 IOException (java.io.IOException)4 IndexAnalyzers (org.elasticsearch.index.analysis.IndexAnalyzers)4 AlreadySetException (org.apache.lucene.util.SetOnce.AlreadySetException)3 EngineException (org.elasticsearch.index.engine.EngineException)3 AssertingDirectoryReader (org.apache.lucene.index.AssertingDirectoryReader)2 Term (org.apache.lucene.index.Term)2 BM25Similarity (org.apache.lucene.search.similarities.BM25Similarity)2 Similarity (org.apache.lucene.search.similarities.Similarity)2 Environment (org.elasticsearch.env.Environment)2 NamedAnalyzer (org.elasticsearch.index.analysis.NamedAnalyzer)2 DisabledQueryCache (org.elasticsearch.index.cache.query.DisabledQueryCache)2 Engine (org.elasticsearch.index.engine.Engine)2 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)2 IndexingOperationListener (org.elasticsearch.index.shard.IndexingOperationListener)2 ShardId (org.elasticsearch.index.shard.ShardId)2