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

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

Introduction

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

Prototype

public UpdateResponse commit() throws SolrServerException, IOException 

Source Link

Document

Performs an explicit commit, causing pending documents to be committed for indexing waitFlush=true and waitSearcher=true to be inline with the defaults for plain HTTP access <p> Be very careful when triggering commits from the client side.

Usage

From source file:fr.jetoile.hadoopunit.component.SolrBootstrapTest.java

License:Apache License

private void injectIntoSolr(EmbeddedSolrServer client) throws SolrServerException, IOException {
    for (int i = 0; i < 1000; ++i) {
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField("cat", "book");
        doc.addField("id", "book-" + i);
        doc.addField("name", "The Legend of the Hobbit part " + i);
        client.add(doc);//from  ww w  . j a v  a  2  s  .  c  o m
        if (i % 100 == 0)
            client.commit(); // periodically flush
    }
    client.commit();
}

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 ww w .j  a  v a  2  s .  c  om*/
    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();
}