use of com.yahoo.document.DocumentPut in project vespa by vespa-engine.
the class VespaJsonDocumentReader method createDocumentOperation.
public DocumentOperation createDocumentOperation(DocumentType documentType, DocumentParseInfo documentParseInfo) {
final DocumentOperation documentOperation;
try {
switch(documentParseInfo.operationType) {
case PUT:
documentOperation = new DocumentPut(new Document(documentType, documentParseInfo.documentId));
readPut(documentParseInfo.fieldsBuffer, (DocumentPut) documentOperation);
verifyEndState(documentParseInfo.fieldsBuffer, JsonToken.END_OBJECT);
break;
case REMOVE:
documentOperation = new DocumentRemove(documentParseInfo.documentId);
break;
case UPDATE:
documentOperation = new DocumentUpdate(documentType, documentParseInfo.documentId);
readUpdate(documentParseInfo.fieldsBuffer, (DocumentUpdate) documentOperation);
verifyEndState(documentParseInfo.fieldsBuffer, JsonToken.END_OBJECT);
break;
default:
throw new IllegalStateException("Implementation out of sync with itself. This is a bug.");
}
} catch (JsonReaderException e) {
throw JsonReaderException.addDocId(e, documentParseInfo.documentId);
}
if (documentParseInfo.create.isPresent()) {
if (!(documentOperation instanceof DocumentUpdate)) {
throw new RuntimeException("Could not set create flag on non update operation.");
}
DocumentUpdate update = (DocumentUpdate) documentOperation;
update.setCreateIfNonExistent(documentParseInfo.create.get());
}
return documentOperation;
}
use of com.yahoo.document.DocumentPut in project vespa by vespa-engine.
the class FieldPathUpdate method applyTo.
public void applyTo(Document doc) {
if (selector == null) {
FieldPathIteratorHandler handler = getIteratorHandler(doc);
doc.iterateNested(fieldPath, 0, handler);
} else {
ResultList results = selector.getMatchingResultList(new DocumentPut(doc));
for (ResultList.ResultPair rp : results.getResults()) {
if (rp.getResult() == Result.TRUE) {
FieldPathIteratorHandler handler = getIteratorHandler(doc);
handler.getVariables().clear();
handler.getVariables().putAll(rp.getVariables());
doc.iterateNested(fieldPath, 0, handler);
}
}
}
}
Aggregations