Skip to content

Instantly share code, notes, and snippets.

@nautical
Created March 29, 2014 18:21
Show Gist options
  • Save nautical/9859452 to your computer and use it in GitHub Desktop.
Save nautical/9859452 to your computer and use it in GitHub Desktop.
EmbeddedSolrExample.java
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.common.SolrInputDocument;
public class EmbeddedSolrExample{
static CoreContainer container;
static EmbeddedSolrServer server;
public static void main(String[] args) throws Exception{
String solrDir = "/Users/TheRoot/Downloads/solr-4.7.0/example/solr/";
container = new CoreContainer(solrDir);
container.load();
server = new EmbeddedSolrServer(container, "collection1");
}
public static String query(String qstring){
String output = null;
ModifiableSolrParams solrParams = new ModifiableSolrParams();
System.out.println(qstring);
solrParams.add(CommonParams.Q, qstring);
QueryResponse queryResponse = null;
try {
queryResponse = server.query(solrParams);
} catch (SolrServerException e) {
e.printStackTrace();
}
for (SolrDocument document : queryResponse.getResults()) {
output += (document.getFieldValueMap().toString());
}
System.out.println(output);
return output;
}
public static void entervalues(String Category,int Id, String Name) throws Exception{
SolrInputDocument doc = new SolrInputDocument();
doc.addField("cat", Category);
doc.addField("id", Id);
doc.addField("name", Name);
server.add(doc);
server.commit(); // commit slows down .. do it after ~N inserts .. Seperate it
}
public static void close(){
server.shutdown();
container.shutdown();
}
}
@amirensi
Copy link

please it's urgent,can any one help me !!!!!!!!!!

@djavaphp
Copy link

I am also facing same issue now. have you resoled it? I have separate module which search from solr and call that jar dependency in MVC project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment