Embedded Solr Server using Java

by Balasundaram

Hi

The Solr server can be used without using the http by using the Embedded Solr server.In this we use the java api to

connect to the solr server.The program for the Embedded Solr is as follows

System.setProperty(“solr.solr.home”, “/home/user1/apache-solr-3.4.0/example/solr”);
CoreContainer.Initializer initializer = new CoreContainer.Initializer();
CoreContainer coreContainer = initializer.initialize();
EmbeddedSolrServer server = new EmbeddedSolrServer(coreContainer, “”);
SolrQuery solrQuery = new  SolrQuery();
solrQuery.setParam(“fl”,”id,score”);
solrQuery.setParam(“q”,string);
solrQuery.setQuery(“id:bala”);
QueryResponse rsp = server.query(solrQuery);
SolrDocumentList docs = rsp.getResults();
System.out.println(docs);

 

By using this we can actually search the indexed document in the Solr which is in a single core.
The set param is used to pass the query string as the parameter and get the required results
based on it.

 

thanks

bala

Advertisements