use of org.apache.solr.common.SolrInputField in project lucene-solr by apache.
the class JsonLoaderTest method testEmptyChildDocs.
@Test
public void testEmptyChildDocs() throws Exception {
String str = "{\n" + " \"add\": {\n" + " \"doc\": {\n" + " \"id\": \"1\",\n" + " \"_childDocuments_\": []\n" + " }\n" + " }\n" + "}";
SolrQueryRequest req = req("commit", "true");
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("id");
assertEquals("1", f.getValue());
List<SolrInputDocument> cd = d.getChildDocuments();
assertNull(cd);
req.close();
}
use of org.apache.solr.common.SolrInputField in project lucene-solr by apache.
the class FieldMutatingUpdateProcessorTest method testLastValue.
public void testLastValue() throws Exception {
SolrInputDocument d = null;
// basics
d = processAdd("last-value", doc(f("id", "1111"), f("foo_s", "string1", "string222"), f("bar_s", "string3"), f("yak_t", "string4", "string5")));
assertNotNull(d);
assertEquals(Arrays.asList("string222"), d.getFieldValues("foo_s"));
assertEquals(Arrays.asList("string3"), d.getFieldValues("bar_s"));
assertEquals(Arrays.asList("string4", "string5"), d.getFieldValues("yak_t"));
// test optimizations (and force test of defaults)
SolrInputField special = null;
// test something that's definitely a SortedSet
special = new SolrInputField("foo_s");
special.setValue(new TreeSet<>(Arrays.asList("ggg", "first", "last", "hhh")));
d = processAdd("last-value", doc(f("id", "1111"), special));
assertNotNull(d);
assertEquals("last", d.getFieldValue("foo_s"));
// test something that's definitely a List
special = new SolrInputField("foo_s");
special.setValue(Arrays.asList("first", "ggg", "hhh", "last"));
d = processAdd("last-value", doc(f("id", "1111"), special));
assertNotNull(d);
assertEquals("last", d.getFieldValue("foo_s"));
// test something that is definitely not a List or SortedSet
// (ie: get default behavior of Collection using iterator)
special = new SolrInputField("foo_s");
special.setValue(new LinkedHashSet<>(Arrays.asList("first", "ggg", "hhh", "last")));
d = processAdd("last-value", doc(f("id", "1111"), special));
assertNotNull(d);
assertEquals("last", d.getFieldValue("foo_s"));
}
use of org.apache.solr.common.SolrInputField in project lucene-solr by apache.
the class SolrTestCaseJ4 method json.
/**
* Appends to the <code>out</code> array with JSON from the <code>doc</code>.
* Doesn't currently handle boosts, but does recursively handle child documents
*/
public static void json(SolrInputDocument doc, CharArr out) {
try {
out.append('{');
boolean firstField = true;
for (SolrInputField sfield : doc) {
if (firstField)
firstField = false;
else
out.append(',');
JSONUtil.writeString(sfield.getName(), 0, sfield.getName().length(), out);
out.append(':');
if (sfield.getValueCount() > 1) {
out.append('[');
boolean firstVal = true;
for (Object val : sfield) {
if (firstVal)
firstVal = false;
else
out.append(',');
out.append(JSONUtil.toJSON(val));
}
out.append(']');
} else {
out.append(JSONUtil.toJSON(sfield.getValue()));
}
}
boolean firstChildDoc = true;
if (doc.hasChildDocuments()) {
out.append(",\"_childDocuments_\": [");
List<SolrInputDocument> childDocuments = doc.getChildDocuments();
for (SolrInputDocument childDocument : childDocuments) {
if (firstChildDoc)
firstChildDoc = false;
else
out.append(',');
json(childDocument, out);
}
out.append(']');
}
out.append('}');
} catch (IOException e) {
// should never happen
}
}
use of org.apache.solr.common.SolrInputField in project lucene-solr by apache.
the class JavaBinCodec method writeSolrInputDocument.
public void writeSolrInputDocument(SolrInputDocument sdoc) throws IOException {
List<SolrInputDocument> children = sdoc.getChildDocuments();
int sz = sdoc.size() + (children == null ? 0 : children.size());
writeTag(SOLRINPUTDOC, sz);
// document boost
writeFloat(1f);
for (SolrInputField inputField : sdoc.values()) {
writeExternString(inputField.getName());
writeVal(inputField.getValue());
}
if (children != null) {
for (SolrInputDocument child : children) {
writeSolrInputDocument(child);
}
}
}
use of org.apache.solr.common.SolrInputField in project lucene-solr by apache.
the class TestCloudDeleteByQuery method f.
public static SolrInputField f(String fieldName, Object... values) {
SolrInputField f = new SolrInputField(fieldName);
f.setValue(values);
return f;
}
Aggregations