Search in sources :

Example 6 with BinaryRequestWriter

use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project lucene-solr by apache.

the class SignatureUpdateProcessorFactoryTest method testNonStringFieldsValues.

@Test
public void testNonStringFieldsValues() throws Exception {
    this.chain = "dedupe-allfields";
    SolrCore core = h.getCore();
    UpdateRequestProcessorChain chained = core.getUpdateProcessingChain(chain);
    SignatureUpdateProcessorFactory factory = ((SignatureUpdateProcessorFactory) chained.getProcessors().get(0));
    factory.setEnabled(true);
    Map<String, String[]> params = new HashMap<>();
    MultiMapSolrParams mmparams = new MultiMapSolrParams(params);
    params.put(UpdateParams.UPDATE_CHAIN, new String[] { chain });
    UpdateRequest ureq = new UpdateRequest();
    {
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField("v_t", "same");
        doc.addField("weight", 1.0f);
        doc.addField("ints_is", 34);
        doc.addField("ints_is", 42);
        ureq.add(doc);
    }
    {
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField("v_t", "same");
        doc.addField("weight", 2.0f);
        doc.addField("ints_is", 42);
        doc.addField("ints_is", 66);
        ureq.add(doc);
    }
    {
        // A and B should have same sig as eachother
        // even though the particulars of how the the ints_is list are built
        SolrInputDocument docA = new SolrInputDocument();
        SolrInputDocument docB = new SolrInputDocument();
        UnusualList<Integer> ints = new UnusualList<>(3);
        for (int val : new int[] { 42, 66, 34 }) {
            docA.addField("ints_is", new Integer(val));
            ints.add(val);
        }
        docB.addField("ints_is", ints);
        for (SolrInputDocument doc : new SolrInputDocument[] { docA, docB }) {
            doc.addField("v_t", "same");
            doc.addField("weight", 3.0f);
            ureq.add(doc);
        }
    }
    {
        // now add another doc with the same values as A & B above, 
        // but diff ints_is collection (diff order)
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField("v_t", "same");
        doc.addField("weight", 3.0f);
        for (int val : new int[] { 66, 42, 34 }) {
            doc.addField("ints_is", new Integer(val));
        }
        ureq.add(doc);
    }
    ArrayList<ContentStream> streams = new ArrayList<>(2);
    streams.add(new BinaryRequestWriter().getContentStream(ureq));
    LocalSolrQueryRequest req = new LocalSolrQueryRequest(h.getCore(), mmparams);
    try {
        req.setContentStreams(streams);
        UpdateRequestHandler h = new UpdateRequestHandler();
        h.init(new NamedList());
        h.handleRequestBody(req, new SolrQueryResponse());
    } finally {
        req.close();
    }
    addDoc(commit());
    checkNumDocs(4);
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) MultiMapSolrParams(org.apache.solr.common.params.MultiMapSolrParams) HashMap(java.util.HashMap) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) SolrCore(org.apache.solr.core.SolrCore) NamedList(org.apache.solr.common.util.NamedList) ArrayList(java.util.ArrayList) BinaryRequestWriter(org.apache.solr.client.solrj.impl.BinaryRequestWriter) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrInputDocument(org.apache.solr.common.SolrInputDocument) ContentStream(org.apache.solr.common.util.ContentStream) UpdateRequestHandler(org.apache.solr.handler.UpdateRequestHandler) Test(org.junit.Test)

Example 7 with BinaryRequestWriter

use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project lucene-solr by apache.

the class SolrSchemalessExampleTest method createNewSolrClient.

