Embedded Solr
November 25th, 2010
Comments
Article Relevancy
Apache Solr 1.4.x
Apache Solr 1.4.x
A java application running in a JVM can use the EmbeddedSolrServer to host Solr in the same JVM.
Following snippet shows how to use it:
public class EmbeddedServerExplorer {
public static void main(String[] args) {
try {
// Set "solr.solr.home" to the directory under which /conf and /data are present.
System.setProperty("solr.solr.home", "solr");
CoreContainer.Initializer initializer = new CoreContainer.Initializer();
CoreContainer coreContainer = initializer.initialize();
EmbeddedSolrServer server = new EmbeddedSolrServer(coreContainer, "");
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "embeddedDoc1");
doc.addField("name", "test embedded server");
server.add(doc);
server.commit();
coreContainer.shutdown();
} catch (Exception e) {
e.printStackTrace();
}
}
}





