Github user dsmiley commented on a diff in the pull request:
https://github.com/apache/lucene-solr/pull/385#discussion_r191396348
--- Diff: solr/core/src/java/org/apache/solr/update/AddUpdateCommand.java
---
@@ -175,69 +176,92 @@ 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;
+ public boolean isBlock() {
+ return getDocsList().size() > 1;
+ }
- 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.
- }
+ public List<SolrInputDocument> getDocsList() {
+ if (docsList == null) {
+ buildDocsList();
+ }
+ return docsList;
+ }
- iter = all.iterator();
- }
+ private void buildDocsList() {
+ List<SolrInputDocument> all = flatten(solrDoc);
- @Override
- public boolean hasNext() {
- return iter.hasNext();
- }
+ String idField = 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, 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.
+ }
+ docsList = all;
}
private List<SolrInputDocument> flatten(SolrInputDocument root) {
List<SolrInputDocument> unwrappedDocs = new ArrayList<>();
- recUnwrapp(unwrappedDocs, root);
+ if(root.hasChildDocuments()) {
+ recUnwrapp(unwrappedDocs, root, true);
+ }
+ recUnwrapRelations(unwrappedDocs, root, true);
if (1 < unwrappedDocs.size() && !
req.getSchema().isUsableForChildDocs()) {
throw new SolrException
(SolrException.ErrorCode.BAD_REQUEST, "Unable to index docs with
children: the schema must " +
"include definitions for both a uniqueKey field and the '" +
IndexSchema.ROOT_FIELD_NAME +
"' field, using the exact same fieldType");
}
+ unwrappedDocs.add(root);
return unwrappedDocs;
}
- private void recUnwrapp(List<SolrInputDocument> unwrappedDocs,
SolrInputDocument currentDoc) {
+ private void recUnwrapRelations(List<SolrInputDocument> unwrappedDocs,
SolrInputDocument currentDoc, boolean isRoot) {
--- End diff --
These similar sounding methods are a little confusing to me; a sentence
javadoc for each method would be helpful.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]