Example usage for org.apache.solr.core SolrCore getSolrConfig

List of usage examples for org.apache.solr.core SolrCore getSolrConfig

Introduction

In this page you can find the example usage for org.apache.solr.core SolrCore getSolrConfig.

Prototype

public SolrConfig getSolrConfig() 

Source Link

Document

Gets the configuration object used by this core instance.

Usage

From source file:com.o19s.solr.swan.highlight.SwanHighlightComponent.java

License:Apache License

@Override
public void inform(SolrCore core) {
    SolrHighlighter highlighter;//from  w  ww  . j  a  v a2s . c om
    List<PluginInfo> children = info.getChildren("highlighting");
    if (children.isEmpty()) {
        PluginInfo pluginInfo = core.getSolrConfig().getPluginInfo(SolrHighlighter.class.getName()); //TODO deprecated configuration remove later
        if (pluginInfo != null) {
            highlighter = core.createInitInstance(pluginInfo, SolrHighlighter.class, null,
                    DefaultSolrHighlighter.class.getName());
            highlighter.initalize(core.getSolrConfig());
        } else {
            DefaultSolrHighlighter defHighlighter = new DefaultSolrHighlighter(core);
            defHighlighter.init(PluginInfo.EMPTY_INFO);
        }
    } else {
        core.createInitInstance(children.get(0), SolrHighlighter.class, null,
                DefaultSolrHighlighter.class.getName());
    }
}

From source file:jp.sf.fess.solr.plugin.update.SuggestTranslogUpdateHandlerFilter.java

License:Apache License

protected void startup() {
    final SolrCore core = updateHandler.getSolrCore();
    final UpdateLog ulog = updateHandler.getUpdateLog();

    //TODO replay?
    TransactionLogUtil.clearSuggestTransactionLog(ulog.getLogDir());

    final SuggestUpdateConfig config = SolrConfigUtil.getUpdateHandlerConfig(core.getSolrConfig());
    final List<SuggestFieldInfo> suggestFieldInfoList = SolrConfigUtil.getSuggestFieldInfoList(config);
    suggestUpdateController = new SuggestUpdateController(config, suggestFieldInfoList,
            core.getResourceLoader());//ww w.  j av  a  2  s .  co m
    if (config.getLabelFields() != null) {
        for (final String label : config.getLabelFields()) {
            suggestUpdateController.addLabelFieldName(label);
        }
    }
    if (config.getRoleFields() != null) {
        for (final String role : config.getRoleFields()) {
            suggestUpdateController.addRoleFieldName(role);
        }
    }
    suggestUpdateController.setLimitDocumentQueuingNum(2);
    suggestUpdateController.start();

}

From source file:lux.solr.SolrIndexConfig.java

License:Mozilla Public License

public static SolrIndexConfig registerIndexConfiguration(SolrCore core) {
    // Read the init args from the LuxUpdateProcessorFactory's configuration
    NamedList<?> initArgs = null;//ww w.ja  v  a 2s  . c  o m
    for (PluginInfo info : core.getSolrConfig().getPluginInfos(UpdateRequestProcessorChain.class.getName())) {
        // FIXME: if there are multiple processors, we prefer the 'default' one, otherwise
        // just take the last?  This is a  bit lame, but it provides back-compat.  We should at least
        // raise a warning if this is ambiguous
        initArgs = info.initArgs;
        if ("true".equals(info.attributes.get("default"))) {
            break;
        }
    }
    String configName = SolrIndexConfig.class.getName();
    SolrInfoMBean configBean = core.getInfoRegistry().get(configName);
    SolrIndexConfig indexConfig;
    if (configBean != null) {
        indexConfig = (SolrIndexConfig) configBean;
    } else {
        int options = (INDEX_PATHS | INDEX_FULLTEXT | STORE_DOCUMENT | SOLR);
        indexConfig = SolrIndexConfig.makeIndexConfiguration(options, initArgs, configName);
        indexConfig.inform(core);
        core.getInfoRegistry().put(configName, indexConfig);
    }
    return indexConfig;
}

From source file:org.dice.solrenhancements.spellchecker.DiceSpellCheckComponent.java

License:Apache License

