Search in sources :

Example 11 with CommitUpdateCommand

use of org.apache.solr.update.CommitUpdateCommand in project lucene-solr by apache.

the class TestLazyCores method checkSearch.

// This is a little weak. I'm not sure how to test that lazy core2 is loaded automagically. The getCore
// will, of course, load it.
private void checkSearch(SolrCore core) throws IOException {
    addLazy(core, "id", "0");
    addLazy(core, "id", "1", "v_t", "Hello Dude");
    addLazy(core, "id", "2", "v_t", "Hello Yonik");
    addLazy(core, "id", "3", "v_s", "{!literal}");
    addLazy(core, "id", "4", "v_s", "other stuff");
    addLazy(core, "id", "5", "v_f", "3.14159");
    addLazy(core, "id", "6", "v_f", "8983");
    SolrQueryRequest req = makeReq(core);
    CommitUpdateCommand cmtCmd = new CommitUpdateCommand(req, false);
    core.getUpdateHandler().commit(cmtCmd);
    // Just get a couple of searches to work!
    assertQ("test prefix query", makeReq(core, "q", "{!prefix f=v_t}hel", "wt", "xml"), "//result[@numFound='2']");
    assertQ("test raw query", makeReq(core, "q", "{!raw f=v_t}hello", "wt", "xml"), "//result[@numFound='2']");
    // no analysis is done, so these should match nothing
    assertQ("test raw query", makeReq(core, "q", "{!raw f=v_t}Hello", "wt", "xml"), "//result[@numFound='0']");
    assertQ("test raw query", makeReq(core, "q", "{!raw f=v_f}1.5", "wt", "xml"), "//result[@numFound='0']");
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand)

Example 12 with CommitUpdateCommand

use of org.apache.solr.update.CommitUpdateCommand in project lucene-solr by apache.

the class UpdateProcessorTestBase method processCommit.

protected void processCommit(final String chain) throws IOException {
    SolrCore core = h.getCore();
    UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
    assertNotNull("No Chain named: " + chain, pc);
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
    CommitUpdateCommand cmd = new CommitUpdateCommand(req, false);
    UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
    try {
        processor.processCommit(cmd);
    } finally {
        req.close();
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 13 with CommitUpdateCommand

use of org.apache.solr.update.CommitUpdateCommand in project lucene-solr by apache.

the class SolrWriter method commit.

@Override
public void commit(boolean optimize) {
    try {
        CommitUpdateCommand commit = new CommitUpdateCommand(req, optimize);
        processor.processCommit(commit);
    } catch (Exception e) {
        log.error("Exception while solr commit.", e);
    }
}
Also used : CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand) SolrException(org.apache.solr.common.SolrException)

Example 14 with CommitUpdateCommand

use of org.apache.solr.update.CommitUpdateCommand in project lucene-solr by apache.

the class BlobHandler method indexMap.

public static void indexMap(SolrQueryRequest req, SolrQueryResponse rsp, Map<String, Object> doc) throws IOException {
    SolrInputDocument solrDoc = new SolrInputDocument();
    for (Map.Entry<String, Object> e : doc.entrySet()) solrDoc.addField(e.getKey(), e.getValue());
    UpdateRequestProcessorChain processorChain = req.getCore().getUpdateProcessorChain(req.getParams());
    try (UpdateRequestProcessor processor = processorChain.createProcessor(req, rsp)) {
        AddUpdateCommand cmd = new AddUpdateCommand(req);
        cmd.solrDoc = solrDoc;
        log.info("Adding doc: " + doc);
        processor.processAdd(cmd);
        log.info("committing doc: " + doc);
        processor.processCommit(new CommitUpdateCommand(req, false));
        processor.finish();
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) UpdateRequestProcessorChain(org.apache.solr.update.processor.UpdateRequestProcessorChain) UpdateRequestProcessor(org.apache.solr.update.processor.UpdateRequestProcessor) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand) Map(java.util.Map) Utils.makeMap(org.apache.solr.common.util.Utils.makeMap) Collections.singletonMap(java.util.Collections.singletonMap) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand)

Example 15 with CommitUpdateCommand

use of org.apache.solr.update.CommitUpdateCommand in project lucene-solr by apache.

the class XMLLoader method processUpdate.

/**
   * @since solr 1.2
   */
