Index external content directly into Solr
From your java code, you can directly index your IdentifiableContentBean's. Also if these beans are for example populate by some external resource.
Assume you have the following bean / pojo populated by some external http call:
public class MyExternalBean implements IdentifiableContentBean {
private String identifier;
private String title;
private String summary;
private String description;
private Double price;
private String[] categories;
public String getIdentifier() {
return identifier;
}
public void setIdentifier(final String identifier) {
this.identifier = identifier;
}
@IndexField
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@IndexField
public String getSummary() {
return summary ;
}
public void setSummary(String summary) {
this.summary = summary;
}
@IndexField
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@IndexField
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
@IndexField
public String[] getCategories() {
return categories;
}
public void setCategories(String[] categories) {
this.categories = categories;
}
}
Now, assume you have some populated list of MyExternalBean objects. All it takes to index them is:
Index beans into Solr:
List<MyExternalBean> myExternalBeans = new ArrayList<MyExternalBean>();
// populate myExternalBeans
HippoSolrClient solrClient =
HstServices.getComponentManager().getComponent(
HippoSolrClient.class.getName(), "org.hippoecm.hst.solr");
try {
solrManager.getSolrServer().addBeans(gogreenBeans);
UpdateResponse commit = solrManager.getSolrServer().commit();
} catch (IOException e) {
//To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
} catch (SolrServerException e) {
//To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
}