Search in sources :

Example 26 with AddUpdateCommand

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

the class ClassificationUpdateProcessorTest method knnMultiClass_maxOutputClasses2_shouldAssignMax2Classes.

@Test
public void knnMultiClass_maxOutputClasses2_shouldAssignMax2Classes() throws Exception {
    UpdateRequestProcessor mockProcessor = mock(UpdateRequestProcessor.class);
    prepareTrainedIndexMultiClass();
    AddUpdateCommand update = new AddUpdateCommand(req());
    SolrInputDocument unseenDocument1 = sdoc(ID, "10", TITLE, "word1 word1 word1", CONTENT, "word2 word2 ", AUTHOR, "unseenAuthor");
    update.solrDoc = unseenDocument1;
    ClassificationUpdateProcessorParams params = initParams(ClassificationUpdateProcessorFactory.Algorithm.KNN);
    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("class2"));
    assertThat(assignedClasses.get(1), is("class1"));
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) ArrayList(java.util.ArrayList) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) Test(org.junit.Test)

Example 27 with AddUpdateCommand

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

the class ClassificationUpdateProcessorTest method knnMonoClass_sampleParams_shouldAssignCorrectClass.

@Test
public void knnMonoClass_sampleParams_shouldAssignCorrectClass() throws Exception {
    UpdateRequestProcessor mockProcessor = mock(UpdateRequestProcessor.class);
    prepareTrainedIndexMonoClass();
    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);
    updateProcessorToTest = new ClassificationUpdateProcessor(params, mockProcessor, reader, req().getSchema());
    updateProcessorToTest.processAdd(update);
    assertThat(unseenDocument1.getFieldValue(TRAINING_CLASS), is("class2"));
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) Test(org.junit.Test)

Example 28 with AddUpdateCommand

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

the class ClassificationUpdateProcessorTest method bayesMonoClass_boostFields_shouldAssignCorrectClass.

@Test
public void bayesMonoClass_boostFields_shouldAssignCorrectClass() throws Exception {
    UpdateRequestProcessor mockProcessor = mock(UpdateRequestProcessor.class);
    prepareTrainedIndexMonoClass();
    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" });
    updateProcessorToTest = new ClassificationUpdateProcessor(params, mockProcessor, reader, req().getSchema());
    updateProcessorToTest.processAdd(update);
    assertThat(unseenDocument1.getFieldValue(TRAINING_CLASS), is("class2"));
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) Test(org.junit.Test)

Example 29 with AddUpdateCommand

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

the class ClassificationUpdateProcessorTest method classificationMonoClass_predictedClassFieldSet_shouldAssignClassInPredictedClassField.

@Test
public void classificationMonoClass_predictedClassFieldSet_shouldAssignClassInPredictedClassField() throws Exception {
    UpdateRequestProcessor mockProcessor = mock(UpdateRequestProcessor.class);
    prepareTrainedIndexMonoClass();
    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.setPredictedClassField(PREDICTED_CLASS);
    updateProcessorToTest = new ClassificationUpdateProcessor(params, mockProcessor, reader, req().getSchema());
    updateProcessorToTest.processAdd(update);
    assertThat(unseenDocument1.getFieldValue(PREDICTED_CLASS), is("class2"));
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) Test(org.junit.Test)

Example 30 with AddUpdateCommand

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

the class ClassificationUpdateProcessorTest method knnMonoClass_boostFields_shouldAssignCorrectClass.

@Test
public void knnMonoClass_boostFields_shouldAssignCorrectClass() throws Exception {
    UpdateRequestProcessor mockProcessor = mock(UpdateRequestProcessor.class);
    prepareTrainedIndexMonoClass();
    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" });
    updateProcessorToTest = new ClassificationUpdateProcessor(params, mockProcessor, reader, req().getSchema());
    updateProcessorToTest.processAdd(update);
    assertThat(unseenDocument1.getFieldValue(TRAINING_CLASS), is("class2"));
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) 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