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

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

Introduction

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

Prototype

public QueryResponse query(SolrParams params) throws SolrServerException, IOException 

Source Link

Document

Performs a query to the Solr server

Usage

From source file:org.apache.coheigea.bigdata.solr.SolrCloudTest.java

License:Apache License

@Test
public void testAddAndQuery() throws Exception {
    CloudSolrClient cloudSolrClient = server.getSolrClient();

    cloudSolrClient.setDefaultCollection("docs");

    // Add document
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("title", "Title of Doc");
    doc.addField("content", "Test Content");

    cloudSolrClient.add(doc);// www.j a va2 s  . c  o m
    cloudSolrClient.commit();

    ModifiableSolrParams params = new ModifiableSolrParams();
    // Test it's uploaded
    params.set("q", "*");
    QueryResponse qResp = cloudSolrClient.query(params);

    SolrDocumentList foundDocs = qResp.getResults();
    Assert.assertEquals(1, foundDocs.getNumFound());

    SolrDocument foundDoc = foundDocs.get(0);
    Assert.assertEquals("Title of Doc", foundDoc.getFieldValue("title"));
}

From source file:org.apache.metron.solr.integration.components.SolrComponent.java

License:Apache License

public List<Map<String, Object>> getAllIndexedDocs(String collection) {
    List<Map<String, Object>> docs = new ArrayList<>();
    CloudSolrClient solr = miniSolrCloudCluster.getSolrClient();
    solr.setDefaultCollection(collection);
    SolrQuery parameters = new SolrQuery();
    parameters.set("q", "*:*");
    try {//from   ww  w.  ja va  2  s  . co m
        solr.commit();
        QueryResponse response = solr.query(parameters);
        for (SolrDocument solrDocument : response.getResults()) {
            docs.add(solrDocument);
        }
    } catch (SolrServerException | IOException e) {
        e.printStackTrace();
    }
    return docs;
}