Search in sources :

Example 1 with DeleteUpdateCommand

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

the class SolrWriter method doDeleteAll.

@Override
public void doDeleteAll() {
    try {
        DeleteUpdateCommand deleteCommand = new DeleteUpdateCommand(req);
        deleteCommand.query = "*:*";
        processor.processDelete(deleteCommand);
    } catch (IOException e) {
        throw new DataImportHandlerException(DataImportHandlerException.SEVERE, "Exception in full dump while deleting all documents.", e);
    }
}
Also used : DeleteUpdateCommand(org.apache.solr.update.DeleteUpdateCommand)

Example 2 with DeleteUpdateCommand

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

the class SolrWriter method deleteDoc.

@Override
public void deleteDoc(Object id) {
    try {
        log.info("Deleting document: " + id);
        DeleteUpdateCommand delCmd = new DeleteUpdateCommand(req);
        delCmd.setId(id.toString());
        processor.processDelete(delCmd);
    } catch (IOException e) {
        log.error("Exception while deleteing: " + id, e);
    }
}
Also used : DeleteUpdateCommand(org.apache.solr.update.DeleteUpdateCommand)

Example 3 with DeleteUpdateCommand

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

the class JsonLoaderTest method testParsing.

public void testParsing() throws Exception {
    SolrQueryRequest req = req();
    SolrQueryResponse rsp = new SolrQueryResponse();
    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
    JsonLoader loader = new JsonLoader();
    loader.load(req, rsp, new ContentStreamBase.StringStream(input), p);
    assertEquals(2, p.addCommands.size());
    AddUpdateCommand add = p.addCommands.get(0);
    SolrInputDocument d = add.solrDoc;
    SolrInputField f = d.getField("boosted");
    assertEquals(2, f.getValues().size());
    // 
    add = p.addCommands.get(1);
    d = add.solrDoc;
    f = d.getField("f1");
    assertEquals(2, f.getValues().size());
    assertEquals(false, add.overwrite);
    assertEquals(0, d.getField("f2").getValueCount());
    // parse the commit commands
    assertEquals(2, p.commitCommands.size());
    CommitUpdateCommand commit = p.commitCommands.get(0);
    assertFalse(commit.optimize);
    assertTrue(commit.waitSearcher);
    assertTrue(commit.openSearcher);
    commit = p.commitCommands.get(1);
    assertTrue(commit.optimize);
    assertFalse(commit.waitSearcher);
    assertFalse(commit.openSearcher);
    // DELETE COMMANDS
    assertEquals(4, p.deleteCommands.size());
    DeleteUpdateCommand delete = p.deleteCommands.get(0);
    assertEquals(delete.id, "ID");
    assertEquals(delete.query, null);
    assertEquals(delete.commitWithin, -1);
    delete = p.deleteCommands.get(1);
    assertEquals(delete.id, "ID");
    assertEquals(delete.query, null);
    assertEquals(delete.commitWithin, 500);
    delete = p.deleteCommands.get(2);
    assertEquals(delete.id, null);
    assertEquals(delete.query, "QUERY");
    assertEquals(delete.commitWithin, -1);
    delete = p.deleteCommands.get(3);
    assertEquals(delete.id, null);
    assertEquals(delete.query, "QUERY");
    assertEquals(delete.commitWithin, 500);
    // ROLLBACK COMMANDS
    assertEquals(1, p.rollbackCommands.size());
    req.close();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) SolrInputField(org.apache.solr.common.SolrInputField) JsonLoader(org.apache.solr.handler.loader.JsonLoader) DeleteUpdateCommand(org.apache.solr.update.DeleteUpdateCommand) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase)

Example 4 with DeleteUpdateCommand

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

the class DocExpirationUpdateProcessorFactoryTest method testAutomaticDeletes.

