Search in sources :

Example 56 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 57 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)

Example 58 with AddUpdateCommand

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

the class ClassificationUpdateProcessorTest method bayesMonoClass_sampleParams_shouldAssignCorrectClass.

@Test
public void bayesMonoClass_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.BAYES);
    updateProcessorToTest = new ClassificationUpdateProcessor(params, mockProcessor, reader, req().getSchema());
    updateProcessorToTest.processAdd(update);
    assertThat(unseenDocument1.getFieldValue(TRAINING_CLASS), is("class1"));
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) Test(org.junit.Test)

Example 59 with AddUpdateCommand

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

the class ClassificationUpdateProcessorTest method knnMonoClass_contextQueryFiltered_shouldAssignCorrectClass.

@Test
public void knnMonoClass_contextQueryFiltered_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, "a");
    update.solrDoc = unseenDocument1;
    ClassificationUpdateProcessorParams params = initParams(ClassificationUpdateProcessorFactory.Algorithm.KNN);
    Query class3DocsChunk = new TermQuery(new Term(TITLE, "word6"));
    params.setTrainingFilterQuery(class3DocsChunk);
    updateProcessorToTest = new ClassificationUpdateProcessor(params, mockProcessor, reader, req().getSchema());
    updateProcessorToTest.processAdd(update);
    assertThat(unseenDocument1.getFieldValue(TRAINING_CLASS), is("class3"));
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) SolrInputDocument(org.apache.solr.common.SolrInputDocument) Query(org.apache.lucene.search.Query) TermQuery(org.apache.lucene.search.TermQuery) Term(org.apache.lucene.index.Term) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) Test(org.junit.Test)

Example 60 with AddUpdateCommand

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

the class XsltUpdateRequestHandlerTest method testEntities.

@Test
public void testEntities() throws Exception {
    // use a binary file, so when it's loaded fail with XML eror:
    String file = getFile("mailing_lists.pdf").toURI().toASCIIString();
    String xml = "<?xml version=\"1.0\"?>" + "<!DOCTYPE foo [" + // check that external entities are not resolved!
    "<!ENTITY bar SYSTEM \"" + file + "\">" + // but named entities should be
    "<!ENTITY wacky \"zzz\">" + "]>" + "<random>" + " &bar;" + " <document>" + "  <node name=\"id\" value=\"12345\"/>" + "  <node name=\"foo_s\" value=\"&wacky;\"/>" + " </document>" + "</random>";
    SolrQueryRequest req = req(CommonParams.TR, "xsl-update-handler-test.xsl");
    SolrQueryResponse rsp = new SolrQueryResponse();
    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
    XMLLoader loader = new XMLLoader().init(null);
    loader.load(req, rsp, new ContentStreamBase.StringStream(xml), p);
    AddUpdateCommand add = p.addCommands.get(0);
    assertEquals("12345", add.solrDoc.getField("id").getFirstValue());
    assertEquals("zzz", add.solrDoc.getField("foo_s").getFirstValue());
    req.close();
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) XMLLoader(org.apache.solr.handler.loader.XMLLoader) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase) 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