void processUpdate(SolrQueryRequest req, UpdateRequestProcessor processor, XMLStreamReader parser) throws XMLStreamException, IOException, FactoryConfigurationError {
    AddUpdateCommand addCmd = null;
    SolrParams params = req.getParams();
    while (true) {
        int event = parser.next();
        switch(event) {
            case XMLStreamConstants.END_DOCUMENT:
                parser.close();
                return;
            case XMLStreamConstants.START_ELEMENT:
                String currTag = parser.getLocalName();
                if (currTag.equals(UpdateRequestHandler.ADD)) {
                    log.trace("SolrCore.update(add)");
                    addCmd = new AddUpdateCommand(req);
                    // First look for commitWithin parameter on the request, will be overwritten for individual <add>'s
                    addCmd.commitWithin = params.getInt(UpdateParams.COMMIT_WITHIN, -1);
                    addCmd.overwrite = params.getBool(UpdateParams.OVERWRITE, true);
                    for (int i = 0; i < parser.getAttributeCount(); i++) {
                        String attrName = parser.getAttributeLocalName(i);
                        String attrVal = parser.getAttributeValue(i);
                        if (UpdateRequestHandler.OVERWRITE.equals(attrName)) {
                            addCmd.overwrite = StrUtils.parseBoolean(attrVal);
                        } else if (UpdateRequestHandler.COMMIT_WITHIN.equals(attrName)) {
                            addCmd.commitWithin = Integer.parseInt(attrVal);
                        } else {
                            log.warn("XML element <add> has invalid XML attr: " + attrName);
                        }
                    }
                } else if ("doc".equals(currTag)) {
                    if (addCmd != null) {
                        log.trace("adding doc...");
                        addCmd.clear();
                        addCmd.solrDoc = readDoc(parser);
                        processor.processAdd(addCmd);
                    } else {
                        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unexpected <doc> tag without an <add> tag surrounding it.");
                    }
                } else if (UpdateRequestHandler.COMMIT.equals(currTag) || UpdateRequestHandler.OPTIMIZE.equals(currTag)) {
                    log.trace("parsing " + currTag);
                    CommitUpdateCommand cmd = new CommitUpdateCommand(req, UpdateRequestHandler.OPTIMIZE.equals(currTag));
                    ModifiableSolrParams mp = new ModifiableSolrParams();
                    for (int i = 0; i < parser.getAttributeCount(); i++) {
                        String attrName = parser.getAttributeLocalName(i);
                        String attrVal = parser.getAttributeValue(i);
                        mp.set(attrName, attrVal);
                    }
                    RequestHandlerUtils.validateCommitParams(mp);
                    // default to the normal request params for commit options
                    SolrParams p = SolrParams.wrapDefaults(mp, req.getParams());
                    RequestHandlerUtils.updateCommit(cmd, p);
                    processor.processCommit(cmd);
                } else // end commit
                if (UpdateRequestHandler.ROLLBACK.equals(currTag)) {
                    log.trace("parsing rollback");
                    RollbackUpdateCommand cmd = new RollbackUpdateCommand(req);
                    processor.processRollback(cmd);
                } else // end rollback
                if (UpdateRequestHandler.DELETE.equals(currTag)) {
                    log.trace("parsing delete");
                    processDelete(req, processor, parser);
                }
                // end delete
                break;
        }
    }
}
Also used : RollbackUpdateCommand(org.apache.solr.update.RollbackUpdateCommand) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) SolrException(org.apache.solr.common.SolrException) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

CommitUpdateCommand (org.apache.solr.update.CommitUpdateCommand)21 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)12 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)12 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)8 SolrException (org.apache.solr.common.SolrException)7 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)6 SolrCore (org.apache.solr.core.SolrCore)5 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)5 UpdateRequestProcessor (org.apache.solr.update.processor.UpdateRequestProcessor)4 Date (java.util.Date)3 SolrInputDocument (org.apache.solr.common.SolrInputDocument)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ExecutionException (java.util.concurrent.ExecutionException)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 QName (org.alfresco.service.namespace.QName)2 SolrServletRequest (org.alfresco.solr.AbstractAlfrescoSolrTests.SolrServletRequest)2 SolrServerException (org.apache.solr.client.solrj.SolrServerException)2