org.elasticsearch.index.analysis.Analysis类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(234)

本文整理了Java中org.elasticsearch.index.analysis.Analysis类的一些代码示例,展示了Analysis类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Analysis类的具体详情如下:
包路径:org.elasticsearch.index.analysis.Analysis
类名称:Analysis

Analysis介绍

暂无

代码示例

代码示例来源:origin: org.elasticsearch/elasticsearch

public static CharArraySet parseStopWords(Environment env, org.elasticsearch.Version indexCreatedVersion, Settings settings,
                     CharArraySet defaultStopWords) {
  boolean stopwordsCase =
    settings.getAsBooleanLenientForPreEs6Indices(indexCreatedVersion, "stopwords_case", false, deprecationLogger);
  return parseStopWords(env, settings, defaultStopWords, stopwordsCase);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

protected Reader getRulesFromSettings(Environment env) {
  Reader rulesReader;
  if (settings.getAsList("synonyms", null) != null) {
    List<String> rulesList = Analysis.getWordList(env, settings, "synonyms");
    StringBuilder sb = new StringBuilder();
    for (String line : rulesList) {
      sb.append(line).append(System.lineSeparator());
    }
    rulesReader = new StringReader(sb.toString());
  } else if (settings.get("synonyms_path") != null) {
    rulesReader = Analysis.getReaderFromFile(env, settings, "synonyms_path");
  } else {
    throw new IllegalArgumentException("synonym requires either `synonyms` or `synonyms_path` to be configured");
  }
  return rulesReader;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

public static CharArraySet parseCommonWords(Environment env, Settings settings, CharArraySet defaultCommonWords, boolean ignoreCase) {
  return parseWords(env, settings, "common_words", defaultCommonWords, NAMED_STOP_WORDS, ignoreCase);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

public static CharArraySet parseWords(Environment env, Settings settings, String name, CharArraySet defaultWords,
                   Map<String, Set<?>> namedWords, boolean ignoreCase) {
  String value = settings.get(name);
  if (value != null) {
    if ("_none_".equals(value)) {
      return CharArraySet.EMPTY_SET;
    } else {
      return resolveNamedWords(settings.getAsList(name), namedWords, ignoreCase);
    }
  }
  List<String> pathLoadedWords = getWordList(env, settings, name);
  if (pathLoadedWords != null) {
    return resolveNamedWords(pathLoadedWords, namedWords, ignoreCase);
  }
  return defaultWords;
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

public FinnishAnalyzerProvider(IndexSettings indexSettings, Environment env, String name, Settings settings) {
  super(indexSettings, name, settings);
  analyzer = new FinnishAnalyzer(Analysis.parseStopWords(env, settings, FinnishAnalyzer.getDefaultStopSet()),
                  Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET));
  analyzer.setVersion(version);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * Fetches a list of words from the specified settings file. The list should either be available at the key
 * specified by settingsPrefix or in a file specified by settingsPrefix + _path.
 *
 * @throws IllegalArgumentException
 *          If the word list cannot be found at either key.
 */
public static List<String> getWordList(Environment env, Settings settings, String settingPrefix) {
  return getWordList(env, settings, settingPrefix + "_path", settingPrefix);
}

代码示例来源:origin: org.elasticsearch.plugin/analysis-kuromoji

public static UserDictionary getUserDictionary(Environment env, Settings settings) {
  try {
    final Reader reader = Analysis.getReaderFromFile(env, settings, USER_DICT_OPTION);
    if (reader == null) {
      return null;
    } else {
      try {
        return UserDictionary.open(reader);
      } finally {
        reader.close();
      }
    }
  } catch (IOException e) {
    throw new ElasticsearchException("failed to load kuromoji user dictionary", e);
  }
}

代码示例来源:origin: skroutz/elasticsearch-analysis-turkishstemmer

private CharArraySet parseExceptions(Environment env, Settings settings,
   String settingPrefix) throws IOException {

  List<String> exceptionsList = new ArrayList<String>();
  Reader exceptionsReader = null;

  try {
   exceptionsReader = Analysis.getReaderFromFile(env, settings, settingPrefix);
  } catch (InvalidPathException e) {
   logger.info("failed to find the " + settingPrefix + ", using the default set");
  }

  if (exceptionsReader != null) {
   try {
    exceptionsList = Analysis.loadWordList(exceptionsReader, "#");
    if (exceptionsList.isEmpty()) {
     return CharArraySet.EMPTY_SET;
    } else {
     return new CharArraySet(exceptionsList, false);
    }
   } finally {
    if (exceptionsReader != null)
     exceptionsReader.close();
   }
  } else {
   return null;
  }
 }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

public AbstractTokenFilterFactory(IndexSettings indexSettings, String name, Settings settings) {
  super(indexSettings);
  this.name = name;
  this.version = Analysis.parseAnalysisVersion(this.indexSettings.getSettings(), settings, logger);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * Fetches a list of words from the specified settings file. The list should either be available at the key
 * specified by <code>settingList</code> or in a file specified by <code>settingPath</code>.
 *
 * @throws IllegalArgumentException
 *          If the word list cannot be found at either key.
 */
public static List<String> getWordList(Environment env, Settings settings, String settingPath, String settingList) {
  String wordListPath = settings.get(settingPath, null);
  if (wordListPath == null) {
    List<String> explicitWordList = settings.getAsList(settingList, null);
    if (explicitWordList == null) {
      return null;
    } else {
      return explicitWordList;
    }
  }
  final Path path = env.configFile().resolve(wordListPath);
  try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
    return loadWordList(reader, "#");
  } catch (CharacterCodingException ex) {
    String message = String.format(Locale.ROOT,
      "Unsupported character encoding detected while reading %s: %s - files must be UTF-8 encoded",
      settingPath, path.toString());
    throw new IllegalArgumentException(message, ex);
  } catch (IOException ioe) {
    String message = String.format(Locale.ROOT, "IOException while reading %s: %s", settingPath, path.toString());
    throw new IllegalArgumentException(message, ioe);
  }
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

public ItalianAnalyzerProvider(IndexSettings indexSettings, Environment env, String name, Settings settings) {
  super(indexSettings, name, settings);
  analyzer = new ItalianAnalyzer(Analysis.parseStopWords(env, settings, ItalianAnalyzer.getDefaultStopSet()),
                  Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET));
  analyzer.setVersion(version);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

public static CharArraySet getWordSet(Environment env, org.elasticsearch.Version indexCreatedVersion, Settings settings,
                   String settingsPrefix) {
  List<String> wordList = getWordList(env, settings, settingsPrefix);
  if (wordList == null) {
    return null;
  }
  boolean ignoreCase =
    settings.getAsBooleanLenientForPreEs6Indices(indexCreatedVersion, settingsPrefix + "_case", false, deprecationLogger);
  return new CharArraySet(wordList, ignoreCase);
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

public static CharArraySet parseWords(Environment env, Settings settings, String name, CharArraySet defaultWords,
                   Map<String, Set<?>> namedWords, boolean ignoreCase) {
  String value = settings.get(name);
  if (value != null) {
    if ("_none_".equals(value)) {
      return CharArraySet.EMPTY_SET;
    } else {
      return resolveNamedWords(Strings.commaDelimitedListToSet(value), namedWords, ignoreCase);
    }
  }
  List<String> pathLoadedWords = getWordList(env, settings, name);
  if (pathLoadedWords != null) {
    return resolveNamedWords(pathLoadedWords, namedWords, ignoreCase);
  }
  return defaultWords;
}

代码示例来源:origin: org.codelibs/elasticsearch-analysis-ja

public static UserDictionary getUserDictionary(final Environment env, final Settings settings) {
  try {
    final Reader reader = Analysis.getReaderFromFile(env, settings, USER_DICT_OPTION);
    if (reader == null) {
      return null;
    } else {
      try {
        return UserDictionary.open(reader);
      } finally {
        reader.close();
      }
    }
  } catch (final IOException e) {
    throw new ElasticsearchException("failed to load kuromoji user dictionary", e);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

public AbstractTokenizerFactory(IndexSettings indexSettings, String ignored, Settings settings) {
  super(indexSettings);
  this.version = Analysis.parseAnalysisVersion(this.indexSettings.getSettings(), settings, logger);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

/**
 * Fetches a list of words from the specified settings file. The list should either be available at the key
 * specified by settingsPrefix or in a file specified by settingsPrefix + _path.
 *
 * @throws IllegalArgumentException
 *          If the word list cannot be found at either key.
 */
public static List<String> getWordList(Environment env, Settings settings, String settingPrefix) {
  String wordListPath = settings.get(settingPrefix + "_path", null);
  if (wordListPath == null) {
    List<String> explicitWordList = settings.getAsList(settingPrefix, null);
    if (explicitWordList == null) {
      return null;
    } else {
      return explicitWordList;
    }
  }
  final Path path = env.configFile().resolve(wordListPath);
  try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
    return loadWordList(reader, "#");
  } catch (CharacterCodingException ex) {
    String message = String.format(Locale.ROOT,
      "Unsupported character encoding detected while reading %s_path: %s - files must be UTF-8 encoded",
      settingPrefix, path.toString());
    throw new IllegalArgumentException(message, ex);
  } catch (IOException ioe) {
    String message = String.format(Locale.ROOT, "IOException while reading %s_path: %s", settingPrefix, path.toString());
    throw new IllegalArgumentException(message, ioe);
  }
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

public HindiAnalyzerProvider(IndexSettings indexSettings, Environment env, String name, Settings settings) {
  super(indexSettings, name, settings);
  analyzer = new HindiAnalyzer(Analysis.parseStopWords(env, settings, HindiAnalyzer.getDefaultStopSet()),
                 Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET));
  analyzer.setVersion(version);
}

代码示例来源:origin: apache/servicemix-bundles

protected Reader getRulesFromSettings(Environment env) {
  Reader rulesReader;
  if (settings.getAsList("synonyms", null) != null) {
    List<String> rulesList = Analysis.getWordList(env, settings, "synonyms");
    StringBuilder sb = new StringBuilder();
    for (String line : rulesList) {
      sb.append(line).append(System.lineSeparator());
    }
    rulesReader = new StringReader(sb.toString());
  } else if (settings.get("synonyms_path") != null) {
    rulesReader = Analysis.getReaderFromFile(env, settings, "synonyms_path");
  } else {
    throw new IllegalArgumentException("synonym requires either `synonyms` or `synonyms_path` to be configured");
  }
  return rulesReader;
}

代码示例来源:origin: codelibs/elasticsearch-analysis-kuromoji-neologd

public PosConcatenationFilterFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
  super(indexSettings, name, settings);
  List<String> tagList = Analysis.getWordList(environment, settings, "tags");
  if (tagList != null) {
    posTags.addAll(tagList);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

public static CharArraySet parseStopWords(Environment env, Settings settings, CharArraySet defaultStopWords, boolean ignoreCase) {
  return parseWords(env, settings, "stopwords", defaultStopWords, NAMED_STOP_WORDS, ignoreCase);
}

相关文章