Search in sources :

Example 6 with UpdateRequestHandler

use of org.apache.solr.handler.UpdateRequestHandler in project lucene-solr by apache.

the class SolrTestCaseJ4 method addDoc.

public static void addDoc(String doc, String updateRequestProcessorChain) throws Exception {
    Map<String, String[]> params = new HashMap<>();
    MultiMapSolrParams mmparams = new MultiMapSolrParams(params);
    params.put(UpdateParams.UPDATE_CHAIN, new String[] { updateRequestProcessorChain });
    SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(), (SolrParams) mmparams) {
    };
    UpdateRequestHandler handler = new UpdateRequestHandler();
    handler.init(null);
    ArrayList<ContentStream> streams = new ArrayList<>(2);
    streams.add(new ContentStreamBase.StringStream(doc));
    req.setContentStreams(streams);
    handler.handleRequestBody(req, new SolrQueryResponse());
    req.close();
}
Also used : ContentStream(org.apache.solr.common.util.ContentStream) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) MultiMapSolrParams(org.apache.solr.common.params.MultiMapSolrParams) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SolrQueryRequestBase(org.apache.solr.request.SolrQueryRequestBase) UpdateRequestHandler(org.apache.solr.handler.UpdateRequestHandler) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase)

Example 7 with UpdateRequestHandler

use of org.apache.solr.handler.UpdateRequestHandler in project lucene-solr by apache.

the class UpdateParamsTest method testUpdateProcessorParamDeprecationRemoved.

/**
   * Tests that only update.chain and not update.processor works (SOLR-2105)
   */
public void testUpdateProcessorParamDeprecationRemoved() throws Exception {
    SolrCore core = h.getCore();
    UpdateRequestHandler handler = new UpdateRequestHandler();
    handler.init(null);
    MapSolrParams params = new MapSolrParams(new HashMap<String, String>());
    params.getMap().put("update.processor", "nonexistant");
    // Add a single document
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrQueryRequestBase req = new SolrQueryRequestBase(core, params) {
    };
    // First check that the old param behaves as it should
    try {
        handler.handleRequestBody(req, rsp);
        assertTrue("Old param update.processor should not have any effect anymore", true);
    } catch (Exception e) {
        assertFalse("Got wrong exception while testing update.chain", e.getMessage().equals("unknown UpdateRequestProcessorChain: nonexistant"));
    }
    // Then check that the new param behaves correctly
    params.getMap().remove("update.processor");
    params.getMap().put(UpdateParams.UPDATE_CHAIN, "nonexistant");
    req.setParams(params);
    try {
        handler.handleRequestBody(req, rsp);
        assertFalse("Faulty update.chain parameter not causing an error - i.e. it is not detected", true);
    } catch (Exception e) {
        assertEquals("Got wrong exception while testing update.chain", e.getMessage(), "unknown UpdateRequestProcessorChain: nonexistant");
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) MapSolrParams(org.apache.solr.common.params.MapSolrParams) SolrCore(org.apache.solr.core.SolrCore) SolrQueryRequestBase(org.apache.solr.request.SolrQueryRequestBase) UpdateRequestHandler(org.apache.solr.handler.UpdateRequestHandler)

Example 8 with UpdateRequestHandler

use of org.apache.solr.handler.UpdateRequestHandler in project lucene-solr by apache.

the class SolrTestCaseJ4 method updateJ.

/** Send JSON update commands */
public static String updateJ(String json, SolrParams args) throws Exception {
    SolrCore core = h.getCore();
    if (args == null) {
        args = params("wt", "json", "indent", "true");
    } else {
        ModifiableSolrParams newArgs = new ModifiableSolrParams(args);
        if (newArgs.get("wt") == null)
            newArgs.set("wt", "json");
        if (newArgs.get("indent") == null)
            newArgs.set("indent", "true");
        args = newArgs;
    }
    DirectSolrConnection connection = new DirectSolrConnection(core);
    SolrRequestHandler handler = core.getRequestHandler("/update/json");
    if (handler == null) {
        handler = new UpdateRequestHandler();
        handler.init(null);
    }
    return connection.request(handler, args, json);
}
Also used : SolrCore(org.apache.solr.core.SolrCore) UpdateRequestHandler(org.apache.solr.handler.UpdateRequestHandler) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) DirectSolrConnection(org.apache.solr.servlet.DirectSolrConnection) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler)

Example 9 with UpdateRequestHandler

use of org.apache.solr.handler.UpdateRequestHandler 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 10 with UpdateRequestHandler

use of org.apache.solr.handler.UpdateRequestHandler in project lucene-solr by apache.

the class UniqFieldsUpdateProcessorFactoryTest method addDoc.

private void addDoc(String doc) throws Exception {
    Map<String, String[]> params = new HashMap<>();
    MultiMapSolrParams mmparams = new MultiMapSolrParams(params);
    params.put(UpdateParams.UPDATE_CHAIN, new String[] { "uniq-fields" });
    SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(), (SolrParams) mmparams) {
    };
    UpdateRequestHandler handler = new UpdateRequestHandler();
    handler.init(null);
    ArrayList<ContentStream> streams = new ArrayList<>(2);
    streams.add(new ContentStreamBase.StringStream(doc));
    req.setContentStreams(streams);
    handler.handleRequestBody(req, new SolrQueryResponse());
    req.close();
}
Also used : ContentStream(org.apache.solr.common.util.ContentStream) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) MultiMapSolrParams(org.apache.solr.common.params.MultiMapSolrParams) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SolrQueryRequestBase(org.apache.solr.request.SolrQueryRequestBase) UpdateRequestHandler(org.apache.solr.handler.UpdateRequestHandler) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase)

Aggregations

UpdateRequestHandler (org.apache.solr.handler.UpdateRequestHandler)10 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)8 SolrCore (org.apache.solr.core.SolrCore)7 SolrQueryRequestBase (org.apache.solr.request.SolrQueryRequestBase)7 MapSolrParams (org.apache.solr.common.params.MapSolrParams)6 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 MultiMapSolrParams (org.apache.solr.common.params.MultiMapSolrParams)3 ContentStream (org.apache.solr.common.util.ContentStream)3 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)2 Collections.singletonList (java.util.Collections.singletonList)1 Collections.singletonMap (java.util.Collections.singletonMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 BinaryRequestWriter (org.apache.solr.client.solrj.impl.BinaryRequestWriter)1 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)1