这是我的代码,我很累创建CoreContainer
File home = new File( "C:/Program Files/Apache Software Foundation/Tomcat 7.0/webapps/solr" );
//home directory
File f = new File(home, "solr.xml" );
CoreContainer container = new CoreContainer();
container.load( "C:/Program Files/Apache Software Foundation/Tomcat 7.0/webapps/solr", f );
EmbeddedSolrServer server = new EmbeddedSolrServer( container, "collection1" );
SolrQuery query = new SolrQuery("*:*");
QueryResponse rsp = server.query(query);
SolrDocumentList docs = rsp.getResults();
Iterator<SolrDocument> i = docs.iterator();
while (i.hasNext()) {
System.out.println(i.next().toString());
}
我solr.xml文件如下。
<solr>
<solrcloud>
<str name="host">${host:}</str>
<int name="hostPort">${jetty.port:9000}</int>
<str name="hostContext">${hostContext:solr}</str>
<int name="zkClientTimeout">${zkClientTimeout:30000}</int>
<bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>
</solrcloud>
<shardHandlerFactory name="shardHandlerFactory"
class="HttpShardHandlerFactory">
<int name="socketTimeout">${socketTimeout:0}</int>
<int name="connTimeout">${connTimeout:0}</int>
</shardHandlerFactory>
</solr>
solrconfig.xml中的文件是一样的默认
当我运行此我得到SolrServerException等,也不会产生EmbeddedSolrServer
INFO: New CoreContainer: solrHome=solr/ instance=6751353
Apr 03, 2014 4:46:05 PM org.apache.solr.core.SolrResourceLoader <init>
INFO: Solr home set to 'C:/Program Files/Apache Software Foundation/Tomcat 7.0/webapps/solr\'
org.apache.solr.client.solrj.SolrServerException: Error executing query
at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:95)
at org.apache.solr.client.solrj.SolrServer.query(SolrServer.java:118)
at com.hl.model.em.main(em.java:101)
Caused by: org.apache.solr.common.SolrException: No such core: collection1
at org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.request(EmbeddedSolrServer.java:104)
at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:89)
... 2 more