public void testAutomaticDeletes() throws Exception {
    // get a handle on our recorder
    UpdateRequestProcessorChain chain = h.getCore().getUpdateProcessingChain("scheduled-delete");
    assertNotNull(chain);
    List<UpdateRequestProcessorFactory> factories = chain.getProcessors();
    assertEquals("did number of processors configured in chain get changed?", 5, factories.size());
    assertTrue("Expected [1] RecordingUpdateProcessorFactory: " + factories.get(1).getClass(), factories.get(1) instanceof RecordingUpdateProcessorFactory);
    RecordingUpdateProcessorFactory recorder = (RecordingUpdateProcessorFactory) factories.get(1);
    try {
        recorder.startRecording();
        // more then one iter to verify it's recurring
        final int numItersToCheck = 1 + RANDOM_MULTIPLIER;
        for (int i = 0; i < numItersToCheck; i++) {
            UpdateCommand tmp;
            // be generous in how long we wait, some jenkins machines are slooooow
            tmp = recorder.commandQueue.poll(30, TimeUnit.SECONDS);
            // we can be confident in the order because DocExpirationUpdateProcessorFactory
            // uses the same request for both the delete & the commit -- and both 
            // RecordingUpdateProcessorFactory's getInstance & startRecording methods are 
            // synchronized.  So it should not be possible to start recording in the 
            // middle of the two commands
            assertTrue("expected DeleteUpdateCommand: " + tmp.getClass(), tmp instanceof DeleteUpdateCommand);
            DeleteUpdateCommand delete = (DeleteUpdateCommand) tmp;
            assertFalse(delete.isDeleteById());
            assertNotNull(delete.getQuery());
            assertTrue(delete.getQuery(), delete.getQuery().startsWith("{!cache=false}eXpField_tdt:[* TO "));
            // commit should be immediately after the delete
            tmp = recorder.commandQueue.poll(5, TimeUnit.SECONDS);
            assertTrue("expected CommitUpdateCommand: " + tmp.getClass(), tmp instanceof CommitUpdateCommand);
            CommitUpdateCommand commit = (CommitUpdateCommand) tmp;
            assertTrue(commit.softCommit);
            assertTrue(commit.openSearcher);
        }
    } finally {
        recorder.stopRecording();
    }
}
Also used : UpdateRequestProcessorFactory(org.apache.solr.update.processor.UpdateRequestProcessorFactory) DeleteUpdateCommand(org.apache.solr.update.DeleteUpdateCommand) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand) UpdateCommand(org.apache.solr.update.UpdateCommand) UpdateRequestProcessorChain(org.apache.solr.update.processor.UpdateRequestProcessorChain) DeleteUpdateCommand(org.apache.solr.update.DeleteUpdateCommand) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand)

Example 5 with DeleteUpdateCommand

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

the class UpdateProcessorTestBase method processDeleteById.

protected void processDeleteById(final String chain, String id) 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());
    DeleteUpdateCommand cmd = new DeleteUpdateCommand(req);
    cmd.setId(id);
    UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
    try {
        processor.processDelete(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) DeleteUpdateCommand(org.apache.solr.update.DeleteUpdateCommand) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

DeleteUpdateCommand (org.apache.solr.update.DeleteUpdateCommand)18 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)7 SolrInputDocument (org.apache.solr.common.SolrInputDocument)5 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)5 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)5 CommitUpdateCommand (org.apache.solr.update.CommitUpdateCommand)4 SolrException (org.apache.solr.common.SolrException)3 SolrInputField (org.apache.solr.common.SolrInputField)3 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)3 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)3 UpdateCommand (org.apache.solr.update.UpdateCommand)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 SolrParams (org.apache.solr.common.params.SolrParams)2 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)2 NamedList (org.apache.solr.common.util.NamedList)2 JsonLoader (org.apache.solr.handler.loader.JsonLoader)2 BufferingRequestProcessor (org.apache.solr.update.processor.BufferingRequestProcessor)2 UpdateRequestProcessor (org.apache.solr.update.processor.UpdateRequestProcessor)2 IntArrayList (com.carrotsearch.hppc.IntArrayList)1