Github user moshebla commented on a diff in the pull request:
https://github.com/apache/lucene-solr/pull/385#discussion_r192015467
--- Diff: solr/core/src/java/org/apache/solr/update/AddUpdateCommand.java
---
@@ -175,69 +172,83 @@ public String getHashableId() {
return id;
}
- public boolean isBlock() {
- return solrDoc.hasChildDocuments();
+ /**
+ * @return String id to hash
+ */
+ public String getHashableId() {
+ return getHashableId(solrDoc);
}
- @Override
- public Iterator<Document> iterator() {
- return new Iterator<Document>() {
- Iterator<SolrInputDocument> iter;
-
- {
- List<SolrInputDocument> all = flatten(solrDoc);
-
- String idField = getHashableId();
-
- boolean isVersion = version != 0;
-
- for (SolrInputDocument sdoc : all) {
- sdoc.setField(IndexSchema.ROOT_FIELD_NAME, idField);
- if(isVersion) sdoc.setField(CommonParams.VERSION_FIELD, version);
- // TODO: if possible concurrent modification exception (if
SolrInputDocument not cloned and is being forwarded to replicas)
- // then we could add this field to the generated lucene document
instead.
- }
-
- iter = all.iterator();
- }
+ public List<SolrInputDocument> computeFlattenedDocs() {
+ List<SolrInputDocument> all = flatten(solrDoc);
- @Override
- public boolean hasNext() {
- return iter.hasNext();
- }
+ String rootId = getHashableId();
- @Override
- public Document next() {
- return DocumentBuilder.toDocument(iter.next(), req.getSchema());
- }
+ boolean isVersion = version != 0;
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
+ for (SolrInputDocument sdoc : all) {
+ if (all.size() > 1) {
+ sdoc.setField(IndexSchema.ROOT_FIELD_NAME, rootId);
}
- };
+ if(isVersion) sdoc.setField(CommonParams.VERSION_FIELD, version);
+ // TODO: if possible concurrent modification exception (if
SolrInputDocument not cloned and is being forwarded to replicas)
+ // then we could add this field to the generated lucene document
instead.
+ }
+ return all;
}
private List<SolrInputDocument> flatten(SolrInputDocument root) {
--- End diff --
That seems about right, and is exactly what happens in
[DirectUpdateHandler2](https://github.com/moshebla/lucene-solr/blob/3b7d33f3cc7363fcb36f7f91ae7ca5f6bd4bee3a/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java#L963).
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]