Moved code to apache-solrj from spring-data-solr, updated code to 6.4.0 solrj, fixed dependencies in both modules (#1196)
* Solr w Apache SolrJ * Solr w Apache SolrJ * updated test names and moved add to @before method * create apache-solrj module, moved code from spring-data-solr
This commit is contained in:
committed by
KevinGilmore
parent
fda362f79d
commit
3371c9047a
@@ -0,0 +1,43 @@
|
||||
package com.baeldung.solrjava;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.solr.client.solrj.SolrServerException;
|
||||
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
||||
import org.apache.solr.client.solrj.impl.XMLResponseParser;
|
||||
import org.apache.solr.common.SolrInputDocument;
|
||||
|
||||
public class SolrJavaIntegration {
|
||||
|
||||
private HttpSolrClient solrClient;
|
||||
|
||||
public SolrJavaIntegration(String clientUrl) {
|
||||
|
||||
solrClient = new HttpSolrClient.Builder(clientUrl).build();
|
||||
solrClient.setParser(new XMLResponseParser());
|
||||
}
|
||||
|
||||
public void addSolrDocument(String documentId, String itemName, String itemPrice) throws SolrServerException, IOException {
|
||||
|
||||
SolrInputDocument document = new SolrInputDocument();
|
||||
document.addField("id", documentId);
|
||||
document.addField("name", itemName);
|
||||
document.addField("price", itemPrice);
|
||||
solrClient.add(document);
|
||||
solrClient.commit();
|
||||
}
|
||||
|
||||
public void deleteSolrDocument(String documentId) throws SolrServerException, IOException {
|
||||
|
||||
solrClient.deleteById(documentId);
|
||||
solrClient.commit();
|
||||
}
|
||||
|
||||
protected HttpSolrClient getSolrClient() {
|
||||
return solrClient;
|
||||
}
|
||||
|
||||
protected void setSolrClient(HttpSolrClient solrClient) {
|
||||
this.solrClient = solrClient;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user