當前位置: 首頁>>代碼示例>>Java>>正文


Java AnalysisModule類代碼示例

本文整理匯總了Java中org.elasticsearch.indices.analysis.AnalysisModule的典型用法代碼示例。如果您正苦於以下問題:Java AnalysisModule類的具體用法?Java AnalysisModule怎麽用?Java AnalysisModule使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AnalysisModule類屬於org.elasticsearch.indices.analysis包,在下文中一共展示了AnalysisModule類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: analyze

import org.elasticsearch.indices.analysis.AnalysisModule; //導入依賴的package包/類
private List<String> analyze(Settings settings, String analyzerName, String text) throws IOException {
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("test", settings);
    AnalysisModule analysisModule = new AnalysisModule(new Environment(settings), singletonList(new AnalysisPlugin() {
        @Override
        public Map<String, AnalysisProvider<TokenFilterFactory>> getTokenFilters() {
            return singletonMap("myfilter", MyFilterTokenFilterFactory::new);
        }
    }));
    IndexAnalyzers indexAnalyzers = analysisModule.getAnalysisRegistry().build(idxSettings);
    Analyzer analyzer = indexAnalyzers.get(analyzerName).analyzer();

    AllEntries allEntries = new AllEntries();
    allEntries.addText("field1", text, 1.0f);

    TokenStream stream = AllTokenStream.allTokenStream("_all", text, 1.0f, analyzer);
    stream.reset();
    CharTermAttribute termAtt = stream.addAttribute(CharTermAttribute.class);

    List<String> terms = new ArrayList<>();
    while (stream.incrementToken()) {
        String tokText = termAtt.toString();
        terms.add(tokText);
    }
    return terms;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:26,代碼來源:CompoundAnalysisTests.java

示例2: getTokenFilters

import org.elasticsearch.indices.analysis.AnalysisModule; //導入依賴的package包/類
@Override
public Map<String, AnalysisModule.AnalysisProvider<TokenFilterFactory>> getTokenFilters() {
    Map<String, AnalysisModule.AnalysisProvider<TokenFilterFactory>> tokenFilters = new HashMap<>();
    tokenFilters.put("openkoreantext-stemmer", OpenKoreanTextStemmerFactory::new);
    tokenFilters.put("openkoreantext-redundant-filter", OpenKoreanTextRedundantFilterFactory::new);
    tokenFilters.put("openkoreantext-phrase-extractor", OpenKoreanTextPhraseExtractorFactory::new);

    return tokenFilters;
}
 
開發者ID:open-korean-text,項目名稱:elasticsearch-analysis-openkoreantext,代碼行數:10,代碼來源:AnalysisOpenKoreanTextPlugin.java

示例3: getTokenizers

import org.elasticsearch.indices.analysis.AnalysisModule; //導入依賴的package包/類
@Override
public Map<String, AnalysisModule.AnalysisProvider<TokenizerFactory>> getTokenizers() {
  Map<String, AnalysisModule.AnalysisProvider<TokenizerFactory>> extra = new HashMap<>();

  extra.put("jieba_search", JiebaTokenizerFactory::getJiebaSearchTokenizerFactory);
  extra.put("jieba_index", JiebaTokenizerFactory::getJiebaIndexTokenizerFactory);

  return extra;
}
 
開發者ID:sing1ee,項目名稱:elasticsearch-jieba-plugin,代碼行數:10,代碼來源:AnalysisJiebaPlugin.java

示例4: getAnalyzers

import org.elasticsearch.indices.analysis.AnalysisModule; //導入依賴的package包/類
@Override
public Map<String, AnalysisModule.AnalysisProvider<AnalyzerProvider<? extends Analyzer>>> getAnalyzers() {
  Map<String, AnalysisModule.AnalysisProvider<AnalyzerProvider<? extends Analyzer>>> extra = new HashMap<>();

  extra.put("jieba_search", JiebaAnalyzerProvider::getJiebaSearchAnalyzerProvider);
  extra.put("jieba_index", JiebaAnalyzerProvider::getJiebaIndexAnalyzerProvider);

  return extra;
}
 
開發者ID:sing1ee,項目名稱:elasticsearch-jieba-plugin,代碼行數:10,代碼來源:AnalysisJiebaPlugin.java

示例5: createTestAnalysis

import org.elasticsearch.indices.analysis.AnalysisModule; //導入依賴的package包/類
/**
 * Creates an TestAnalysis with all the default analyzers configured.
 */
public static TestAnalysis createTestAnalysis(IndexSettings indexSettings, Settings nodeSettings,
                                              AnalysisPlugin... analysisPlugins) throws IOException {
    Environment env = new Environment(nodeSettings);
    AnalysisModule analysisModule = new AnalysisModule(env, Arrays.asList(analysisPlugins));
    AnalysisRegistry analysisRegistry = analysisModule.getAnalysisRegistry();
    return new TestAnalysis(analysisRegistry.build(indexSettings),
        analysisRegistry.buildTokenFilterFactories(indexSettings),
        analysisRegistry.buildTokenizerFactories(indexSettings),
        analysisRegistry.buildCharFilterFactories(indexSettings));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:14,代碼來源:ESTestCase.java

示例6: getAnalyzer

import org.elasticsearch.indices.analysis.AnalysisModule; //導入依賴的package包/類
/**
 * Returns a registered {@link Analyzer} provider by name or <code>null</code> if the analyzer was not registered
 */
public Analyzer getAnalyzer(String analyzer) throws IOException {
    AnalysisModule.AnalysisProvider<AnalyzerProvider<?>> analyzerProvider = this.prebuiltAnalysis.getAnalyzerProvider(analyzer);
    if (analyzerProvider == null) {
        AnalysisModule.AnalysisProvider<AnalyzerProvider<?>> provider = analyzers.get(analyzer);
        return provider == null ? null : cachedAnalyzer.computeIfAbsent(analyzer, (key) -> {
                    try {
                        return provider.get(environment, key).get();
                    } catch (IOException ex) {
                        throw new ElasticsearchException("failed to load analyzer for name " + key, ex);
                    }}
        );
    }
    return analyzerProvider.get(environment, analyzer).get();
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:AnalysisRegistry.java

示例7: buildTokenFilterFactories

import org.elasticsearch.indices.analysis.AnalysisModule; //導入依賴的package包/類
public Map<String, TokenFilterFactory> buildTokenFilterFactories(IndexSettings indexSettings) throws IOException {
    final Map<String, Settings> tokenFiltersSettings = indexSettings.getSettings().getGroups(INDEX_ANALYSIS_FILTER);
    Map<String, AnalysisModule.AnalysisProvider<TokenFilterFactory>> tokenFilters = new HashMap<>(this.tokenFilters);
    /*
     * synonym and synonym_graph are different than everything else since they need access to the tokenizer factories for the index.
     * instead of building the infrastructure for plugins we rather make it a real exception to not pollute the general interface and
     * hide internal data-structures as much as possible.
     */
    tokenFilters.put("synonym", requiresAnalysisSettings((is, env, name, settings) -> new SynonymTokenFilterFactory(is, env, this, name, settings)));
    tokenFilters.put("synonym_graph", requiresAnalysisSettings((is, env, name, settings) -> new SynonymGraphTokenFilterFactory(is, env, this, name, settings)));
    return buildMapping(Component.FILTER, indexSettings, tokenFiltersSettings, Collections.unmodifiableMap(tokenFilters), prebuiltAnalysis.tokenFilterFactories);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:AnalysisRegistry.java

示例8: requiresAnalysisSettings

import org.elasticsearch.indices.analysis.AnalysisModule; //導入依賴的package包/類
private static <T> AnalysisModule.AnalysisProvider<T> requiresAnalysisSettings(AnalysisModule.AnalysisProvider<T> provider) {
    return new AnalysisModule.AnalysisProvider<T>() {
        @Override
        public T get(IndexSettings indexSettings, Environment environment, String name, Settings settings) throws IOException {
            return provider.get(indexSettings, environment, name, settings);
        }
        @Override
        public boolean requiresAnalysisSettings() {
            return true;
        }
    };
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:AnalysisRegistry.java

示例9: createTestAnalysisFromSettings

import org.elasticsearch.indices.analysis.AnalysisModule; //導入依賴的package包/類
public static ESTestCase.TestAnalysis createTestAnalysisFromSettings(
        Settings settings) throws IOException {
    if (settings.get(IndexMetaData.SETTING_VERSION_CREATED) == null) {
        settings = Settings.builder().put(settings).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
    }
    IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("test", settings);
    AnalysisRegistry analysisRegistry = new AnalysisModule(new Environment(settings), emptyList()).getAnalysisRegistry();
    return new ESTestCase.TestAnalysis(analysisRegistry.build(indexSettings),
        analysisRegistry.buildTokenFilterFactories(indexSettings),
        analysisRegistry.buildTokenizerFactories(indexSettings),
        analysisRegistry.buildCharFilterFactories(indexSettings));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:AnalysisTestsHelper.java

示例10: testDefaultsCompoundAnalysis

import org.elasticsearch.indices.analysis.AnalysisModule; //導入依賴的package包/類
public void testDefaultsCompoundAnalysis() throws Exception {
    Settings settings = getJsonSettings();
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("test", settings);
    AnalysisModule analysisModule = new AnalysisModule(new Environment(settings), singletonList(new AnalysisPlugin() {
        @Override
        public Map<String, AnalysisProvider<TokenFilterFactory>> getTokenFilters() {
            return singletonMap("myfilter", MyFilterTokenFilterFactory::new);
        }
    }));
    TokenFilterFactory filterFactory = analysisModule.getAnalysisRegistry().buildTokenFilterFactories(idxSettings).get("dict_dec");
    MatcherAssert.assertThat(filterFactory, instanceOf(DictionaryCompoundWordTokenFilterFactory.class));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:CompoundAnalysisTests.java

示例11: setUp

import org.elasticsearch.indices.analysis.AnalysisModule; //導入依賴的package包/類
@Override
public void setUp() throws Exception {
    super.setUp();
    Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();

    Settings indexSettings = Settings.builder()
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
            .put("index.analysis.filter.wordDelimiter.type", "word_delimiter")
            .put("index.analysis.filter.wordDelimiter.split_on_numerics", false)
            .put("index.analysis.analyzer.custom_analyzer.tokenizer", "whitespace")
            .putArray("index.analysis.analyzer.custom_analyzer.filter", "lowercase", "wordDelimiter")
            .put("index.analysis.analyzer.custom_analyzer.tokenizer", "whitespace")
            .putArray("index.analysis.analyzer.custom_analyzer.filter", "lowercase", "wordDelimiter")
            .put("index.analysis.tokenizer.trigram.type", "ngram")
            .put("index.analysis.tokenizer.trigram.min_gram", 3)
            .put("index.analysis.tokenizer.trigram.max_gram", 3)
            .put("index.analysis.filter.synonym.type", "synonym")
            .putArray("index.analysis.filter.synonym.synonyms", "kimchy => shay")
            .put("index.analysis.filter.synonym.tokenizer", "trigram")
            .put("index.analysis.filter.synonym.min_gram", 3)
            .put("index.analysis.filter.synonym.max_gram", 3).build();
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", indexSettings);
    environment = new Environment(settings);
    registry = new AnalysisModule(environment, emptyList()).getAnalysisRegistry();
    indexAnalyzers = registry.build(idxSettings);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:28,代碼來源:TransportAnalyzeActionTests.java

示例12: getTokenizers

import org.elasticsearch.indices.analysis.AnalysisModule; //導入依賴的package包/類
@Override
public Map<String, AnalysisModule.AnalysisProvider<TokenizerFactory>> getTokenizers() {
    HashMap<String, AnalysisModule.AnalysisProvider<TokenizerFactory>> tokenizers = new HashMap<>();
    tokenizers.put("hanlp", HanLPTokenizerFactory::createStandard);
    tokenizers.put("hanlp-standard", HanLPTokenizerFactory::createStandard);
    tokenizers.put("hanlp-nlp", HanLPTokenizerFactory::createNLP);
    tokenizers.put("hanlp-index", HanLPIndexAnalyzerFactory::new);
    tokenizers.put("hanlp-nshort", HanLPTokenizerFactory::createNShort);
    tokenizers.put("hanlp-shortest", HanLPTokenizerFactory::createShortest);
    tokenizers.put("hanlp-crf", HanLPTokenizerFactory::createCRF);
    tokenizers.put("hanlp-speed", HanLPTokenizerFactory::createSpeed);
    return tokenizers;
}
 
開發者ID:hualongdata,項目名稱:hanlp-ext,代碼行數:14,代碼來源:AnalysisHanLPPlugin.java

示例13: getAnalyzers

import org.elasticsearch.indices.analysis.AnalysisModule; //導入依賴的package包/類
@Override
public Map<String, AnalysisModule.AnalysisProvider<AnalyzerProvider<? extends Analyzer>>> getAnalyzers() {
    Map<String, AnalysisModule.AnalysisProvider<AnalyzerProvider<? extends Analyzer>>> analyzers = new HashMap<>();
    analyzers.put("hanlp", HanLPAnalyzerProvider::new);
    analyzers.put("hanlp-index", HanLPIndexAnalyzerProvider::new);
    return analyzers;
}
 
開發者ID:hualongdata,項目名稱:hanlp-ext,代碼行數:8,代碼來源:AnalysisHanLPPlugin.java

示例14: getAnalyzers

import org.elasticsearch.indices.analysis.AnalysisModule; //導入依賴的package包/類
@Override
public Map<String, AnalysisModule.AnalysisProvider<AnalyzerProvider<? extends Analyzer>>> getAnalyzers() {
    Map<String, AnalysisModule.AnalysisProvider<AnalyzerProvider<? extends Analyzer>>> extra = new HashMap<>();

    extra.put("ik_smart", IkAnalyzerProvider::getIkSmartAnalyzerProvider);
    extra.put("ik_max_word", IkAnalyzerProvider::getIkAnalyzerProvider);

    return extra;
}
 
開發者ID:judasn,項目名稱:Elasticsearch-Tutorial-zh-CN,代碼行數:10,代碼來源:AnalysisIkPlugin.java

示例15: getTokenFilters

import org.elasticsearch.indices.analysis.AnalysisModule; //導入依賴的package包/類
@Override
public Map<String, AnalysisModule.AnalysisProvider<TokenFilterFactory>> getTokenFilters() {
    Map<String, AnalysisModule.AnalysisProvider<TokenFilterFactory>> tokenFilters = new HashMap<>();

    tokenFilters.put(PLUGIN_NAME, requiresAnalysisSettings((is, env, name, settings) -> new DynamicSynonymTokenFilterFactory(is, env, name, settings)));

    return tokenFilters;
}
 
開發者ID:ginobefun,項目名稱:elasticsearch-dynamic-synonym,代碼行數:9,代碼來源:DynamicSynonymPlugin.java


注:本文中的org.elasticsearch.indices.analysis.AnalysisModule類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。