Search in sources :

Example 56 with QueryRequest

use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.

the class TestReplicaProperties method addProperty.

private void addProperty(CloudSolrClient client, String... paramsIn) throws IOException, SolrServerException {
    assertTrue("paramsIn must be an even multiple of 2, it is: " + paramsIn.length, (paramsIn.length % 2) == 0);
    ModifiableSolrParams params = new ModifiableSolrParams();
    for (int idx = 0; idx < paramsIn.length; idx += 2) {
        params.set(paramsIn[idx], paramsIn[idx + 1]);
    }
    QueryRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");
    client.request(request);
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 57 with QueryRequest

use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.

the class TestSmileRequest method testDistribJsonRequest.

@Test
public void testDistribJsonRequest() throws Exception {
    initServers();
    SolrTestCaseHS.Client client = servers.getClient(random().nextInt());
    client.tester = new SolrTestCaseHS.Client.Tester() {

        @Override
        public void assertJQ(SolrClient client, SolrParams args, String... tests) throws Exception {
            ((HttpSolrClient) client).setParser(SmileResponseParser.inst);
            QueryRequest query = new QueryRequest(args);
            String path = args.get("qt");
            if (path != null) {
                query.setPath(path);
            }
            NamedList<Object> rsp = client.request(query);
            Map m = rsp.asMap(5);
            String jsonStr = Utils.toJSONString(m);
            SolrTestCaseHS.matchJSON(jsonStr, tests);
        }
    };
    client.queryDefaults().set("shards", servers.getShards());
    TestJsonRequest.doJsonRequest(client);
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) NamedList(org.apache.solr.common.util.NamedList) SolrParams(org.apache.solr.common.params.SolrParams) SolrTestCaseHS(org.apache.solr.SolrTestCaseHS) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) Map(java.util.Map) IOException(java.io.IOException) Test(org.junit.Test) SmileWriterTest(org.apache.solr.response.SmileWriterTest)

Example 58 with QueryRequest

use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.

the class TimeSeriesStream method open.

public void open() throws IOException {
    if (cache != null) {
        cloudSolrClient = cache.getCloudSolrClient(zkHost);
    } else {
        cloudSolrClient = new Builder().withZkHost(zkHost).build();
    }
    String json = getJsonFacetString(field, metrics, start, end, gap);
    ModifiableSolrParams paramsLoc = new ModifiableSolrParams(params);
    paramsLoc.set("json.facet", json);
    paramsLoc.set("rows", "0");
    QueryRequest request = new QueryRequest(paramsLoc);
    try {
        NamedList response = cloudSolrClient.request(request, collection);
        getTuples(response, field, metrics);
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) Builder(org.apache.solr.client.solrj.impl.CloudSolrClient.Builder) IOException(java.io.IOException) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) IOException(java.io.IOException)

Example 59 with QueryRequest

use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.

the class TestRemoteStreaming method testQtUpdateFails.

/** SOLR-3161
   * Technically stream.body isn't remote streaming, but there wasn't a better place for this test method. */
@Test(expected = SolrException.class)
public void testQtUpdateFails() throws SolrServerException, IOException {
    SolrQuery query = new SolrQuery();
    //for anything
    query.setQuery("*:*");
    query.add("echoHandler", "true");
    //sneaky sneaky
    query.add("qt", "/update");
    query.add("stream.body", "<delete><query>*:*</query></delete>");
    QueryRequest queryRequest = new QueryRequest(query) {

        @Override
        public String getPath() {
            //don't let superclass substitute qt for the path
            return "/select";
        }
    };
    QueryResponse rsp = queryRequest.process(getSolrClient());
    //!! should *fail* above for security purposes
    String handler = (String) rsp.getHeader().get("handler");
    System.out.println(handler);
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 60 with QueryRequest

use of org.apache.solr.client.solrj.request.QueryRequest in project metron by apache.

the class MetronSolrClient method getListCollectionsRequest.

public QueryRequest getListCollectionsRequest() {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set(SolrConstants.REQUEST_ACTION, CollectionParams.CollectionAction.LIST.name());
    QueryRequest request = new QueryRequest(params);
    request.setPath(SolrConstants.REQUEST_COLLECTIONS_PATH);
    return request;
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)112 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)77 SolrRequest (org.apache.solr.client.solrj.SolrRequest)35 NamedList (org.apache.solr.common.util.NamedList)35 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)29 Test (org.junit.Test)28 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)21 ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)17 Map (java.util.Map)17 SolrQuery (org.apache.solr.client.solrj.SolrQuery)17 IOException (java.io.IOException)16 SolrException (org.apache.solr.common.SolrException)15 SolrInputDocument (org.apache.solr.common.SolrInputDocument)14 SolrClient (org.apache.solr.client.solrj.SolrClient)13 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)12 List (java.util.List)11 SolrServerException (org.apache.solr.client.solrj.SolrServerException)8 RemoteSolrException (org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException)8 SolrDocumentList (org.apache.solr.common.SolrDocumentList)8