|
1 | 1 | /* |
2 | | - * Copyright (c) 2017-2024 Works Applications Co., Ltd. |
| 2 | + * Copyright (c) 2017-2025 Works Applications Co., Ltd. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -29,33 +29,29 @@ class SudachiAnalyzerProvider( |
29 | 29 | analysisCache: AnalysisCacheService, |
30 | 30 | dictionaryService: DictionaryService, |
31 | 31 | indexSettings: IndexSettings, |
32 | | - env: Environment?, |
33 | | - name: String?, |
34 | | - settings: Settings? |
| 32 | + env: Environment, |
| 33 | + name: String, |
| 34 | + settings: Settings |
35 | 35 | ) : AbstractIndexAnalyzerProvider<SudachiAnalyzer>(indexSettings, env, name, settings) { |
36 | | - private val analyzer: SudachiAnalyzer |
37 | 36 |
|
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) |
55 | 44 | } |
56 | 45 |
|
57 | 46 | 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 | + ) |
59 | 55 | } |
60 | 56 |
|
61 | 57 | companion object { |
|
0 commit comments