Search in sources :

Example 71 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 72 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 73 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)

Example 74 with AddUpdateCommand

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

the class TestLazyCores method addLazy.

private void addLazy(SolrCore core, String... fieldValues) throws IOException {
    UpdateHandler updater = core.getUpdateHandler();
    AddUpdateCommand cmd = new AddUpdateCommand(makeReq(core));
    cmd.solrDoc = sdoc((Object[]) fieldValues);
    updater.addDoc(cmd);
}
Also used : UpdateHandler(org.apache.solr.update.UpdateHandler) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand)

Example 75 with AddUpdateCommand

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

the class JsonLoaderTest method testBigDecimalValuesInAdd.

@Test
public void testBigDecimalValuesInAdd() throws Exception {
    String str = ("{'add':[{'id':'1','bd1':0.12345678901234567890123456789012345," + "'bd2':12345678901234567890.12345678901234567890,'bd3':0.012345678901234567890123456789012345," + "'bd3':123456789012345678900.012345678901234567890}]}").replace('\'', '"');
    SolrQueryRequest req = req();
    SolrQueryResponse rsp = new SolrQueryResponse();
    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
    JsonLoader loader = new JsonLoader();
    loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);
    assertEquals(1, p.addCommands.size());
    AddUpdateCommand add = p.addCommands.get(0);
    SolrInputDocument d = add.solrDoc;
    SolrInputField f = d.getField("bd1");
    assertTrue(f.getValue() instanceof String);
    assertEquals("0.12345678901234567890123456789012345", f.getValue());
    f = d.getField("bd2");
    assertTrue(f.getValue() instanceof String);
    assertEquals("12345678901234567890.12345678901234567890", f.getValue());
    f = d.getField("bd3");
    assertEquals(2, ((List) f.getValue()).size());
    assertTrue(((List) f.getValue()).contains("0.012345678901234567890123456789012345"));
    assertTrue(((List) f.getValue()).contains("123456789012345678900.012345678901234567890"));
    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) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase) Test(org.junit.Test)

Aggregations

AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)87 SolrInputDocument (org.apache.solr.common.SolrInputDocument)59 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)41 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)37 Test (org.junit.Test)34 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)23 BufferingRequestProcessor (org.apache.solr.update.processor.BufferingRequestProcessor)19 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)17 SolrInputField (org.apache.solr.common.SolrInputField)14 UpdateRequestProcessor (org.apache.solr.update.processor.UpdateRequestProcessor)14 ArrayList (java.util.ArrayList)12 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)11 JsonLoader (org.apache.solr.handler.loader.JsonLoader)11 IOException (java.io.IOException)8 SkipExistingDocumentsUpdateProcessor (org.apache.solr.update.processor.SkipExistingDocumentsProcessorFactory.SkipExistingDocumentsUpdateProcessor)8 SolrException (org.apache.solr.common.SolrException)7 CommitUpdateCommand (org.apache.solr.update.CommitUpdateCommand)7 DeleteUpdateCommand (org.apache.solr.update.DeleteUpdateCommand)7 SolrCore (org.apache.solr.core.SolrCore)6 NamedList (org.apache.solr.common.util.NamedList)5