Skip to content

Commit

Permalink
Compile with Es8.13
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuma-t committed Apr 24, 2024
1 parent 60a790e commit 5837cc4
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 13 deletions.
9 changes: 6 additions & 3 deletions buildSrc/src/main/groovy/com/worksap/nlp/tools/engines.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ enum EsSupport implements EngineSupport {
Es78("es-7.08"),
Es715("es-7.15"),
Es80("es-8.00"),
Es83("es-8.30"),
Es84("es-8.40")
Es83("es-8.03"),
Es84("es-8.04"),
Es812("es-8.12")

String tag
List<String> keys
Expand All @@ -33,8 +34,10 @@ enum EsSupport implements EngineSupport {
return Es80
} else if (vers.ge(8, 3) && vers.lt(8, 4)) {
return Es83
} else if (vers.ge(8, 4) && vers.lt(9, 0)) {
} else if (vers.ge(8, 4) && vers.lt(8, 12)) {
return Es84
} else if (vers.ge(8, 12) && vers.lt(9, 0)) {
return Es812
} else {
throw new IllegalArgumentException("unsupported ElasticSearch version: " + vers.raw)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Works Applications Co., Ltd.
* Copyright (c) 2023-2024 Works Applications Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,6 +44,11 @@ fun SudachiInSearchEngineEnv.makePluginService(): PluginsServiceAlias {
return PluginsService(settings(), configPath, null, pluginsPath, emptyList())
}

fun SudachiInSearchEngineEnv.getPluginList(): List<AnalysisPlugin> {
val plugins = makePluginService()
return plugins.filterPlugins(AnalysisPlugin::class.java)
}

fun SudachiInSearchEngineEnv.makeAnalysisModule(): AnalysisModule {
val plugins = makePluginService()
val analysisPlugins = plugins.filterPlugins(AnalysisPlugin::class.java)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Works Applications Co., Ltd.
* Copyright (c) 2023-2024 Works Applications Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,9 +44,14 @@ fun SudachiInSearchEngineEnv.makePluginService(): PluginsServiceAlias {
return PluginsService(settings(), configPath, null, pluginsPath)
}

fun SudachiInSearchEngineEnv.getPluginList(): List<AnalysisPlugin> {
val plugins = makePluginService()
return plugins.filterPlugins(AnalysisPlugin::class.java).toList()
}

fun SudachiInSearchEngineEnv.makeAnalysisModule(): AnalysisModule {
val plugins = makePluginService()
val analysisPlugins = plugins.filterPlugins(AnalysisPlugin::class.java)
val analysisPlugins = plugins.filterPlugins(AnalysisPlugin::class.java).toList()
val env = environment()
return AnalysisModule(env, analysisPlugins, plugins.stablePluginRegistry)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2023-2024 Works Applications Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.worksap.nlp.elasticsearch.sudachi

import org.elasticsearch.action.admin.indices.analyze.AnalyzeAction
import org.elasticsearch.action.admin.indices.analyze.TransportAnalyzeAction
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.env.Environment
import org.elasticsearch.indices.analysis.AnalysisModule
import org.elasticsearch.plugins.AnalysisPlugin
import org.elasticsearch.plugins.PluginsService

typealias SearchEngineTestCase = org.elasticsearch.test.ESTestCase

typealias PluginsServiceAlias = PluginsService

typealias AnalysisRegistryAlias = org.elasticsearch.index.analysis.AnalysisRegistry

typealias EnvironmentAlias = Environment

typealias SettingsAlias = Settings

typealias AnalysisPluginAlias = AnalysisPlugin

typealias AnalyzeActionRequestAlias = AnalyzeAction.Request

typealias TransportAnalyzeActionAlias = TransportAnalyzeAction

fun SudachiInSearchEngineEnv.makePluginService(): PluginsServiceAlias {
return PluginsService(settings(), configPath, null, pluginsPath)
}

fun SudachiInSearchEngineEnv.getPluginList(): List<AnalysisPlugin> {
val plugins = makePluginService()
return plugins.filterPlugins(AnalysisPlugin::class.java)
}

fun SudachiInSearchEngineEnv.makeAnalysisModule(): AnalysisModule {
val plugins = makePluginService()
var analysisPlugins = plugins.filterPlugins(AnalysisPlugin::class.java)
val env = environment()
return AnalysisModule(env, analysisPlugins, plugins.stablePluginRegistry)
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ fun SudachiInSearchEngineEnv.makePluginService(): PluginsServiceAlias {
return PluginsService(settings(), configPath, null, pluginsPath, emptyList())
}

fun SudachiInSearchEngineEnv.getPluginList(): List<AnalysisPlugin> {
val plugins = makePluginService()
return plugins.filterPlugins(AnalysisPlugin::class.java)
}

fun SudachiInSearchEngineEnv.makeAnalysisModule(): AnalysisModule {
val plugins = makePluginService()
val analysisPlugins = plugins.filterPlugins(AnalysisPlugin::class.java)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Works Applications Co., Ltd.
* Copyright (c) 2023-2024 Works Applications Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,8 +22,7 @@ import org.junit.Test
class BasicTest : SudachiEnvTest() {
@Test
fun canLoadPlugin() {
val plugins = sudachiEnv.makePluginService()
val analysisPlugins = plugins.filterPlugins(AnalysisPluginAlias::class.java)
val analysisPlugins = sudachiEnv.getPluginList()
Assert.assertEquals(2, analysisPlugins.size)
val plugin =
analysisPlugins.find {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023 Works Applications Co., Ltd.
* Copyright (c) 2022-2024 Works Applications Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023 Works Applications Co., Ltd.
* Copyright (c) 2022-2024 Works Applications Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
42 changes: 42 additions & 0 deletions src/test/ext/es-8.12-ge/engine-aliases-test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2023-2024 Works Applications Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@file:Suppress("PackageDirectoryMismatch")

package com.worksap.nlp.search.aliases

typealias Version = org.elasticsearch.Version

typealias LogConfigurator = org.elasticsearch.common.logging.LogConfigurator

typealias TestEnvironment = org.elasticsearch.env.TestEnvironment

typealias Index = org.elasticsearch.index.Index

typealias AnalysisModule = org.elasticsearch.indices.analysis.AnalysisModule

typealias IndexSettingsModule = org.elasticsearch.test.IndexSettingsModule

typealias NamedAnalyzer = org.elasticsearch.index.analysis.NamedAnalyzer

typealias IndexAnalyzers = org.elasticsearch.index.analysis.IndexAnalyzers

typealias IndexCreationContext = org.elasticsearch.index.IndexService.IndexCreationContext

typealias AnalysisRegistry = org.elasticsearch.index.analysis.AnalysisRegistry

fun AnalysisRegistry.buildWithCreateIndex(indexSettings: IndexSettings): IndexAnalyzers =
this.build(IndexCreationContext.CREATE_INDEX, indexSettings)
21 changes: 21 additions & 0 deletions src/test/ext/es-8.12-lt/BaseTokenStreamTestCase.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2022-2024 Works Applications Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@file:Suppress("UNUSED_PARAMETER", "PackageDirectoryMismatch")

package com.worksap.nlp.lucene.sudachi.aliases

abstract class BaseTokenStreamTestCase : org.apache.lucene.tests.analysis.BaseTokenStreamTestCase()
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Works Applications Co., Ltd.
* Copyright (c) 2023-2024 Works Applications Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,3 +33,8 @@ typealias IndexSettingsModule = org.elasticsearch.test.IndexSettingsModule
typealias NamedAnalyzer = org.elasticsearch.index.analysis.NamedAnalyzer

typealias IndexAnalyzers = org.elasticsearch.index.analysis.IndexAnalyzers

typealias AnalysisRegistry = org.elasticsearch.index.analysis.AnalysisRegistry

fun AnalysisRegistry.buildWithCreateIndex(indexSettings: IndexSettings): IndexAnalyzers =
this.build(indexSettings)
5 changes: 5 additions & 0 deletions src/test/ext/os-2.00-ge/engine-aliases-test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ typealias NamedAnalyzer = org.opensearch.index.analysis.NamedAnalyzer
typealias IndexAnalyzers = org.opensearch.index.analysis.IndexAnalyzers

typealias XContentType = org.opensearch.common.xcontent.XContentType

typealias AnalysisRegistry = org.elasticsearch.index.analysis.AnalysisRegistry

fun AnalysisRegistry.buildWithCreateIndex(indexSettings: IndexSettings): IndexAnalyzers =
this.build(indexSettings)
5 changes: 5 additions & 0 deletions src/test/ext/os-2.10-ge/alias-index.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@
package com.worksap.nlp.search.aliases

typealias Index = org.opensearch.core.index.Index

typealias AnalysisRegistry = org.elasticsearch.index.analysis.AnalysisRegistry

fun AnalysisRegistry.buildWithCreateIndex(indexSettings: IndexSettings): IndexAnalyzers =
this.build(indexSettings)
5 changes: 5 additions & 0 deletions src/test/ext/os-2.10-lt/alias-index.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@
package com.worksap.nlp.search.aliases

typealias Index = org.opensearch.index.Index

typealias AnalysisRegistry = org.elasticsearch.index.analysis.AnalysisRegistry

fun AnalysisRegistry.buildWithCreateIndex(indexSettings: IndexSettings): IndexAnalyzers =
this.build(indexSettings)
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SearchEngineEnv(vararg components: String = arrayOf("system")) : ExternalR

fun indexAnalyzers(settings: Settings): IndexAnalyzers {
val indexSettings = IndexSettingsModule.newIndexSettings(Index("test", "_na_"), settings)
return analysisRegistry.build(indexSettings)
return analysisRegistry.buildWithCreateIndex(indexSettings)
}

fun tokenizers(settings: Map<String, String>): Map<String, TokenizerFactory> {
Expand Down

0 comments on commit 5837cc4

Please sign in to comment.