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']");
}
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();
}
}
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);
}
}
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();
}
}
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;
}
}
}
Aggregations