You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by dc...@yahoo.it on 2010/02/12 09:30:57 UTC
EmbeddedSolrServer vs CommonsHttpSolrServer
Hi all,
I am new to solr/solrj.
I correctly started up the server example given in the distribution (apache-solr-1.4.0\example\solr), populated the index with test data set, and successfully tested with http query string via browser (es. http://localhost:8983/solr/select/?indent=on&q=video&fl=name,id)
I am trying to set up solrj clients using both CommonsHttpSolrServer and EmbeddedSolrServer.
My examples are with single core configuration.
Here below the method used for CommonsHttpSolrServer initialization:
[code.1]
public SolrServer getCommonsHttpSolrServer() throws IOException, ParserConfigurationException, SAXException, SolrServerException {
String url = "http://localhost:8983/solr";
CommonsHttpSolrServer server = new CommonsHttpSolrServer(url);
server.setSoTimeout(1000); // socket read timeout
server.setConnectionTimeout(100);
server.setDefaultMaxConnectionsPerHost(100);
server.setMaxTotalConnections(100);
server.setFollowRedirects(false); // defaults to false
// allowCompression defaults to false.
// Server side must support gzip or deflate for this to have any effect.
server.setAllowCompression(true);
server.setMaxRetries(1); // defaults to 0. > 1 not recommended.
return server;
}
Here below the method used for EmbeddedSolrServer initialization (provided in the wiki section):
[code.2]
public SolrServer getEmbeddedSolrServer() throws IOException, ParserConfigurationException, SAXException, SolrServerException {
System.setProperty("solr.solr.home", "/WORKSPACE/bin/apache-solr-1.4.0/example/solr");
CoreContainer.Initializer initializer = new CoreContainer.Initializer();
CoreContainer coreContainer = initializer.initialize();
EmbeddedSolrServer server = new EmbeddedSolrServer(coreContainer, "");
return server;
}
Here below the common code used to query the server:
[code.3]
SolrServer server = mintIdxMain.getEmbeddedSolrServer();
//SolrServer server = mintIdxMain.getCommonsHttpSolrServer();
SolrQuery query = new SolrQuery("video");
QueryResponse rsp = server.query(query);
SolrDocumentList docs = rsp.getResults();
System.out.println("Found : " + docs.getNumFound());
System.out.println("Start : " + docs.getStart());
System.out.println("Max Score: " + docs.getMaxScore());
CommonsHttpSolrServer gives correct results whereas EmbeddedSolrServer gives always no results.
What's wrong with the initialization and/or the configuration of the
EmbeddedSolrServer?
CoreContainer.Initializer() seems to not recognize the single core from solrconfig.xml...
If I modify [code.2] with the following code, it seems to work.
I manually added only explicit Core Container registration.
Is [code.4] the correct way?
[code.4]
public SolrServer getEmbeddedSolrServer() throws IOException, ParserConfigurationException, SAXException, SolrServerException {
System.setProperty("solr.solr.home", "/WORKSPACE/bin/apache-solr-1.4.0/example/solr");
CoreContainer.Initializer initializer = new CoreContainer.Initializer();
CoreContainer coreContainer = initializer.initialize();
/* >>>>> */
SolrConfig solrConfig = new SolrConfig("/WORKSPACE/bin/apache-solr-1.4.0/example/solr", "solrconfig.xml", null);
IndexSchema indexSchema = new IndexSchema(solrConfig, "schema.xml", null);
CoreDescriptor coreDescriptor = new CoreDescriptor(coreContainer, "", solrConfig.getResourceLoader().getInstanceDir());
SolrCore core = new SolrCore(null, "/WORKSPACE/bin/apache-solr-1.4.0/example/solr/data", solrConfig, indexSchema, coreDescriptor);
coreContainer.register("", core, false);
/* <<<<< */
EmbeddedSolrServer server = new EmbeddedSolrServer(coreContainer, "");
return server;
}
Many thanks in advance for the support and the great work realized with all the lucene/solr projects.
Dino.
--