Example usage for org.apache.lucene.analysis.util ResourceLoader findClass

List of usage examples for org.apache.lucene.analysis.util ResourceLoader findClass

Introduction

In this page you can find the example usage for org.apache.lucene.analysis.util ResourceLoader findClass.

Prototype

public <T> Class<? extends T> findClass(String cname, Class<T> expectedType);

Source Link

Document

Finds class of the name and expected type

Usage

From source file:edu.upenn.library.solrplugins.tokentype.TokenTypeProcessFilterFactory.java

License:Apache License

@Override
public void inform(ResourceLoader loader) throws IOException {
    if (delegateFilterFactoryName == null) {
        delegateFilterFactory = null;//  w  w w.  j a  va  2 s. com
    } else {
        Class<? extends TokenFilterFactory> offClass = loader.findClass(delegateFilterFactoryName,
                TokenFilterFactory.class);
        try {
            Constructor<? extends TokenFilterFactory> constructor = offClass.getConstructor(Map.class);
            delegateFilterFactory = constructor.newInstance(subargs);
            if (delegateFilterFactory instanceof ResourceLoaderAware) {
                ((ResourceLoaderAware) delegateFilterFactory).inform(loader);
            }
        } catch (NoSuchMethodException ex) {
            throw new RuntimeException(ex);
        } catch (SecurityException ex) {
            throw new RuntimeException(ex);
        } catch (InstantiationException ex) {
            throw new RuntimeException(ex);
        } catch (IllegalAccessException ex) {
            throw new RuntimeException(ex);
        } catch (IllegalArgumentException ex) {
            throw new RuntimeException(ex);
        } catch (InvocationTargetException ex) {
            throw new RuntimeException(ex);
        }
    }
}

From source file:edu.upenn.library.solrplugins.tokentype.TokenTypeSplitFilterFactory.java

License:Apache License

@Override
public void inform(ResourceLoader loader) throws IOException {
    if (outputFilterFactoryName == null) {
        outputFilterFactory = null;// w  w w .ja v a  2 s. co m
    } else {
        Class<? extends TokenFilterFactory> offClass = loader.findClass(outputFilterFactoryName,
                TokenFilterFactory.class);
        try {
            Constructor<? extends TokenFilterFactory> constructor = offClass.getConstructor(Map.class);
            outputFilterFactory = constructor.newInstance(subargs);
            if (outputFilterFactory instanceof ResourceLoaderAware) {
                ((ResourceLoaderAware) outputFilterFactory).inform(loader);
            }
        } catch (NoSuchMethodException ex) {
            throw new RuntimeException(ex);
        } catch (SecurityException ex) {
            throw new RuntimeException(ex);
        } catch (InstantiationException ex) {
            throw new RuntimeException(ex);
        } catch (IllegalAccessException ex) {
            throw new RuntimeException(ex);
        } catch (IllegalArgumentException ex) {
            throw new RuntimeException(ex);
        } catch (InvocationTargetException ex) {
            throw new RuntimeException(ex);
        }
    }
}

From source file:jp.sf.fess.solr.plugin.analysis.synonym.NGramSynonymTokenizerFactory.java

License:Apache License

private SynonymMap loadSynonyms(final ResourceLoader loader, final String cname, final boolean dedup,
        final Analyzer analyzer, final boolean expand, final String synonyms)
        throws IOException, ParseException {
    final CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder()
            .onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);

    SynonymMap.Parser parser;//  www  .j av  a  2  s.com
    final 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 (final Exception e) {
        throw new RuntimeException(e);
    }

    final File synonymFile = new File(synonyms);
    if (synonymFile.exists()) {
        decoder.reset();
        parser.parse(new InputStreamReader(loader.openResource(synonyms), decoder));
    } else {
        final List<String> files = splitFileNames(synonyms);
        for (final String file : files) {
            decoder.reset();
            parser.parse(new InputStreamReader(loader.openResource(file), decoder));
        }
    }
    return parser.build();
}

From source file:org.apache.solr.rest.schema.analysis.FSTSynonymFilterFactory.java

License:Apache License

/**
 * Load synonyms with the given SynonymMap.Parser class.
 *///ww  w  . j  av  a2s.c  om
protected SynonymMap loadSynonyms(ResourceLoader loader, String cname, boolean dedup, Analyzer analyzer)
        throws IOException, ParseException {
    CharsetDecoder decoder = Charset.forName("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);
    }

    File synonymFile = new File(synonyms);
    if (synonymFile.exists()) {
        decoder.reset();
        parser.parse(new InputStreamReader(loader.openResource(synonyms), decoder));
    } else {
        List<String> files = splitFileNames(synonyms);
        for (String file : files) {
            decoder.reset();
            parser.parse(new InputStreamReader(loader.openResource(file), decoder));
        }
    }
    return parser.build();
}

From source file:org.apache.solr.rest.schema.analysis.FSTSynonymFilterFactory.java

License:Apache License

private TokenizerFactory loadTokenizerFactory(ResourceLoader loader, String cname) throws IOException {
    Class<? extends TokenizerFactory> clazz = loader.findClass(cname, TokenizerFactory.class);
    try {//from  w w  w .  j  av a2  s  . c o m
        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);
    }
}

From source file:pl.litwiniuk.rowicki.modsynonyms.ModificatedFSTSynonymFilterFactory.java

License:Apache License

private TokenizerFactory loadTokenizerFactory(ResourceLoader loader, String cname) throws IOException {
    Map<String, String> args = new HashMap<String, String>();
    args.put("luceneMatchVersion", getLuceneMatchVersion().toString());
    Class<? extends TokenizerFactory> clazz = loader.findClass(cname, TokenizerFactory.class);
    try {//from w  ww  .  j av a2s .c om
        TokenizerFactory tokFactory = clazz.getConstructor(Map.class).newInstance(args);
        if (tokFactory instanceof ResourceLoaderAware) {
            ((ResourceLoaderAware) tokFactory).inform(loader);
        }
        return tokFactory;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}