Added more indexing/delete/query examples to code (#1251)

* 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

* More examples for indexing,delete,and query for solrj

* More examples for indexing,delete,and query for solrj
This commit is contained in:
Nancy Bosecker
2017-02-27 20:26:30 -08:00
committed by KevinGilmore
parent 29882a1f06
commit 1bfc944c5a
3 changed files with 114 additions and 7 deletions
@@ -0,0 +1,44 @@
package com.baeldung.solrjava;
import org.apache.solr.client.solrj.beans.Field;
public class ProductBean {
String id;
String name;
String price;
public ProductBean(String id, String name, String price) {
super();
this.id = id;
this.name = name;
this.price = price;
}
public String getId() {
return id;
}
@Field("id")
protected void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
@Field("name")
protected void setName(String name) {
this.name = name;
}
public String getPrice() {
return price;
}
@Field("price")
protected void setPrice(String price) {
this.price = price;
}
}
@@ -17,6 +17,12 @@ public class SolrJavaIntegration {
solrClient.setParser(new XMLResponseParser());
}
public void addProductBean(ProductBean pBean) throws IOException, SolrServerException {
solrClient.addBean(pBean);
solrClient.commit();
}
public void addSolrDocument(String documentId, String itemName, String itemPrice) throws SolrServerException, IOException {
SolrInputDocument document = new SolrInputDocument();
@@ -27,12 +33,18 @@ public class SolrJavaIntegration {
solrClient.commit();
}
public void deleteSolrDocument(String documentId) throws SolrServerException, IOException {
public void deleteSolrDocumentById(String documentId) throws SolrServerException, IOException {
solrClient.deleteById(documentId);
solrClient.commit();
}
public void deleteSolrDocumentByQuery(String query) throws SolrServerException, IOException {
solrClient.deleteByQuery(query);
solrClient.commit();
}
protected HttpSolrClient getSolrClient() {
return solrClient;
}
@@ -40,4 +52,5 @@ public class SolrJavaIntegration {
protected void setSolrClient(HttpSolrClient solrClient) {
this.solrClient = solrClient;
}
}