Example usage for org.apache.solr.client.solrj.embedded EmbeddedSolrServer addBean

List of usage examples for org.apache.solr.client.solrj.embedded EmbeddedSolrServer addBean

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.embedded EmbeddedSolrServer addBean.

Prototype

public UpdateResponse addBean(Object obj) throws IOException, SolrServerException 

Source Link

Document

Adds a single bean The bean is converted to a SolrInputDocument by the client's org.apache.solr.client.solrj.beans.DocumentObjectBinder

Usage

From source file:it.seralf.solrbook.client.java.EmbeddedSolrExample.java

License:Apache License

public static void main(String[] args) throws Exception {

    // NOTE: we can override this configuration, passing a valid slr home from command line
    System.setProperty("solr.solr.home", "solr-home");

    CoreContainer container = new CoreContainer();
    container.load();//from   w w  w  .  j av  a  2 s  .c  o  m
    EmbeddedSolrServer server = new EmbeddedSolrServer(container, "arts");

    // delete all documents
    server.deleteByQuery("*:*");

    Artist doc = new Artist("http://en.wikipedia.org/wiki/Leonardo_da_Vinci", "Leonardo Da Vinci", "Vinci",
            "Florence");
    server.addBean(doc);

    server.commit();

    QueryResponse rsp = server.query(new SolrQuery("leonardo"), METHOD.GET);

    SolrDocumentList oo = rsp.getResults();
    for (SolrDocument d : oo) {
        for (String field : d.getFieldNames()) {
            System.out.printf("%s = %s\n", field, d.getFieldValue(field));
        }
    }

    server.shutdown();
}