Skip to content

Commit a756a23

Browse files
Merge pull request #164 from nomoa/require-analysis-settings-and-load-the-analyzer-lazily
Do not load the sudachi analyzer eagerly
2 parents ed2815f + 0cb3aa3 commit a756a23

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

src/main/java/com/worksap/nlp/elasticsearch/sudachi/index/SudachiAnalyzerProvider.kt

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017-2024 Works Applications Co., Ltd.
2+
* Copyright (c) 2017-2025 Works Applications Co., Ltd.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,33 +29,29 @@ class SudachiAnalyzerProvider(
2929
analysisCache: AnalysisCacheService,
3030
dictionaryService: DictionaryService,
3131
indexSettings: IndexSettings,
32-
env: Environment?,
33-
name: String?,
34-
settings: Settings?
32+
env: Environment,
33+
name: String,
34+
settings: Settings
3535
) : AbstractIndexAnalyzerProvider<SudachiAnalyzer>(indexSettings, env, name, settings) {
36-
private val analyzer: SudachiAnalyzer
3736

38-
init {
39-
val stopWords: Set<*> =
40-
parseStopWords(env, settings, SudachiAnalyzer.getDefaultStopSet(), false)
41-
val configs = ConfigAdapter(dictionaryService.anchor, settings!!, env!!)
42-
val dictionary = dictionaryService.forConfig(configs.compiled)
43-
val cache =
44-
analysisCache.analysisCache(
45-
indexSettings.index.name, configs.compiled, configs.mode, settings)
46-
analyzer =
47-
SudachiAnalyzer(
48-
dictionary,
49-
cache,
50-
configs.discardPunctuation,
51-
configs.mode,
52-
CharArraySet.copy(stopWords),
53-
SudachiAnalyzer.getDefaultStopTags(),
54-
)
37+
private val stopWords: Set<*> by lazy {
38+
parseStopWords(env, settings, SudachiAnalyzer.getDefaultStopSet(), false)
39+
}
40+
private val configs by lazy { ConfigAdapter(dictionaryService.anchor, settings, env) }
41+
private val dictionary by lazy { dictionaryService.forConfig(configs.compiled) }
42+
private val cache by lazy {
43+
analysisCache.analysisCache(indexSettings.index.name, configs.compiled, configs.mode, settings)
5544
}
5645

5746
override fun get(): SudachiAnalyzer {
58-
return analyzer
47+
return SudachiAnalyzer(
48+
dictionary,
49+
cache,
50+
configs.discardPunctuation,
51+
configs.mode,
52+
CharArraySet.copy(stopWords),
53+
SudachiAnalyzer.getDefaultStopTags(),
54+
)
5955
}
6056

6157
companion object {

0 commit comments

Comments
 (0)