Java Code Examples for org.apache.lucene.analysis.util.ResourceLoader#findClass()

The following examples show how to use org.apache.lucene.analysis.util.ResourceLoader#findClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SynonymGraphFilterFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Load synonyms with the given {@link SynonymMap.Parser} class.
 */
protected SynonymMap loadSynonyms(ResourceLoader loader, String cname, boolean dedup, Analyzer analyzer) throws IOException, ParseException {
  CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder()
      .onMalformedInput(CodingErrorAction.REPORT)
      .onUnmappableCharacter(CodingErrorAction.REPORT);

  SynonymMap.Parser parser;
  Class<? extends SynonymMap.Parser> clazz = loader.findClass(cname, SynonymMap.Parser.class);
  try {
    parser = clazz.getConstructor(boolean.class, boolean.class, Analyzer.class).newInstance(dedup, expand, analyzer);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }

  List<String> files = splitFileNames(synonyms);
  for (String file : files) {
    decoder.reset();
    parser.parse(new InputStreamReader(loader.openResource(file), decoder));
  }
  return parser.build();
}
 
Example 2
Source File: SynonymFilterFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Load synonyms with the given {@link SynonymMap.Parser} class.
 */
protected SynonymMap loadSynonyms(ResourceLoader loader, String cname, boolean dedup, Analyzer analyzer) throws IOException, ParseException {
  CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder()
      .onMalformedInput(CodingErrorAction.REPORT)
      .onUnmappableCharacter(CodingErrorAction.REPORT);

  SynonymMap.Parser parser;
  Class<? extends SynonymMap.Parser> clazz = loader.findClass(cname, SynonymMap.Parser.class);
  try {
    parser = clazz.getConstructor(boolean.class, boolean.class, Analyzer.class).newInstance(dedup, expand, analyzer);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }

  List<String> files = splitFileNames(synonyms);
  for (String file : files) {
    decoder.reset();
    try (final Reader isr = new InputStreamReader(loader.openResource(file), decoder)) {
      parser.parse(isr);
    }
  }
  return parser.build();
}
 
Example 3
Source File: SynonymGraphFilterFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private TokenizerFactory loadTokenizerFactory(ResourceLoader loader, String cname) throws IOException {
  Class<? extends TokenizerFactory> clazz = loader.findClass(cname, TokenizerFactory.class);
  try {
    TokenizerFactory tokFactory = clazz.getConstructor(Map.class).newInstance(tokArgs);
    if (tokFactory instanceof ResourceLoaderAware) {
      ((ResourceLoaderAware) tokFactory).inform(loader);
    }
    return tokFactory;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 4
Source File: SynonymGraphFilterFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private Analyzer loadAnalyzer(ResourceLoader loader, String cname) throws IOException {
  Class<? extends Analyzer> clazz = loader.findClass(cname, Analyzer.class);
  try {
    Analyzer analyzer = clazz.getConstructor().newInstance();
    if (analyzer instanceof ResourceLoaderAware) {
      ((ResourceLoaderAware) analyzer).inform(loader);
    }
    return analyzer;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 5
Source File: SynonymFilterFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private TokenizerFactory loadTokenizerFactory(ResourceLoader loader, String cname) throws IOException {
  Class<? extends TokenizerFactory> clazz = loader.findClass(cname, TokenizerFactory.class);
  try {
    TokenizerFactory tokFactory = clazz.getConstructor(Map.class).newInstance(tokArgs);
    if (tokFactory instanceof ResourceLoaderAware) {
      ((ResourceLoaderAware) tokFactory).inform(loader);
    }
    return tokFactory;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 6
Source File: SynonymFilterFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private Analyzer loadAnalyzer(ResourceLoader loader, String cname) throws IOException {
  Class<? extends Analyzer> clazz = loader.findClass(cname, Analyzer.class);
  try {
    Analyzer analyzer = clazz.getConstructor().newInstance();
    if (analyzer instanceof ResourceLoaderAware) {
      ((ResourceLoaderAware) analyzer).inform(loader);
    }
    return analyzer;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}