1

这是我的代码:

File home = new File(System.getProperty("solr.solr.home"));
        CoreContainer container = new CoreContainer(home.getAbsolutePath());
        CoreAdminRequest.Create create = new CoreAdminRequest.Create();
        create.setCoreName("newCoreName");
        create.setCoreNodeName("newCoreName");
        create.setAction(CoreAdminAction.CREATE);
        create.setInstanceDir(home.getAbsolutePath()); 
        create.process(new EmbeddedSolrServer(container, ""));

当我运行它时,我得到“没有这样的核心:”“”异常。如果我将其更改为:

create.process(new EmbeddedSolrServer(container, "newCoreName"));

我得到“没有这样的核心:“newCoreName””异常。

请帮我...

4

1 回答 1

1

我们发现创建核心需要两件事:1)必须有一个默认核心 2)应该创建用于新核心的目录。

solr.xml 如下:

<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="false">
  <cores defaultCoreName="empty" adminPath="/admin/cores">
    <core instanceDir="empty/" name="empty"/>
  </cores>
</solr>

要创建新核心,请执行以下操作:

File home = new File(scfg.getIndexHome());
File solr = new File(home, "solr.xml");
String corename = "newcore";
CoreContainer container = new CoreContainer(home, solr);
//create the directory
File f = new File(home, corename); f.mkdirs();
SolrServer server = new EmbeddedSolrServer(container, "empty"); //default
//create the core
CoreAdminRequest.createCore(corename, corename, server, "solrconfig.xml", "schema.xml");
//persist it in the solr.xml
CoreAdminRequest.persist("solr.xml", server);
SolrServer servernew = new EmbeddedSolrServer(container, corename);
于 2013-10-08T10:24:43.913 回答