@Override
public void inform(SolrCore core) {
    if (initParams != null) {
        LOG.info("Initializing spell checkers");
        boolean hasDefault = false;
        for (int i = 0; i < initParams.size(); i++) {
            if (initParams.getName(i).equals("spellchecker")) {
                NamedList spellchecker = (NamedList) initParams.getVal(i);
                String className = (String) spellchecker.get("classname");
                // TODO: this is a little bit sneaky: warn if class isnt supplied
                // so that its mandatory in a future release?
                if (className == null)
                    className = IndexBasedSpellChecker.class.getName();
                SolrResourceLoader loader = core.getResourceLoader();
                SolrSpellChecker checker = loader.newInstance(className, SolrSpellChecker.class);
                if (checker != null) {
                    String dictionary = checker.init(spellchecker, core);
                    if (dictionary != null) {
                        boolean isDefault = dictionary.equals(SolrSpellChecker.DEFAULT_DICTIONARY_NAME);
                        if (isDefault == true && hasDefault == false) {
                            hasDefault = true;
                        } else if (isDefault == true && hasDefault == true) {
                            throw new RuntimeException("More than one dictionary is missing name.");
                        }//from w w w.j a  va 2s  .c  o m
                        spellCheckers.put(dictionary, checker);
                    } else {
                        if (hasDefault == false) {
                            spellCheckers.put(SolrSpellChecker.DEFAULT_DICTIONARY_NAME, checker);
                            hasDefault = true;
                        } else {
                            throw new RuntimeException("More than one dictionary is missing name.");
                        }
                    }
                    // Register event listeners for this SpellChecker
                    core.registerFirstSearcherListener(new SpellCheckerListener(core, checker, false, false));
                    boolean buildOnCommit = Boolean.parseBoolean((String) spellchecker.get("buildOnCommit"));
                    boolean buildOnOptimize = Boolean
                            .parseBoolean((String) spellchecker.get("buildOnOptimize"));
                    if (buildOnCommit || buildOnOptimize) {
                        LOG.info("Registering newSearcher listener for spellchecker: "
                                + checker.getDictionaryName());
                        core.registerNewSearcherListener(
                                new SpellCheckerListener(core, checker, buildOnCommit, buildOnOptimize));
                    }
                } else {
                    throw new RuntimeException("Can't load spell checker: " + className);
                }
            }
        }

        Map<String, QueryConverter> queryConverters = new HashMap<String, QueryConverter>();
        core.initPlugins(queryConverters, QueryConverter.class);

        //ensure that there is at least one query converter defined
        if (queryConverters.size() == 0) {
            LOG.info("No queryConverter defined, using default converter");
            queryConverters.put("queryConverter", new SpellingQueryConverter());
        }

        //there should only be one
        if (queryConverters.size() == 1) {
            queryConverter = queryConverters.values().iterator().next();
            IndexSchema schema = core.getLatestSchema();
            String fieldTypeName = (String) initParams.get("queryAnalyzerFieldType");
            FieldType fieldType = schema.getFieldTypes().get(fieldTypeName);
            Analyzer analyzer = fieldType == null
                    ? new WhitespaceAnalyzer(core.getSolrConfig().luceneMatchVersion)
                    : fieldType.getQueryAnalyzer();
            //TODO: There's got to be a better way!  Where's Spring when you need it?
            queryConverter.setAnalyzer(analyzer);
        }
    }
}

From source file:solandra.SolandraIndexWriter.java

License:Apache License

public SolandraIndexWriter(SolrCore core) {
    super(core);// w  w  w.  j  a  v a2  s  . c om

    cassandraHost = core.getSolrConfig().get("updateHandler/str[@name='cassandraHost']");

    if (cassandraHost == null || cassandraHost.length() == 0)
        throw new SolrException(ErrorCode.NOT_FOUND,
                "<str name=\"cassandraHost\">localhost</str>  tag required");

    cassandraPort = core.getSolrConfig().getInt("updateHandler/int[@name='cassandraPort']");

    if (cassandraPort == null)
        throw new SolrException(ErrorCode.NOT_FOUND, "<int name=\"cassandraPort\">9160</int>  tag required");

    cassandraFramed = core.getSolrConfig().getBool("updateHandler/bool[@name='cassandraFramed']", false);

    try {
        writer = new lucandra.IndexWriter(core.getSchema().getSchemaName(),
                CassandraUtils.createRobustConnection(cassandraHost, cassandraPort, cassandraFramed, true));

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}