You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by is...@apache.org on 2017/01/06 23:58:58 UTC
lucene-solr:jira/solr-5944: SOLR-5944: Refactor some internal
conversions to/from SolrDocument/SolrInputDocument
Repository: lucene-solr
Updated Branches:
refs/heads/jira/solr-5944 5db04fdc4 -> 378a283cc
SOLR-5944: Refactor some internal conversions to/from SolrDocument/SolrInputDocument
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/378a283c
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/378a283c
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/378a283c
Branch: refs/heads/jira/solr-5944
Commit: 378a283cc40375661dcb2407a6687332e9c27660
Parents: 5db04fd
Author: Ishan Chattopadhyaya <is...@apache.org>
Authored: Sat Jan 7 05:28:32 2017 +0530
Committer: Ishan Chattopadhyaya <is...@apache.org>
Committed: Sat Jan 7 05:28:32 2017 +0530
----------------------------------------------------------------------
.../handler/component/RealTimeGetComponent.java | 40 ++++++++------------
.../org/apache/solr/update/DocumentBuilder.java | 3 +-
.../org/apache/solr/update/UpdateLogTest.java | 8 ++--
3 files changed, 22 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/378a283c/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java b/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java
index d5a473a..1d0c3a0 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java
@@ -45,7 +45,6 @@ import org.apache.solr.client.solrj.SolrResponse;
import org.apache.solr.cloud.CloudDescriptor;
import org.apache.solr.cloud.ZkController;
import org.apache.solr.common.SolrDocument;
-import org.apache.solr.common.SolrDocumentBase;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
@@ -232,21 +231,19 @@ public class RealTimeGetComponent extends SearchComponent
break;
}
- SolrDocument doc = toSolrDoc((SolrInputDocument)entry.get(entry.size()-1), core.getLatestSchema(), oper == UpdateLog.UPDATE_INPLACE);
- if (oper == UpdateLog.UPDATE_INPLACE) {
+ SolrDocument doc;
+ if (oper == UpdateLog.ADD) {
+ doc = toSolrDoc((SolrInputDocument)entry.get(entry.size()-1), core.getLatestSchema());
+ } else if (oper == UpdateLog.UPDATE_INPLACE) {
assert entry.size() == 5;
// For in-place update case, we have obtained the partial document till now. We need to
// resolve it to a full document to be returned to the user.
- doc = (SolrDocument) resolveFullDocument(core, idBytes.get(), rsp.getReturnFields(), doc, entry, null);
+ doc = resolveFullDocument(core, idBytes.get(), rsp.getReturnFields(), (SolrInputDocument)entry.get(entry.size()-1), entry, null);
if (doc == null) {
break; // document has been deleted as the resolve was going on
}
- // Since the partial doc from the tlog was obtained and resolved without ever having populated all
- // the defaults and the copy fields before, we need to do it before returning. The call to toSolrDoc()
- // here achieves that.
- // nocommit: Is it possible to refactor these methods cleanly so that this double conversion (SD->SID->(Document->)SD)
- // nocommit: can be avoided?
- doc = toSolrDoc(toSolrInputDocument(doc, core.getLatestSchema()), core.getLatestSchema(), false);
+ } else {
+ throw new SolrException(ErrorCode.INVALID_STATE, "Expected ADD or UPDATE_INPLACE. Got: " + oper);
}
if (transformer!=null) {
transformer.transform(doc, -1, 0); // unknown docID
@@ -376,7 +373,7 @@ public class RealTimeGetComponent extends SearchComponent
* after the resolving began)
*/
private static SolrDocument resolveFullDocument(SolrCore core, BytesRef idBytes,
- ReturnFields returnFields, SolrDocumentBase partialDoc, List logEntry, Set<String> onlyTheseFields) throws IOException {
+ ReturnFields returnFields, SolrInputDocument partialDoc, List logEntry, Set<String> onlyTheseFields) throws IOException {
if (idBytes == null || logEntry.size() != 5) {
throw new SolrException(ErrorCode.INVALID_STATE, "Either Id field not present in partial document or log entry doesn't have previous version.");
}
@@ -402,11 +399,7 @@ public class RealTimeGetComponent extends SearchComponent
} else { // i.e. lastPrevPointer==0
assert lastPrevPointer == 0;
// We have successfully resolved the document based off the tlogs
- if (partialDoc instanceof SolrInputDocument) {
- return toSolrDoc((SolrInputDocument)partialDoc, core.getLatestSchema(), false); // last param is false since this is no longer meant to be a partial doc
- } else {
- return (SolrDocument)partialDoc;
- }
+ return toSolrDoc(partialDoc, core.getLatestSchema());
}
}
@@ -452,7 +445,7 @@ public class RealTimeGetComponent extends SearchComponent
* document doesn't exist in the index.
*/
private static SolrDocument mergePartialDocWithFullDocFromIndex(SolrCore core, BytesRef idBytes, ReturnFields returnFields,
- Set<String> onlyTheseFields, SolrDocumentBase partialDoc) throws IOException {
+ Set<String> onlyTheseFields, SolrInputDocument partialDoc) throws IOException {
RefCounted<SolrIndexSearcher> searcherHolder = core.getRealtimeSearcher(); //Searcher();
try {
// now fetch last document from index, and merge partialDoc on top of it
@@ -488,7 +481,7 @@ public class RealTimeGetComponent extends SearchComponent
return doc;
}
for (String fieldName: (Iterable<String>) partialDoc.getFieldNames()) {
- doc.setField(fieldName.toString(), partialDoc.get(fieldName)); // since partial doc will only contain single valued fields, this is fine
+ doc.setField(fieldName.toString(), partialDoc.getFieldValue(fieldName)); // since partial doc will only contain single valued fields, this is fine
}
return doc;
@@ -533,12 +526,11 @@ public class RealTimeGetComponent extends SearchComponent
try {
// For in-place update case, we have obtained the partial document till now. We need to
// resolve it to a full document to be returned to the user.
- doc = toSolrInputDocument(
- resolveFullDocument(core, idBytes, new SolrReturnFields(), doc, entry, onlyTheseNonStoredDVs),
- core.getLatestSchema());
- if (doc == null) {
+ SolrDocument sdoc = resolveFullDocument(core, idBytes, new SolrReturnFields(), doc, entry, onlyTheseNonStoredDVs);
+ if (sdoc == null) {
return DELETED;
}
+ doc = toSolrInputDocument(sdoc, core.getLatestSchema());
return doc;
} catch (IOException ex) {
throw new SolrException(ErrorCode.SERVER_ERROR, "Error while resolving full document. ", ex);
@@ -714,9 +706,9 @@ public class RealTimeGetComponent extends SearchComponent
* Converts a SolrInputDocument to SolrDocument, using an IndexSchema instance.
* @lucene.experimental
*/
- public static SolrDocument toSolrDoc(SolrInputDocument sdoc, IndexSchema schema, boolean isThisAPartialDoc) {
+ public static SolrDocument toSolrDoc(SolrInputDocument sdoc, IndexSchema schema) {
// TODO: do something more performant than this double conversion
- Document doc = DocumentBuilder.toDocument(sdoc, schema, isThisAPartialDoc);
+ Document doc = DocumentBuilder.toDocument(sdoc, schema, false);
// copy the stored fields only
Document out = new Document();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/378a283c/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java b/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java
index d4468f9..0b2539f 100644
--- a/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java
+++ b/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java
@@ -115,7 +115,8 @@ public class DocumentBuilder {
*
* @param doc SolrInputDocument from which the document has to be built
* @param schema Schema instance
- * @param forInPlaceUpdate Whether the output document would be used for an in-place update or not.
+ * @param forInPlaceUpdate Whether the output document would be used for an in-place update or not. When this is true,
+ * default fields values and copy fields targets are not populated.
* @return Built Lucene document
*/
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/378a283c/solr/core/src/test/org/apache/solr/update/UpdateLogTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/update/UpdateLogTest.java b/solr/core/src/test/org/apache/solr/update/UpdateLogTest.java
index aa6e9d0..c6f83a9 100644
--- a/solr/core/src/test/org/apache/solr/update/UpdateLogTest.java
+++ b/solr/core/src/test/org/apache/solr/update/UpdateLogTest.java
@@ -67,7 +67,7 @@ public class UpdateLogTest extends SolrTestCaseJ4 {
Object partialUpdate = ulog.lookup(DOC_1_INDEXED_ID);
SolrDocument partialDoc = RealTimeGetComponent.toSolrDoc((SolrInputDocument)((List)partialUpdate).get(4),
- h.getCore().getLatestSchema(), true);
+ h.getCore().getLatestSchema());
long prevVersion = (Long)((List)partialUpdate).get(3);
long prevPointer = (Long)((List)partialUpdate).get(2);
@@ -91,7 +91,7 @@ public class UpdateLogTest extends SolrTestCaseJ4 {
ulogAdd(ulog, 200L, sdoc("id", "1", "val1_i_dvo", "5", "_version_", "201"));
partialUpdate = ulog.lookup(DOC_1_INDEXED_ID);
- partialDoc = RealTimeGetComponent.toSolrDoc((SolrInputDocument)((List)partialUpdate).get(4), h.getCore().getLatestSchema(), true);
+ partialDoc = RealTimeGetComponent.toSolrDoc((SolrInputDocument)((List)partialUpdate).get(4), h.getCore().getLatestSchema());
prevVersion = (Long)((List)partialUpdate).get(3);
prevPointer = (Long)((List)partialUpdate).get(2);
@@ -118,7 +118,7 @@ public class UpdateLogTest extends SolrTestCaseJ4 {
ulogAdd(ulog, 101L, sdoc("id", "1", "val1_i_dvo", "6", "_version_", "300"));
Object partialUpdate = ulog.lookup(DOC_1_INDEXED_ID);
- SolrDocument partialDoc = RealTimeGetComponent.toSolrDoc((SolrInputDocument)((List)partialUpdate).get(4), h.getCore().getLatestSchema(), true);
+ SolrDocument partialDoc = RealTimeGetComponent.toSolrDoc((SolrInputDocument)((List)partialUpdate).get(4), h.getCore().getLatestSchema());
long prevVersion = (Long)((List)partialUpdate).get(3);
long prevPointer = (Long)((List)partialUpdate).get(2);
@@ -138,7 +138,7 @@ public class UpdateLogTest extends SolrTestCaseJ4 {
ulogAdd(ulog, 501L, sdoc("id", "1", "val1_i_dvo", "3", "_version_", "502"));
Object partialUpdate = ulog.lookup(DOC_1_INDEXED_ID);
- SolrDocument partialDoc = RealTimeGetComponent.toSolrDoc((SolrInputDocument)((List)partialUpdate).get(4), h.getCore().getLatestSchema(), true);
+ SolrDocument partialDoc = RealTimeGetComponent.toSolrDoc((SolrInputDocument)((List)partialUpdate).get(4), h.getCore().getLatestSchema());
long prevVersion = (Long)((List)partialUpdate).get(3);
long prevPointer = (Long)((List)partialUpdate).get(2);