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"));
}
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"));
}
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();
}
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);
}
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();
}
Aggregations