Search in sources :

Example 41 with AddUpdateCommand

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

the class AtomicUpdateProcessorFactoryTest method testWrongAtomicOpPassed.

public void testWrongAtomicOpPassed() throws Exception {
    AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams().add("processor", "Atomic").add("Atomic.cat", "delete").add("commit", "true")));
    try {
        AtomicUpdateProcessorFactory factory = new AtomicUpdateProcessorFactory();
        factory.inform(h.getCore());
        factory.getInstance(cmd.getReq(), new SolrQueryResponse(), null).processAdd(cmd);
    } catch (SolrException e) {
        assertEquals("Unexpected param(s) for AtomicUpdateProcessor, invalid atomic op passed: 'delete'", e.getMessage());
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrException(org.apache.solr.common.SolrException)

Example 42 with AddUpdateCommand

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

the class AtomicUpdateProcessorFactoryTest method testNoUniqueIdPassed.

public void testNoUniqueIdPassed() throws Exception {
    //TODO
    AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams().add("processor", "Atomic").add("Atomic.cat", "add").add("commit", "true")));
    cmd.solrDoc = new SolrInputDocument();
    cmd.solrDoc.addField("title", 1);
    try {
        AtomicUpdateProcessorFactory factory = new AtomicUpdateProcessorFactory();
        factory.inform(h.getCore());
        factory.getInstance(cmd.getReq(), new SolrQueryResponse(), null).processAdd(cmd);
    } catch (SolrException e) {
        assertEquals("Document passed with no unique field: 'id'", e.getMessage());
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrException(org.apache.solr.common.SolrException)

Example 43 with AddUpdateCommand

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

the class DefaultValueUpdateProcessorTest method processAdd.

/**
   * Runs a document through the specified chain, and returns the final 
   * document used when the chain is completed (NOTE: some chains may 
   * modify the document in place
   */
SolrInputDocument processAdd(final String chain, final SolrInputDocument docIn) 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());
    try {
        SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
        AddUpdateCommand cmd = new AddUpdateCommand(req);
        cmd.solrDoc = docIn;
        UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
        processor.processAdd(cmd);
        return cmd.solrDoc;
    } finally {
        SolrRequestInfo.clearRequestInfo();
        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) UpdateRequestProcessorChain(org.apache.solr.update.processor.UpdateRequestProcessorChain) UpdateRequestProcessor(org.apache.solr.update.processor.UpdateRequestProcessor) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 44 with AddUpdateCommand

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

the class ClassificationUpdateProcessorTest method bayesMultiClass_boostFieldsMaxOutputClasses2_shouldAssignMax2Classes.

@Test
public void bayesMultiClass_boostFieldsMaxOutputClasses2_shouldAssignMax2Classes() throws Exception {
    UpdateRequestProcessor mockProcessor = mock(UpdateRequestProcessor.class);
    prepareTrainedIndexMultiClass();
    AddUpdateCommand update = new AddUpdateCommand(req());
    SolrInputDocument unseenDocument1 = sdoc(ID, "10", TITLE, "word4 word4 word4", CONTENT, "word2 word2 ", AUTHOR, "unseenAuthor");
    update.solrDoc = unseenDocument1;
    ClassificationUpdateProcessorParams params = initParams(ClassificationUpdateProcessorFactory.Algorithm.BAYES);
    params.setInputFieldNames(new String[] { TITLE + "^1.5", CONTENT + "^0.5", AUTHOR + "^2.5" });
    params.setMaxPredictedClasses(2);
    updateProcessorToTest = new ClassificationUpdateProcessor(params, mockProcessor, reader, req().getSchema());
    updateProcessorToTest.processAdd(update);
    ArrayList<Object> assignedClasses = (ArrayList) unseenDocument1.getFieldValues(TRAINING_CLASS);
    assertThat(assignedClasses.size(), is(2));
    assertThat(assignedClasses.get(0), is("class4"));
    assertThat(assignedClasses.get(1), is("class6"));
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) ArrayList(java.util.ArrayList) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) Test(org.junit.Test)

Example 45 with AddUpdateCommand

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

the class ClassificationUpdateProcessorTest method knnMultiClass_boostFieldsMaxOutputClasses2_shouldAssignMax2Classes.

@Test
public void knnMultiClass_boostFieldsMaxOutputClasses2_shouldAssignMax2Classes() throws Exception {
    UpdateRequestProcessor mockProcessor = mock(UpdateRequestProcessor.class);
    prepareTrainedIndexMultiClass();
    AddUpdateCommand update = new AddUpdateCommand(req());
    SolrInputDocument unseenDocument1 = sdoc(ID, "10", TITLE, "word4 word4 word4", CONTENT, "word2 word2 ", AUTHOR, "unseenAuthor");
    update.solrDoc = unseenDocument1;
    ClassificationUpdateProcessorParams params = initParams(ClassificationUpdateProcessorFactory.Algorithm.KNN);
    params.setInputFieldNames(new String[] { TITLE + "^1.5", CONTENT + "^0.5", AUTHOR + "^2.5" });
    params.setMaxPredictedClasses(2);
    updateProcessorToTest = new ClassificationUpdateProcessor(params, mockProcessor, reader, req().getSchema());
    updateProcessorToTest.processAdd(update);
    ArrayList<Object> assignedClasses = (ArrayList) unseenDocument1.getFieldValues(TRAINING_CLASS);
    assertThat(assignedClasses.size(), is(2));
    assertThat(assignedClasses.get(0), is("class4"));
    assertThat(assignedClasses.get(1), is("class6"));
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) ArrayList(java.util.ArrayList) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) Test(org.junit.Test)

Aggregations

AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)68 SolrInputDocument (org.apache.solr.common.SolrInputDocument)41 Test (org.junit.Test)34 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)31 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)26 BufferingRequestProcessor (org.apache.solr.update.processor.BufferingRequestProcessor)19 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)17 SolrInputField (org.apache.solr.common.SolrInputField)14 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)12 JsonLoader (org.apache.solr.handler.loader.JsonLoader)11 ArrayList (java.util.ArrayList)10 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)10 SkipExistingDocumentsUpdateProcessor (org.apache.solr.update.processor.SkipExistingDocumentsProcessorFactory.SkipExistingDocumentsUpdateProcessor)8 SolrException (org.apache.solr.common.SolrException)7 DeleteUpdateCommand (org.apache.solr.update.DeleteUpdateCommand)6 CommitUpdateCommand (org.apache.solr.update.CommitUpdateCommand)5 SolrCore (org.apache.solr.core.SolrCore)4 SolrRequestInfo (org.apache.solr.request.SolrRequestInfo)4 UpdateRequestProcessor (org.apache.solr.update.processor.UpdateRequestProcessor)4 UpdateRequestProcessorChain (org.apache.solr.update.processor.UpdateRequestProcessorChain)4