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

The following examples show how to use org.apache.lucene.analysis.util.ResourceLoader#newInstance() . 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: DelimitedPayloadTokenFilterFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void inform(ResourceLoader loader) {
  if (encoderClass.equals("float")){
    encoder = new FloatEncoder();
  } else if (encoderClass.equals("integer")){
    encoder = new IntegerEncoder();
  } else if (encoderClass.equals("identity")){
    encoder = new IdentityEncoder();
  } else {
    encoder = loader.newInstance(encoderClass, PayloadEncoder.class);
  }
}
 
Example 2
Source File: ReplaceRewriterFactory.java    From querqy with Apache License 2.0 5 votes vote down vote up
@Override
public RewriterFactory createFactory(String id, NamedList<?> args, ResourceLoader resourceLoader) throws IOException {

    final String rulesResourceName = (String) args.get("rules");
    if (rulesResourceName == null) {
        throw new IllegalArgumentException("Property 'rules' not configured");
    }

    final InputStreamReader reader = new InputStreamReader(resourceLoader.openResource(rulesResourceName), StandardCharsets.UTF_8);

    final Boolean ignoreCase = args.getBooleanArg("ignoreCase");

    final String inputDelimiter = (String) args.get("inputDelimiter");

    // querqy parser for queries that are part of the instructions in the rules
    String rulesQuerqyParser = (String) args.get("querqyParser");
    QuerqyParserFactory querqyParser = null;
    if (rulesQuerqyParser != null) {
        rulesQuerqyParser = rulesQuerqyParser.trim();
        if (rulesQuerqyParser.length() > 0) {
            querqyParser = resourceLoader.newInstance(rulesQuerqyParser, QuerqyParserFactory.class);
        }
    }

    if (querqyParser == null) {
        querqyParser = new WhiteSpaceQuerqyParserFactory();
    }

    return new querqy.rewrite.contrib.ReplaceRewriterFactory(id, reader,
            ignoreCase != null ? ignoreCase : DEFAULT_IGNORE_CASE,
            inputDelimiter != null ? inputDelimiter : DEFAULT_INPUT_DELIMITER,
            querqyParser.createParser());
}
 
Example 3
Source File: AbstractQuerqyDismaxQParserPlugin.java    From querqy with Apache License 2.0 4 votes vote down vote up
/**
 * Loads the whole {@link RewriteChain}s from the args and returns a list of
 * them.
 */
private RewriteChain loadRewriteChain(final ResourceLoader loader) throws IOException {

    final NamedList<?> chainConfig = (NamedList<?>) initArgs.get("rewriteChain");
    final List<RewriterFactory> factories = new ArrayList<>();

    if (chainConfig != null) {

        @SuppressWarnings("unchecked")
        final List<NamedList<?>> rewriterConfigs = (List<NamedList<?>>) chainConfig.getAll("rewriter");
        if (rewriterConfigs != null) {

            int count = 0;
            final Set<String> seenRewriterIds = new HashSet<>(rewriterConfigs.size());

            for (NamedList<?> config : rewriterConfigs) {

                final String className = (String) config.get("class");

                @SuppressWarnings("unchecked")
                final FactoryAdapter<RewriterFactory> factoryAdapter = loader
                        .newInstance(className, FactoryAdapter.class);

                final String idConf = (String) config.get("id");
                final String id = idConf == null
                        ? factoryAdapter.getCreatedClass().getClass().getName() + "#" + count : idConf;

                final RewriterFactory factory = factoryAdapter.createFactory(id, config, loader);
                if (!seenRewriterIds.add(factory.getRewriterId())) {
                    throw new IllegalStateException("Rewriter id is not unique: " + id);
                }

                factories.add(factory);
                count++;
            }
        }
    }

    return new RewriteChain(factories);

}
 
Example 4
Source File: SimpleCommonRulesRewriterFactory.java    From querqy with Apache License 2.0 4 votes vote down vote up
@Override
public RewriterFactory createFactory(final String id, final NamedList<?> args,
                                     final ResourceLoader resourceLoader) throws IOException {

    final String rulesResourceName = (String) args.get("rules");
    if (rulesResourceName == null) {
        throw new IllegalArgumentException("Property 'rules' not configured");
    }

    final Map<String, SelectionStrategyFactory> selectionStrategyFactories = new HashMap<>();

    final NamedList<?> selectionStrategyConfiguration = (NamedList<?>) args.get("rules.selectionStrategy");

    if (selectionStrategyConfiguration != null) {

        @SuppressWarnings("unchecked")
        final List<NamedList<?>> strategyConfigs = (List<NamedList<?>>) selectionStrategyConfiguration
                .getAll("strategy");

        if (strategyConfigs != null) {
            for (NamedList<?> config : strategyConfigs) {
                @SuppressWarnings("unchecked")
                final FactoryAdapter<SelectionStrategyFactory> factory = resourceLoader
                        .newInstance((String) config.get("class"), FactoryAdapter.class);
                final String strategyId = (String) config.get("id");
                if (selectionStrategyFactories.put(strategyId,
                        factory.createFactory(strategyId, config, resourceLoader)) != null) {
                    throw new IOException("Duplicate id in rules.selectionStrategy: " + id);
                }
            }
        }
    }


    final Boolean ignoreCase = args.getBooleanArg("ignoreCase");

    // querqy parser for queries that are part of the instructions in the
    // rules
    String rulesQuerqyParser = (String) args.get("querqyParser");
    QuerqyParserFactory querqyParser = null;
    if (rulesQuerqyParser != null) {
        rulesQuerqyParser = rulesQuerqyParser.trim();
        if (rulesQuerqyParser.length() > 0) {
            querqyParser = resourceLoader.newInstance(rulesQuerqyParser, QuerqyParserFactory.class);
        }
    }

    if (querqyParser == null) {
        querqyParser = new WhiteSpaceQuerqyParserFactory();
    }

    return new querqy.rewrite.commonrules.SimpleCommonRulesRewriterFactory(id,
            new InputStreamReader(resourceLoader.openResource(rulesResourceName), "UTF-8"), querqyParser,
            ignoreCase == null || ignoreCase, selectionStrategyFactories, DEFAULT_SELECTION_STRATEGY_FACTORY);
}
 
Example 5
Source File: MorphologyFilterFactory.java    From russianmorphology with Apache License 2.0 4 votes vote down vote up
public void inform(ResourceLoader loader) {

        String className = "org.apache.lucene.morphology." + language.toLowerCase() + "." + language + "LuceneMorphology";
        luceneMorphology = loader.newInstance(className, LuceneMorphology.class);
    }