Example usage for org.apache.solr.schema IndexSchemaFactory buildIndexSchema

List of usage examples for org.apache.solr.schema IndexSchemaFactory buildIndexSchema

Introduction

In this page you can find the example usage for org.apache.solr.schema IndexSchemaFactory buildIndexSchema.

Prototype

public static IndexSchema buildIndexSchema(String resourceName, SolrConfig config) 

Source Link

Document

Instantiates the configured schema factory, then calls create on it.

Usage

From source file:org.alfresco.solr.SolrCoreTestBase.java

License:Open Source License

@Before
public void setUpBase() throws Exception {
    Properties properties = new Properties();
    properties.put("solr.tests.maxBufferedDocs", "1000");
    properties.put("solr.tests.maxIndexingThreads", "10");
    properties.put("solr.tests.ramBufferSizeMB", "1024");
    properties.put("solr.tests.mergeScheduler", "org.apache.lucene.index.ConcurrentMergeScheduler");
    properties.put("solr.tests.mergePolicy", "org.apache.lucene.index.TieredMergePolicy");

    coreContainer = new CoreContainer(TEST_FILES_LOCATION);
    resourceLoader = new SolrResourceLoader(Paths.get(TEST_SOLR_CONF), null, properties);
    SolrConfig solrConfig = new SolrConfig(resourceLoader, "solrconfig-afts.xml", null);
    IndexSchemaFactory.buildIndexSchema("schema-afts.xml", solrConfig);
    coreDescriptor = new CoreDescriptor(coreContainer, "name", Paths.get(TEST_SOLR_COLLECTION));

    // SolrCore is final, we can't mock with mockito
    core = new SolrCore("name", null, solrConfig, null, null, coreDescriptor, null, null, null);

    FieldUtils.writeField(core, "updateHandler", updateHandler, true);
    FieldUtils.writeField(core, "resourceLoader", resourceLoader, true);
    infoRegistry = new HashMap<String, SolrInfoMBean>();
    FieldUtils.writeField(core, "infoRegistry", infoRegistry, true);
    reqHandlers = new RequestHandlers(core);
    reqHandlers.register("/select", selectRequestHandler);
    reqHandlers.register("/afts", aftsRequestHandler);
    FieldUtils.writeField(core, "reqHandlers", reqHandlers, true);

    Map<String, UpdateRequestProcessorChain> map = new HashMap<>();
    List<UpdateRequestProcessorFactory> factories = new ArrayList<UpdateRequestProcessorFactory>(1);
    factories.add(runUpdateProcessorFactory);
    when(runUpdateProcessorFactory.getInstance(any(SolrQueryRequest.class), any(SolrQueryResponse.class),
            any(UpdateRequestProcessor.class))).thenReturn(processor);
    UpdateRequestProcessorChain def = new UpdateRequestProcessorChain(factories, core);
    map.put(null, def);/*  w w w  .  j  av a  2  s . c om*/
    map.put("", def);
    FieldUtils.writeField(core, "updateProcessorChains", map, true);
}

From source file:org.kitesdk.morphline.solr.SolrLocator.java

License:Apache License

public IndexSchema getIndexSchema() {
    if (context instanceof SolrMorphlineContext) {
        IndexSchema schema = ((SolrMorphlineContext) context).getIndexSchema();
        if (schema != null) {
            validateSchema(schema);//  ww w. j a  v a  2s  . co m
            return schema;
        }
    }

    File downloadedSolrHomeDir = null;
    try {
        // If solrHomeDir isn't defined and zkHost and collectionName are defined 
        // then download schema.xml and solrconfig.xml, etc from zk and use that as solrHomeDir
        String mySolrHomeDir = solrHomeDir;
        if (solrHomeDir == null || solrHomeDir.length() == 0) {
            if (zkHost == null || zkHost.length() == 0) {
                // TODO: implement download from solrUrl if specified
                throw new MorphlineCompilationException(
                        "Downloading a Solr schema requires either parameter 'solrHomeDir' or parameters 'zkHost' and 'collection'",
                        config);
            }
            if (collectionName == null || collectionName.length() == 0) {
                throw new MorphlineCompilationException(
                        "Parameter 'zkHost' requires that you also pass parameter 'collection'", config);
            }
            ZooKeeperDownloader zki = new ZooKeeperDownloader();
            SolrZkClient zkClient = zki.getZkClient(zkHost);
            try {
                String configName = zki.readConfigName(zkClient, collectionName);
                downloadedSolrHomeDir = Files.createTempDir();
                downloadedSolrHomeDir = zki.downloadConfigDir(zkClient, configName, downloadedSolrHomeDir);
                mySolrHomeDir = downloadedSolrHomeDir.getAbsolutePath();
            } catch (KeeperException e) {
                throw new MorphlineCompilationException("Cannot download schema.xml from ZooKeeper", config, e);
            } catch (InterruptedException e) {
                throw new MorphlineCompilationException("Cannot download schema.xml from ZooKeeper", config, e);
            } catch (IOException e) {
                throw new MorphlineCompilationException("Cannot download schema.xml from ZooKeeper", config, e);
            } finally {
                zkClient.close();
            }
        }

        LOG.debug("SolrLocator loading IndexSchema from dir {}", mySolrHomeDir);
        try {
            SolrResourceLoader loader = new SolrResourceLoader(mySolrHomeDir);
            SolrConfig solrConfig = new SolrConfig(loader, "solrconfig.xml", null);

            IndexSchema schema = IndexSchemaFactory.buildIndexSchema("schema.xml", solrConfig);
            validateSchema(schema);
            return schema;
        } catch (ParserConfigurationException e) {
            throw new MorphlineRuntimeException(e);
        } catch (IOException e) {
            throw new MorphlineRuntimeException(e);
        } catch (SAXException e) {
            throw new MorphlineRuntimeException(e);
        }
    } finally {
        if (downloadedSolrHomeDir != null) {
            try {
                FileUtils.deleteDirectory(downloadedSolrHomeDir);
            } catch (IOException e) {
                LOG.warn("Cannot delete tmp directory", e);
            }
        }
    }
}