Example usage for org.apache.solr.client.solrj.impl CloudSolrClient commit

List of usage examples for org.apache.solr.client.solrj.impl CloudSolrClient commit

Introduction

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

Prototype

public UpdateResponse commit(String collection) 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.SolrCloudBootstrapTest.java

License:Apache License

@Test
public void solrCloudShouldStart() throws IOException, SolrServerException, KeeperException,
        InterruptedException, NotFoundServiceException {

    String collectionName = configuration.getString(SolrCloudBootstrap.SOLR_COLLECTION_NAME);

    //        String zkHostString = configuration.getString(Config.ZOOKEEPER_HOST_KEY) + ":" + configuration.getInt(Config.ZOOKEEPER_PORT_KEY);
    //        CloudSolrClient client = new CloudSolrClient(zkHostString);
    CloudSolrClient client = ((SolrCloudBootstrap) HadoopBootstrap.INSTANCE.getService(Component.SOLRCLOUD))
            .getClient();//from   ww  w  . ja v  a  2  s  . c  om

    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(collectionName, doc);
        if (i % 100 == 0)
            client.commit(collectionName); // periodically flush
    }
    client.commit("collection1");

    SolrDocument collection1 = client.getById(collectionName, "book-1");

    assertNotNull(collection1);

    assertThat(collection1.getFieldValue("name")).isEqualTo("The Legend of the Hobbit part 1");

    client.close();
}

From source file:fr.jetoile.hadoopunit.integrationtest.IntegrationBootstrapTest.java

License:Apache License

@Test
public void solrCloudShouldStart()
        throws IOException, SolrServerException, KeeperException, InterruptedException {

    String collectionName = configuration.getString(SolrCloudBootstrap.SOLR_COLLECTION_NAME);

    String zkHostString = configuration.getString(Config.ZOOKEEPER_HOST_KEY) + ":"
            + configuration.getInt(Config.ZOOKEEPER_PORT_KEY);
    CloudSolrClient client = new CloudSolrClient(zkHostString);

    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(collectionName, doc);
        if (i % 100 == 0)
            client.commit(collectionName); // periodically flush
    }/*from  w w  w.  ja va2 s  . com*/
    client.commit("collection1");

    SolrDocument collection1 = client.getById(collectionName, "book-1");

    assertNotNull(collection1);

    assertThat(collection1.getFieldValue("name")).isEqualTo("The Legend of the Hobbit part 1");

    client.close();
}