Java 类org.apache.lucene.analysis.icu.segmentation.DefaultICUTokenizerConfig 实例源码

项目:emoji-search    文件:EmojiTokenizerFactory.java   
public EmojiTokenizerFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
    super(indexSettings, name, settings);

    config = new DefaultICUTokenizerConfig(true, true) {
        @Override
        public BreakIterator getBreakIterator(int script) {
            // Load the ICU default rules
            RuleBasedBreakIterator rbbi = (RuleBasedBreakIterator)
                    BreakIterator.getWordInstance(Locale.getDefault());
            String defaultRules = rbbi.toString();

            // Customize the rules to add EmojiNRK as first class word
            defaultRules = defaultRules.replace(
                "!!forward;",
                "!!forward;\n$EmojiNRK {200};"
            );

            defaultRules = defaultRules.replace(
                "| $ZWJ)*;",
                "| $ZWJ)* {200};"
            );

            return new RuleBasedBreakIterator(defaultRules);
        }
    };
}