-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from masaruh/analyzer
Add analyzer
- Loading branch information
Showing
14 changed files
with
281 additions
and
154 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...elasticsearch/analysis/KeystrokeUtil.java → ...csearch/index/analysis/KeystrokeUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/org/elasticsearch/index/analysis/KuromojiSuggestAnalyzer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.elasticsearch.index.analysis; | ||
|
||
import org.apache.lucene.analysis.Analyzer; | ||
import org.apache.lucene.analysis.TokenStream; | ||
import org.apache.lucene.analysis.Tokenizer; | ||
import org.apache.lucene.analysis.core.LowerCaseFilter; | ||
|
||
import java.io.Reader; | ||
import java.text.Normalizer; | ||
|
||
public abstract class KuromojiSuggestAnalyzer extends Analyzer { | ||
@Override | ||
protected TokenStreamComponents createComponents(String fieldName) { | ||
Tokenizer tokenizer = createTokenizer(); | ||
TokenStream tokenStream = new LowerCaseFilter(tokenizer); | ||
return new TokenStreamComponents(tokenizer, tokenStream); | ||
} | ||
|
||
@Override | ||
protected Reader initReader(String fieldName, Reader reader) { | ||
return new UnicodeNormalizationCharFilter(reader, Normalizer.Form.NFKC, false); | ||
} | ||
|
||
protected abstract Tokenizer createTokenizer(); | ||
|
||
public static class IndexKuromojiSuggestAnalyzer extends KuromojiSuggestAnalyzer { | ||
@Override | ||
protected Tokenizer createTokenizer() { | ||
return new KuromojiSuggestTokenizer(true, 512, false); | ||
} | ||
} | ||
|
||
public static class SearchKuromojiSuggestAnalyzer extends KuromojiSuggestAnalyzer { | ||
@Override | ||
protected Tokenizer createTokenizer() { | ||
return new KuromojiSuggestTokenizer(false, 512, false); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/org/elasticsearch/index/analysis/KuromojiSuggestAnalyzerProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.elasticsearch.index.analysis; | ||
|
||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.inject.assistedinject.Assisted; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.index.settings.IndexSettingsService; | ||
|
||
public class KuromojiSuggestAnalyzerProvider extends AbstractIndexAnalyzerProvider<KuromojiSuggestAnalyzer> { | ||
public static final String INDEX_ANALYZER = "kuromoji_suggest_index"; | ||
public static final String SEARCH_ANALYZER = "kuromoji_suggest_search"; | ||
|
||
private final KuromojiSuggestAnalyzer analyzer; | ||
@Inject | ||
public KuromojiSuggestAnalyzerProvider(Index index, IndexSettingsService indexSettingsService, | ||
@Assisted String name, @Assisted Settings settings) { | ||
super(index, indexSettingsService.indexSettings(), name, settings); | ||
|
||
switch (name) { | ||
case INDEX_ANALYZER: | ||
this.analyzer = new KuromojiSuggestAnalyzer.IndexKuromojiSuggestAnalyzer(); | ||
break; | ||
case SEARCH_ANALYZER: | ||
this.analyzer = new KuromojiSuggestAnalyzer.SearchKuromojiSuggestAnalyzer(); | ||
break; | ||
default: | ||
throw new IllegalArgumentException("Invalid name [" + name + "]"); | ||
} | ||
} | ||
|
||
@Override | ||
public KuromojiSuggestAnalyzer get() { | ||
return this.analyzer; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ch/analysis/KuromojiSuggestTokenizer.java → ...ex/analysis/KuromojiSuggestTokenizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...lysis/UnicodeNormalizationCharFilter.java → ...lysis/UnicodeNormalizationCharFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...nicodeNormalizationCharFilterFactory.java → ...nicodeNormalizationCharFilterFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/org/elasticsearch/indices/analysis/KuromojiSuggestIndicesAnalysis.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.elasticsearch.indices.analysis; | ||
|
||
import org.apache.lucene.analysis.Tokenizer; | ||
import org.elasticsearch.common.component.AbstractComponent; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.analysis.AnalyzerScope; | ||
import org.elasticsearch.index.analysis.CharFilterFactory; | ||
import org.elasticsearch.index.analysis.KuromojiSuggestAnalyzer; | ||
import org.elasticsearch.index.analysis.KuromojiSuggestAnalyzerProvider; | ||
import org.elasticsearch.index.analysis.KuromojiSuggestTokenizer; | ||
import org.elasticsearch.index.analysis.PreBuiltAnalyzerProviderFactory; | ||
import org.elasticsearch.index.analysis.PreBuiltCharFilterFactoryFactory; | ||
import org.elasticsearch.index.analysis.PreBuiltTokenizerFactoryFactory; | ||
import org.elasticsearch.index.analysis.TokenizerFactory; | ||
import org.elasticsearch.index.analysis.UnicodeNormalizationCharFilter; | ||
|
||
import java.io.Reader; | ||
import java.text.Normalizer; | ||
|
||
/** | ||
* Registers indices level analysis components so, if not explicitly configured, | ||
* will be shared among all indices. | ||
*/ | ||
public class KuromojiSuggestIndicesAnalysis extends AbstractComponent { | ||
@Inject | ||
public KuromojiSuggestIndicesAnalysis(Settings settings, IndicesAnalysisService indicesAnalysisService) { | ||
super(settings); | ||
indicesAnalysisService.analyzerProviderFactories().put(KuromojiSuggestAnalyzerProvider.INDEX_ANALYZER, | ||
new PreBuiltAnalyzerProviderFactory(KuromojiSuggestAnalyzerProvider.INDEX_ANALYZER, AnalyzerScope.INDICES, | ||
new KuromojiSuggestAnalyzer.IndexKuromojiSuggestAnalyzer())); | ||
|
||
indicesAnalysisService.analyzerProviderFactories().put(KuromojiSuggestAnalyzerProvider.SEARCH_ANALYZER, | ||
new PreBuiltAnalyzerProviderFactory(KuromojiSuggestAnalyzerProvider.SEARCH_ANALYZER, AnalyzerScope.INDICES, | ||
new KuromojiSuggestAnalyzer.SearchKuromojiSuggestAnalyzer())); | ||
|
||
indicesAnalysisService.charFilterFactories().put("nfkc", | ||
new PreBuiltCharFilterFactoryFactory(new CharFilterFactory() { | ||
@Override | ||
public String name() { | ||
return "nfkc"; | ||
} | ||
|
||
@Override | ||
public Reader create(Reader reader) { | ||
return new UnicodeNormalizationCharFilter(reader, Normalizer.Form.NFKC, false); | ||
} | ||
})); | ||
|
||
indicesAnalysisService.tokenizerFactories().put("kuromoji_suggest_index", | ||
new PreBuiltTokenizerFactoryFactory(new TokenizerFactory() { | ||
@Override | ||
public String name() { | ||
return "kuromoji_suggest_index"; | ||
} | ||
|
||
@Override | ||
public Tokenizer create() { | ||
return new KuromojiSuggestTokenizer(true, 512, false); | ||
} | ||
})); | ||
|
||
indicesAnalysisService.tokenizerFactories().put("kuromoji_suggest_search", | ||
new PreBuiltTokenizerFactoryFactory(new TokenizerFactory() { | ||
@Override | ||
public String name() { | ||
return "kuromoji_suggest_search"; | ||
} | ||
|
||
@Override | ||
public Tokenizer create() { | ||
return new KuromojiSuggestTokenizer(false, 512, false); | ||
} | ||
})); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/elasticsearch/indices/analysis/KuromojiSuggestIndicesAnalysisModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.elasticsearch.indices.analysis; | ||
|
||
import org.elasticsearch.common.inject.AbstractModule; | ||
|
||
public class KuromojiSuggestIndicesAnalysisModule extends AbstractModule { | ||
@Override | ||
protected void configure() { | ||
bind(KuromojiSuggestIndicesAnalysis.class).asEagerSingleton(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.