Github user dsmiley commented on a diff in the pull request:

    https://github.com/apache/lucene-solr/pull/416#discussion_r206901995
  
    --- Diff: 
solr/core/src/test/org/apache/solr/response/transform/TestDeeplyNestedChildDocTransformer.java
 ---
    @@ -168,35 +172,57 @@ private static String id() {
         return "" + counter.incrementAndGet();
       }
     
    +  private static void cleanSolrDocumentFields(SolrDocument input) {
    +    for(Map.Entry<String, Object> field: input) {
    +      Object val = field.getValue();
    +      if(val instanceof Collection) {
    +        Object newVals = ((Collection) val).stream().map((item) -> 
(cleanIndexableField(item)))
    +            .collect(Collectors.toList());
    +        input.setField(field.getKey(), newVals);
    +        continue;
    +      } else {
    +        input.setField(field.getKey(), 
cleanIndexableField(field.getValue()));
    +      }
    +    }
    +  }
    +
    +  private static Object cleanIndexableField(Object field) {
    +    if(field instanceof IndexableField) {
    +      return ((IndexableField) field).stringValue();
    +    } else if(field instanceof SolrDocument) {
    +      cleanSolrDocumentFields((SolrDocument) field);
    +    }
    +    return field;
    +  }
    +
       private static String grandChildDocTemplate(int id) {
         int docNum = id / 8; // the index of docs sent to solr in the 
AddUpdateCommand. e.g. first doc is 0
    -    return 
"SolrDocument{id=stored,indexed,tokenized,omitNorms,indexOptions=DOCS<id:" + id 
+ ">, type_s=[stored,indexed,tokenized,omitNorms,indexOptions=DOCS<type_s:" + 
types[docNum % types.length] + ">], 
name_s=[stored,indexed,tokenized,omitNorms,indexOptions=DOCS<name_s:" + 
names[docNum % names.length] + ">], " +
    -        
"_root_=stored,indexed,tokenized,omitNorms,indexOptions=DOCS<_root_:" + id + 
">, " +
    -        
"toppings=[SolrDocument{id=stored,indexed,tokenized,omitNorms,indexOptions=DOCS<id:"
 + (id + 3) + ">, 
type_s=[stored,indexed,tokenized,omitNorms,indexOptions=DOCS<type_s:Regular>], 
_nest_parent_=stored,indexed,tokenized,omitNorms,indexOptions=DOCS<_nest_parent_:"
 + id + ">, " +
    -        
"_root_=stored,indexed,tokenized,omitNorms,indexOptions=DOCS<_root_:" + id + 
">, " +
    -        
"ingredients=[SolrDocument{id=stored,indexed,tokenized,omitNorms,indexOptions=DOCS<id:"
 + (id + 4) + ">, 
name_s=[stored,indexed,tokenized,omitNorms,indexOptions=DOCS<name_s:cocoa>], " +
    -        
"_nest_parent_=stored,indexed,tokenized,omitNorms,indexOptions=DOCS<_nest_parent_:"
 + (id + 3) + ">, 
_root_=stored,indexed,tokenized,omitNorms,indexOptions=DOCS<_root_:" + id + 
">}]}, " +
    -        
"SolrDocument{id=stored,indexed,tokenized,omitNorms,indexOptions=DOCS<id:" + 
(id + 5) + ">, 
type_s=[stored,indexed,tokenized,omitNorms,indexOptions=DOCS<type_s:Chocolate>],
 
_nest_parent_=stored,indexed,tokenized,omitNorms,indexOptions=DOCS<_nest_parent_:"
 + id + ">, " +
    -        
"_root_=stored,indexed,tokenized,omitNorms,indexOptions=DOCS<_root_:" + id + 
">, " +
    -        
"ingredients=[SolrDocument{id=stored,indexed,tokenized,omitNorms,indexOptions=DOCS<id:"
 + (id + 6) + ">, 
name_s=[stored,indexed,tokenized,omitNorms,indexOptions=DOCS<name_s:cocoa>], 
_nest_parent_=stored,indexed,tokenized,omitNorms,indexOptions=DOCS<_nest_parent_:"
 + (id + 5)+ ">, " +
    -        
"_root_=stored,indexed,tokenized,omitNorms,indexOptions=DOCS<_root_:" + id + 
">}, " +
    -        
"SolrDocument{id=stored,indexed,tokenized,omitNorms,indexOptions=DOCS<id:" + 
(id + 7) + ">, 
name_s=[stored,indexed,tokenized,omitNorms,indexOptions=DOCS<name_s:cocoa>], 
_nest_parent_=stored,indexed,tokenized,omitNorms,indexOptions=DOCS<_nest_parent_:"
 + (id + 5) + ">, " +
    -        
"_root_=stored,indexed,tokenized,omitNorms,indexOptions=DOCS<_root_:" + id + 
">}]}]}";
    +    return "SolrDocument{id="+ id + ", type_s=[" + types[docNum % 
types.length] + "], name_s=[" + names[docNum % names.length] + "], " +
    --- End diff --
    
    Keeping one ID is fine; we certainly don't need additional ones.  Maybe 
consider using letters or names for IDs instead of incrementing counters.  
Anything to help make reading a doc/child structure more readily apparent.  
Anything to reduce string interpolation here is also a win IMO.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org

Reply via email to