@Override
public SolrClient createNewSolrClient() {
    try {
        // setup the server...
        String url = jetty.getBaseUrl().toString() + "/collection1";
        HttpSolrClient client = getHttpSolrClient(url);
        client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
        client.setUseMultiPartPost(random().nextBoolean());
        if (random().nextBoolean()) {
            client.setParser(new BinaryResponseParser());
            client.setRequestWriter(new BinaryRequestWriter());
        }
        return client;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) BinaryResponseParser(org.apache.solr.client.solrj.impl.BinaryResponseParser) BinaryRequestWriter(org.apache.solr.client.solrj.impl.BinaryRequestWriter)

Example 8 with BinaryRequestWriter

use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project lucene-solr by apache.

the class TestSolrJErrorHandling method testWithBinary.

@Test
public void testWithBinary() throws Exception {
    HttpSolrClient client = (HttpSolrClient) getSolrClient();
    client.setRequestWriter(new BinaryRequestWriter());
    // delete everything!
    client.deleteByQuery("*:*");
    doIt(client);
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) BinaryRequestWriter(org.apache.solr.client.solrj.impl.BinaryRequestWriter) Test(org.junit.Test)

Example 9 with BinaryRequestWriter

use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project lucene-solr by apache.

the class BinaryUpdateRequestHandlerTest method testRequestParams.

@Test
public void testRequestParams() throws Exception {
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id", "1");
    UpdateRequest ureq = new UpdateRequest();
    ureq.add(doc);
    ureq.setParam(UpdateParams.COMMIT_WITHIN, "100");
    ureq.setParam(UpdateParams.OVERWRITE, Boolean.toString(false));
    BinaryRequestWriter brw = new BinaryRequestWriter();
    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
    SolrQueryResponse rsp = new SolrQueryResponse();
    UpdateRequestHandler handler = new UpdateRequestHandler();
    handler.init(new NamedList());
    SolrQueryRequest req = req();
    ContentStreamLoader csl = handler.newLoader(req, p);
    csl.load(req, rsp, brw.getContentStream(ureq), p);
    AddUpdateCommand add = p.addCommands.get(0);
    System.out.println(add.solrDoc);
    assertEquals(false, add.overwrite);
    assertEquals(100, add.commitWithin);
    req.close();
}
Also used : ContentStreamLoader(org.apache.solr.handler.loader.ContentStreamLoader) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) NamedList(org.apache.solr.common.util.NamedList) BinaryRequestWriter(org.apache.solr.client.solrj.impl.BinaryRequestWriter) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) Test(org.junit.Test)

Example 10 with BinaryRequestWriter

use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project lucene-solr by apache.

the class StreamingSolrClients method getSolrClient.

public synchronized SolrClient getSolrClient(final SolrCmdDistributor.Req req) {
    String url = getFullUrl(req.node.getUrl());
    ConcurrentUpdateSolrClient client = solrClients.get(url);
    if (client == null) {
        // NOTE: increasing to more than 1 threadCount for the client could cause updates to be reordered
        // on a greater scale since the current behavior is to only increase the number of connections/Runners when
        // the queue is more than half full.
        client = new ErrorReportingConcurrentUpdateSolrClient(url, httpClient, 100, runnerCount, updateExecutor, true, req);
        // minimize connections created
        client.setPollQueueTime(Integer.MAX_VALUE);
        client.setParser(new BinaryResponseParser());
        client.setRequestWriter(new BinaryRequestWriter());
        Set<String> queryParams = new HashSet<>(2);
        queryParams.add(DistributedUpdateProcessor.DISTRIB_FROM);
        queryParams.add(DistributingUpdateProcessorFactory.DISTRIB_UPDATE_PARAM);
        client.setQueryParams(queryParams);
        solrClients.put(url, client);
    }
    return client;
}
Also used : BinaryResponseParser(org.apache.solr.client.solrj.impl.BinaryResponseParser) BinaryRequestWriter(org.apache.solr.client.solrj.impl.BinaryRequestWriter) ConcurrentUpdateSolrClient(org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient) HashSet(java.util.HashSet)

Aggregations

BinaryRequestWriter (org.apache.solr.client.solrj.impl.BinaryRequestWriter)14 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)7 Test (org.junit.Test)5 BinaryResponseParser (org.apache.solr.client.solrj.impl.BinaryResponseParser)4 ArrayList (java.util.ArrayList)2 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)2 CommonsHttpSolrServer (org.apache.solr.client.solrj.impl.CommonsHttpSolrServer)2 ConcurrentUpdateSolrClient (org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient)2 Krb5HttpClientBuilder (org.apache.solr.client.solrj.impl.Krb5HttpClientBuilder)2 SolrHttpClientBuilder (org.apache.solr.client.solrj.impl.SolrHttpClientBuilder)2 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)2 SolrInputDocument (org.apache.solr.common.SolrInputDocument)2 NamedList (org.apache.solr.common.util.NamedList)2 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 SolrClient (org.apache.solr.client.solrj.SolrClient)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1