Search in sources :

Example 1 with SolrResourceLoader

use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.

the class TestModelManager method test.

@Test
public void test() throws Exception {
    final SolrResourceLoader loader = new SolrResourceLoader(tmpSolrHome.toPath());
    final RestManager.Registry registry = loader.getManagedResourceRegistry();
    assertNotNull("Expected a non-null RestManager.Registry from the SolrResourceLoader!", registry);
    final String resourceId = "/schema/fstore1";
    registry.registerManagedResource(resourceId, ManagedFeatureStore.class, new LTRQParserPlugin());
    final String resourceId2 = "/schema/mstore1";
    registry.registerManagedResource(resourceId2, ManagedModelStore.class, new LTRQParserPlugin());
    final NamedList<String> initArgs = new NamedList<>();
    final RestManager restManager = new RestManager();
    restManager.init(loader, initArgs, new ManagedResourceStorage.InMemoryStorageIO());
    final ManagedResource res = restManager.getManagedResource(resourceId);
    assertTrue(res instanceof ManagedFeatureStore);
    assertEquals(res.getResourceId(), resourceId);
}
Also used : SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) NamedList(org.apache.solr.common.util.NamedList) LTRQParserPlugin(org.apache.solr.ltr.search.LTRQParserPlugin) ManagedResourceStorage(org.apache.solr.rest.ManagedResourceStorage) RestManager(org.apache.solr.rest.RestManager) ManagedResource(org.apache.solr.rest.ManagedResource) Test(org.junit.Test)

Example 2 with SolrResourceLoader

use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.

the class SpellCheckComponent method addSpellChecker.

private boolean addSpellChecker(SolrCore core, boolean hasDefault, NamedList spellchecker) {
    String className = (String) spellchecker.get("classname");
    if (className == null)
        className = (String) spellchecker.get("class");
    // so that it's 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 && !hasDefault) {
                hasDefault = true;
            } else if (isDefault && hasDefault) {
                throw new RuntimeException("More than one dictionary is missing name.");
            }
            spellCheckers.put(dictionary, checker);
        } else {
            if (!hasDefault) {
                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);
    }
    return hasDefault;
}
Also used : SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) ConjunctionSolrSpellChecker(org.apache.solr.spelling.ConjunctionSolrSpellChecker) SolrSpellChecker(org.apache.solr.spelling.SolrSpellChecker)

Example 3 with SolrResourceLoader

use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.

the class SchemaManager method getFreshManagedSchema.

public static ManagedIndexSchema getFreshManagedSchema(SolrCore core) throws IOException, KeeperException, InterruptedException {
    SolrResourceLoader resourceLoader = core.getResourceLoader();
    String name = core.getLatestSchema().getResourceName();
    if (resourceLoader instanceof ZkSolrResourceLoader) {
        InputStream in = resourceLoader.openResource(name);
        if (in instanceof ZkSolrResourceLoader.ZkByteArrayInputStream) {
            int version = ((ZkSolrResourceLoader.ZkByteArrayInputStream) in).getStat().getVersion();
            log.info("managed schema loaded . version : {} ", version);
            return new ManagedIndexSchema(core.getSolrConfig(), name, new InputSource(in), true, name, version, core.getLatestSchema().getSchemaUpdateLock());
        } else {
            return (ManagedIndexSchema) core.getLatestSchema();
        }
    } else {
        return (ManagedIndexSchema) core.getLatestSchema();
    }
}
Also used : ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader)

Example 4 with SolrResourceLoader

use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.

the class ManagedIndexSchemaFactory method upgradeToManagedSchema.

/**
   * Persist the managed schema and rename the non-managed schema 
   * by appending {@link #UPGRADED_SCHEMA_EXTENSION}.
   *
   * Failure to rename the non-managed schema will be logged as a warning,
   * and no exception will be thrown.
   */
