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