use of com.yahoo.document.Document in project vespa by vespa-engine.
the class Rot13DocumentProcessor method process.
@Override
public Progress process(Processing processing) {
int oldVal = counter.getAndIncrement();
if ((oldVal % 3) != 0) {
return Progress.LATER;
}
for (DocumentOperation op : processing.getDocumentOperations()) {
if (op instanceof DocumentPut) {
Document document = ((DocumentPut) op).getDocument();
StringFieldValue oldTitle = (StringFieldValue) document.getFieldValue(FIELD_NAME);
if (oldTitle != null) {
document.setFieldValue(FIELD_NAME, rot13(oldTitle.getString()));
}
}
}
return Progress.DONE;
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class JDiscContainerDocprocTest method requireThatLaterDocumentProcessingWorks.
@Test
public void requireThatLaterDocumentProcessingWorks() throws Exception {
try (Application app = new ApplicationBuilder().servicesXml(getXML(CHAIN_NAME, Rot13DocumentProcessor.class.getCanonicalName())).networking(Networking.disable).documentType("music", DOCUMENT).build()) {
JDisc container = app.getJDisc("container");
DocumentProcessing docProc = container.documentProcessing();
DocumentType type = docProc.getDocumentTypes().get("music");
ChainRegistry<DocumentProcessor> chains = docProc.getChains();
assertTrue(chains.allComponentsById().containsKey(new ComponentId(CHAIN_NAME)));
Document doc = new Document(type, "doc:this:is:a:great:album");
doc.setFieldValue("title", "Great Album!");
com.yahoo.docproc.Processing processing;
DocumentProcessor.Progress progress;
DocumentPut put = new DocumentPut(doc);
processing = com.yahoo.docproc.Processing.of(put);
progress = docProc.processOnce(ComponentSpecification.fromString(CHAIN_NAME), processing);
assertThat(progress, instanceOf(DocumentProcessor.LaterProgress.class));
assertThat(doc.getFieldValue("title").toString(), equalTo("Great Album!"));
progress = docProc.processOnce(ComponentSpecification.fromString(CHAIN_NAME), processing);
assertThat(progress, instanceOf(DocumentProcessor.LaterProgress.class));
assertThat(doc.getFieldValue("title").toString(), equalTo("Great Album!"));
progress = docProc.processOnce(ComponentSpecification.fromString(CHAIN_NAME), processing);
assertThat(progress, sameInstance(DocumentProcessor.Progress.DONE));
assertThat(doc.getFieldValue("title").toString(), equalTo("Terng Nyohz!"));
}
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class ScriptTestCase method requireThatIfExpressionPassesOriginalInputAlong.
@Test
public void requireThatIfExpressionPassesOriginalInputAlong() throws ParseException {
Document input = new Document(type, "doc:scheme:");
Document output = Expression.execute(Expression.fromString("'foo' | if (1 < 2) { 'bar' | index 'out-1' } else { 'baz' | index 'out-1' } | index 'out-1'"), input);
assertNotNull(output);
assertEquals(new StringFieldValue("foo"), output.getFieldValue("out-1"));
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class ScriptTestCase method requireThatFactoryMethodWorks.
@Test
public void requireThatFactoryMethodWorks() throws ParseException {
Document input = new Document(type, "doc:scheme:");
input.setFieldValue("in-1", new StringFieldValue("FOO"));
Document output = Expression.execute(Expression.fromString("input 'in-1' | { index 'out-1'; lowercase | index 'out-2' }"), input);
assertNotNull(output);
assertEquals(new StringFieldValue("FOO"), output.getFieldValue("out-1"));
assertEquals(new StringFieldValue("foo"), output.getFieldValue("out-2"));
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class DocumentFieldTemplate method hit.
@Override
public void hit(Context context, Writer writer) throws IOException {
DocumentHit hit = (DocumentHit) context.get("hit");
Document doc = hit.getDocument();
// Assume field existence has been checked before we ever get here.
// Also assume that relevant encoding/content type is set
// appropriately according to the request and the field's content
// type, as this is immutable in the template set.
FieldValue value = doc.getFieldValue(field);
if (field.getDataType() == DataType.RAW) {
ByteWriter bw = (ByteWriter) writer;
bw.append(((Raw) value).getByteBuffer().array());
} else {
writer.write(XML.xmlEscape(value.toString(), false));
}
}
Aggregations