public static SolrInputDocument toSolrInputDocument(Document document) { SolrInputDocument solrInputDocument = new SolrInputDocument(); for (Map.Entry<String, Object> field : document.getDocument().entrySet()) { if (field.getKey().equals(MetaAlertConstants.ALERT_FIELD)) { // We have a children, that needs to be translated as a child doc, not a field. List<Map<String, Object>> alerts = (List<Map<String, Object>>) field.getValue(); for (Map<String, Object> alert : alerts) { SolrInputDocument childDocument = new SolrInputDocument(); for (Map.Entry<String, Object> alertField : alert.entrySet()) { childDocument.addField(alertField.getKey(), alertField.getValue()); } solrInputDocument.addChildDocument(childDocument); } } else { solrInputDocument.addField(field.getKey(), field.getValue()); } } return solrInputDocument; }
public void addChildDocuments(Collection<SolrInputDocument> childs) { for (SolrInputDocument child : childs) { addChildDocument(child); } }
public void addChildDocuments(Collection<SolrInputDocument> children) { for (SolrInputDocument child : children) { addChildDocument(child); } }
private void addChild(Object obj, DocField field, SolrInputDocument doc) { Object val = field.get(obj); if (val == null) return; if (val instanceof Collection) { Collection collection = (Collection) val; for (Object o : collection) { SolrInputDocument child = toSolrInputDocument(o); doc.addChildDocument(child); } } else if (val.getClass().isArray()) { Object[] objs = (Object[]) val; for (Object o : objs) doc.addChildDocument(toSolrInputDocument(o)); } else { doc.addChildDocument(toSolrInputDocument(val)); } }
private void addChild(Object obj, DocField field, SolrInputDocument doc) { Object val = field.get(obj); if (val == null) return; if (val instanceof Collection) { Collection collection = (Collection) val; for (Object o : collection) { SolrInputDocument child = toSolrInputDocument(o); doc.addChildDocument(child); } } else if (val.getClass().isArray()) { Object[] objs = (Object[]) val; for (Object o : objs) doc.addChildDocument(toSolrInputDocument(o)); } else { doc.addChildDocument(toSolrInputDocument(val)); } }
public SolrInputDocument sdocWithChildren(String id, String version, int childCount) { SolrInputDocument doc = sdoc("id", id, "_version_", version); for (int i = 1; i <= childCount; i++) { doc.addChildDocument(sdoc("id", id + "_child" + i)); } return doc; } public SolrInputDocument sdocWithChildren(Integer id, String version, int childCount) {
public SolrInputDocument sdocWithChildren(Integer id, String version, int childCount) { SolrInputDocument doc = sdoc("id", id, "_version_", version); for (int i = 1; i <= childCount; i++) { doc.addChildDocument(sdoc("id", (1000)*id + i)); } return doc; }
private SolrInputDocument convert(Record record) { Map<String, Collection<Object>> map = record.getFields().asMap(); SolrInputDocument doc = new SolrInputDocument(new HashMap(2 * map.size())); for (Map.Entry<String, Collection<Object>> entry : map.entrySet()) { String key = entry.getKey(); if (LoadSolrBuilder.LOAD_SOLR_CHILD_DOCUMENTS.equals(key)) { for (Object value : entry.getValue()) { if (value instanceof Record) { value = convert((Record) value); // recurse } if (value instanceof SolrInputDocument) { doc.addChildDocument((SolrInputDocument) value); } else { throw new MorphlineRuntimeException("Child document must be of class " + Record.class.getName() + " or " + SolrInputDocument.class.getName() + ": " + value); } } } else { doc.setField(key, entry.getValue()); } } return doc; }
private SolrInputDocument convert(Record record) { Map<String, Collection<Object>> map = record.getFields().asMap(); SolrInputDocument doc = new SolrInputDocument(new HashMap(2 * map.size())); for (Map.Entry<String, Collection<Object>> entry : map.entrySet()) { String key = entry.getKey(); if (LOAD_SOLR_CHILD_DOCUMENTS.equals(key)) { for (Object value : entry.getValue()) { if (value instanceof Record) { value = convert((Record) value); // recurse } if (value instanceof SolrInputDocument) { doc.addChildDocument((SolrInputDocument) value); } else { throw new MorphlineRuntimeException("Child document must be of class " + Record.class.getName() + " or " + SolrInputDocument.class.getName() + ": " + value); } } } else { Collection<Object> values = entry.getValue(); if (values.size() == 1 && values.iterator().next() instanceof Map) { doc.setField(key, values.iterator().next(), getBoost(key)); // it is an atomic update } else { doc.setField(key, values, getBoost(key)); } } } return doc; }
private SolrInputDocument convert(Record record) { Map<String, Collection<Object>> map = record.getFields().asMap(); SolrInputDocument doc = new SolrInputDocument(new HashMap(2 * map.size())); for (Map.Entry<String, Collection<Object>> entry : map.entrySet()) { String key = entry.getKey(); if (LOAD_SOLR_CHILD_DOCUMENTS.equals(key)) { for (Object value : entry.getValue()) { if (value instanceof Record) { value = convert((Record) value); // recurse } if (value instanceof SolrInputDocument) { doc.addChildDocument((SolrInputDocument) value); } else { throw new MorphlineRuntimeException("Child document must be of class " + Record.class.getName() + " or " + SolrInputDocument.class.getName() + ": " + value); } } } else { doc.setField(key, entry.getValue(), getBoost(key)); } } return doc; }
sdoc.addChildDocument((SolrInputDocument)obj); continue; } else {
document.addChildDocument(createInputDocument(childDocument)) );
public static SolrInputDocument toSolrInputDocument(SolrDocument solrDocument) { SolrInputDocument solrInputDocument = new SolrInputDocument(); for (String name : solrDocument.getFieldNames()) { solrInputDocument.addField(name, solrDocument.getFieldValue(name)); } //Don't forget children documents if(solrDocument.getChildDocuments() != null) { for(SolrDocument childDocument : solrDocument.getChildDocuments()) { //You can add paranoic check against infinite loop childDocument == solrDocument solrInputDocument.addChildDocument(toSolrInputDocument(childDocument)); } } return solrInputDocument; } }
SolrInputDocument parentDocUpdateing = new SolrInputDocument(); parentDocUpdateing.addField("id", "parent_1"); parentDocUpdateing.addField("name_s", "Sarah Connor"); parentDocUpdateing.addField("blockJoinId", "1"); SolrInputDocument childDoc = new SolrInputDocument(); childDoc.addField("id", "child_1"); childDoc.addField("name_s", "John Connor"); childDoc.addField("blockJoinId", "1"); parentDocUpdateing.addChildDocument(childDoc); solrClient.add(parentDocUpdateing); solrClient.commit();
person1.addChildDocument( p1_car1 ); person1.addChildDocument( p1_car2 ); person1.addChildDocument( p1_bike1 ); person1.addChildDocument( p1_bike2 ); p2_bike1.addField( "model_t", "Spree" ); person2.addChildDocument( p2_car1 ); person2.addChildDocument( p2_bike1 ); batch.add( person2 );
/** * Converts a {@link SolrDocument} to a {@link SolrInputDocument} * * @param solrDocument * @return */ public static SolrInputDocument toSolrInputDocument(SolrDocument solrDocument) { /* * Note: ClientUtils.toSolrInputDocument was removed in solr 6 Replacement found on * https://stackoverflow.com/questions/38266684/ * substitute-of-org-apache-solr-client-solrj-util-clientutils-tosolrinputdocument */ SolrInputDocument solrInputDocument = new SolrInputDocument(); for (String name : solrDocument.getFieldNames()) { solrInputDocument.addField(name, solrDocument.getFieldValue(name)); } //Don't forget children documents if (solrDocument.getChildDocuments() != null) { for (SolrDocument childDocument : solrDocument.getChildDocuments()) { //You can add paranoic check against infinite loop childDocument == solrDocument solrInputDocument.addChildDocument(toSolrInputDocument(childDocument)); } } return solrInputDocument; } }
public SolrInputDocument readSolrInputDocument(DataInputInputStream dis) throws IOException { int sz = readVInt(dis); float docBoost = (Float)readVal(dis); SolrInputDocument sdoc = new SolrInputDocument(); sdoc.setDocumentBoost(docBoost); for (int i = 0; i < sz; i++) { float boost = 1.0f; String fieldName; Object obj = readVal(dis); // could be a boost, a field name, or a child document if (obj instanceof Float) { boost = (Float)obj; fieldName = (String)readVal(dis); } else if (obj instanceof SolrInputDocument) { sdoc.addChildDocument((SolrInputDocument)obj); continue; } else { fieldName = (String)obj; } Object fieldVal = readVal(dis); sdoc.setField(fieldName, fieldVal, boost); } return sdoc; }
person1.addChildDocument( p1_car1 ); person1.addChildDocument( p1_car2 ); person1.addChildDocument( p1_bike1 ); person1.addChildDocument( p1_bike2 ); p2_bike1.addField( "model_t", "Spree" ); person2.addChildDocument( p2_car1 ); person2.addChildDocument( p2_bike1 ); batch.add( person2 );
diffSolrDoc.addField("filePath", firstTreeWalk.getPathString()); System.out.println(diffSolrDoc); solrDoc.addChildDocument(diffSolrDoc); idx++; solrDoc.addChildDocument(diffSolrDoc);