use of org.apache.solr.common.SolrInputField in project lucene-solr by apache.
the class TestUpdateRequestCodec method testIteratable.
@Test
public void testIteratable() throws IOException {
final List<String> values = new ArrayList<>();
values.add("iterItem1");
values.add("iterItem2");
UpdateRequest updateRequest = new UpdateRequest();
updateRequest.deleteByQuery("*:*");
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", 1);
doc.addField("desc", "one");
// imagine someone adding a custom Bean that implements Iterable
// but is not a Collection
doc.addField("iter", new Iterable<String>() {
@Override
public Iterator<String> iterator() {
return values.iterator();
}
});
doc.addField("desc", "1");
updateRequest.add(doc);
JavaBinUpdateRequestCodec codec = new JavaBinUpdateRequestCodec();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
codec.marshal(updateRequest, baos);
final List<SolrInputDocument> docs = new ArrayList<>();
JavaBinUpdateRequestCodec.StreamingUpdateHandler handler = new JavaBinUpdateRequestCodec.StreamingUpdateHandler() {
@Override
public void update(SolrInputDocument document, UpdateRequest req, Integer commitWithin, Boolean overwrite) {
Assert.assertNotNull(req.getParams());
docs.add(document);
}
};
UpdateRequest updateUnmarshalled = codec.unmarshal(new ByteArrayInputStream(baos.toByteArray()), handler);
for (SolrInputDocument document : docs) {
updateUnmarshalled.add(document);
}
SolrInputDocument outDoc = updateUnmarshalled.getDocuments().get(0);
SolrInputField iter = outDoc.getField("iter");
Assert.assertNotNull("iter field is null", iter);
Object iterVal = iter.getValue();
Assert.assertTrue("iterVal is not a Collection", iterVal instanceof Collection);
Assert.assertEquals("iterVal contents", values, iterVal);
}
use of org.apache.solr.common.SolrInputField in project lucene-solr by apache.
the class TestTolerantUpdateProcessorCloud method f.
public static SolrInputField f(String fieldName, Object... values) {
SolrInputField f = new SolrInputField(fieldName);
f.setValue(values);
return f;
}
use of org.apache.solr.common.SolrInputField in project lucene-solr by apache.
the class JsonLoaderTest method testSimpleFormat.
public void testSimpleFormat() throws Exception {
String str = "[{'id':'1'},{'id':'2'}]".replace('\'', '"');
SolrQueryRequest req = req("commitWithin", "100", "overwrite", "false");
SolrQueryResponse rsp = new SolrQueryResponse();
BufferingRequestProcessor p = new BufferingRequestProcessor(null);
JsonLoader loader = new JsonLoader();
loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);
assertEquals(2, p.addCommands.size());
AddUpdateCommand add = p.addCommands.get(0);
SolrInputDocument d = add.solrDoc;
SolrInputField f = d.getField("id");
assertEquals("1", f.getValue());
assertEquals(add.commitWithin, 100);
assertEquals(add.overwrite, false);
add = p.addCommands.get(1);
d = add.solrDoc;
f = d.getField("id");
assertEquals("2", f.getValue());
assertEquals(add.commitWithin, 100);
assertEquals(add.overwrite, false);
req.close();
}
use of org.apache.solr.common.SolrInputField in project lucene-solr by apache.
the class JsonLoaderTest method testExtendedFieldValues.
public void testExtendedFieldValues() throws Exception {
String str = "[{'id':'1', 'val_s':{'add':'foo'}}]".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);
assertEquals(add.commitWithin, -1);
assertEquals(add.overwrite, true);
SolrInputDocument d = add.solrDoc;
SolrInputField f = d.getField("id");
assertEquals("1", f.getValue());
f = d.getField("val_s");
Map<String, Object> map = (Map<String, Object>) f.getValue();
assertEquals("foo", map.get("add"));
req.close();
}
use of org.apache.solr.common.SolrInputField in project lucene-solr by apache.
the class JsonLoaderTest method testParsing.
public void testParsing() throws Exception {
SolrQueryRequest req = req();
SolrQueryResponse rsp = new SolrQueryResponse();
BufferingRequestProcessor p = new BufferingRequestProcessor(null);
JsonLoader loader = new JsonLoader();
loader.load(req, rsp, new ContentStreamBase.StringStream(input), p);
assertEquals(2, p.addCommands.size());
AddUpdateCommand add = p.addCommands.get(0);
SolrInputDocument d = add.solrDoc;
SolrInputField f = d.getField("boosted");
assertEquals(2, f.getValues().size());
//
add = p.addCommands.get(1);
d = add.solrDoc;
f = d.getField("f1");
assertEquals(2, f.getValues().size());
assertEquals(false, add.overwrite);
assertEquals(0, d.getField("f2").getValueCount());
// parse the commit commands
assertEquals(2, p.commitCommands.size());
CommitUpdateCommand commit = p.commitCommands.get(0);
assertFalse(commit.optimize);
assertTrue(commit.waitSearcher);
assertTrue(commit.openSearcher);
commit = p.commitCommands.get(1);
assertTrue(commit.optimize);
assertFalse(commit.waitSearcher);
assertFalse(commit.openSearcher);
// DELETE COMMANDS
assertEquals(4, p.deleteCommands.size());
DeleteUpdateCommand delete = p.deleteCommands.get(0);
assertEquals(delete.id, "ID");
assertEquals(delete.query, null);
assertEquals(delete.commitWithin, -1);
delete = p.deleteCommands.get(1);
assertEquals(delete.id, "ID");
assertEquals(delete.query, null);
assertEquals(delete.commitWithin, 500);
delete = p.deleteCommands.get(2);
assertEquals(delete.id, null);
assertEquals(delete.query, "QUERY");
assertEquals(delete.commitWithin, -1);
delete = p.deleteCommands.get(3);
assertEquals(delete.id, null);
assertEquals(delete.query, "QUERY");
assertEquals(delete.commitWithin, 500);
// ROLLBACK COMMANDS
assertEquals(1, p.rollbackCommands.size());
req.close();
}
Aggregations