private void upgradeToManagedSchema() {
    SolrResourceLoader loader = config.getResourceLoader();
    if (loader instanceof ZkSolrResourceLoader) {
        zkUgradeToManagedSchema();
    } else {
        // Configs are not on ZooKeeper
        // Only create it - don't update it if it already exists
        schema.persistManagedSchema(true);
        if (resourceName.equals(managedSchemaResourceName)) {
            log.info("On upgrading to managed schema, did not rename non-managed schema '" + resourceName + "' because it's the same as the managed schema's name.");
        } else {
            final File nonManagedSchemaFile = locateConfigFile(resourceName);
            if (null == nonManagedSchemaFile) {
                // Don't throw an exception for failure to rename the non-managed schema
                log.warn("On upgrading to managed schema, did not rename non-managed schema " + resourceName + " because it's neither an absolute file " + "nor under SolrConfig.getConfigDir() or the current directory." + "  PLEASE REMOVE THIS FILE.");
            } else {
                File upgradedSchemaFile = new File(nonManagedSchemaFile + UPGRADED_SCHEMA_EXTENSION);
                if (nonManagedSchemaFile.renameTo(upgradedSchemaFile)) {
                    // Set the resource name to the managed schema so that the CoreAdminHandler returns a findable filename 
                    schema.setResourceName(managedSchemaResourceName);
                    log.info("After upgrading to managed schema, renamed the non-managed schema " + nonManagedSchemaFile + " to " + upgradedSchemaFile);
                } else {
                    // Don't throw an exception for failure to rename the non-managed schema
                    log.warn("Can't rename " + nonManagedSchemaFile.toString() + " to " + upgradedSchemaFile.toString() + " - PLEASE REMOVE THIS FILE.");
                }
            }
        }
    }
}
Also used : SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) File(java.io.File)

Example 5 with SolrResourceLoader

use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.

the class ClusteringComponent method inform.

@SuppressWarnings("unchecked")
@Override
public void inform(SolrCore core) {
    if (initParams != null) {
        log.info("Initializing Clustering Engines");
        // Our target list of engines, split into search-results and document clustering.
        SolrResourceLoader loader = core.getResourceLoader();
        for (Map.Entry<String, Object> entry : initParams) {
            if ("engine".equals(entry.getKey())) {
                NamedList<Object> engineInitParams = (NamedList<Object>) entry.getValue();
                Boolean optional = engineInitParams.getBooleanArg("optional");
                optional = (optional == null ? Boolean.FALSE : optional);
                String engineClassName = StringUtils.defaultIfBlank((String) engineInitParams.get("classname"), CarrotClusteringEngine.class.getName());
                // Instantiate the clustering engine and split to appropriate map. 
                final ClusteringEngine engine = loader.newInstance(engineClassName, ClusteringEngine.class);
                final String name = StringUtils.defaultIfBlank(engine.init(engineInitParams, core), "");
                if (!engine.isAvailable()) {
                    if (optional) {
                        log.info("Optional clustering engine not available: " + name);
                    } else {
                        throw new SolrException(ErrorCode.SERVER_ERROR, "A required clustering engine failed to initialize, check the logs: " + name);
                    }
                }
                final ClusteringEngine previousEntry;
                if (engine instanceof SearchClusteringEngine) {
                    previousEntry = searchClusteringEngines.put(name, (SearchClusteringEngine) engine);
                } else if (engine instanceof DocumentClusteringEngine) {
                    previousEntry = documentClusteringEngines.put(name, (DocumentClusteringEngine) engine);
                } else {
                    log.warn("Unknown type of a clustering engine for class: " + engineClassName);
                    continue;
                }
                if (previousEntry != null) {
                    log.warn("Duplicate clustering engine component named '" + name + "'.");
                }
            }
        }
        // Set up the default engine key for both types of engines.
        setupDefaultEngine("search results clustering", searchClusteringEngines);
        setupDefaultEngine("document clustering", documentClusteringEngines);
        log.info("Finished Initializing Clustering Engines");
    }
}
Also used : NamedList(org.apache.solr.common.util.NamedList) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) CarrotClusteringEngine(org.apache.solr.handler.clustering.carrot2.CarrotClusteringEngine) CarrotClusteringEngine(org.apache.solr.handler.clustering.carrot2.CarrotClusteringEngine) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SolrException(org.apache.solr.common.SolrException)

Aggregations

SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)54 Test (org.junit.Test)18 File (java.io.File)11 InputStream (java.io.InputStream)11 NamedList (org.apache.solr.common.util.NamedList)10 SolrException (org.apache.solr.common.SolrException)9 NodeConfig (org.apache.solr.core.NodeConfig)9 Path (java.nio.file.Path)8 CoreContainer (org.apache.solr.core.CoreContainer)8 InputStreamReader (java.io.InputStreamReader)7 Reader (java.io.Reader)7 Map (java.util.Map)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 XMLResponseParser (org.apache.solr.client.solrj.impl.XMLResponseParser)5 SolrCore (org.apache.solr.core.SolrCore)5 ArrayList (java.util.ArrayList)4 ZkSolrResourceLoader (org.apache.solr.cloud.ZkSolrResourceLoader)4 SolrConfig (org.apache.solr.core.SolrConfig)4