use of com.yahoo.document.Field in project vespa by vespa-engine.
the class IndexSchemaTestCase method requireThatStructWithArrayFieldIsFlattened.
@Test
public void requireThatStructWithArrayFieldIsFlattened() {
StructDataType type = new StructDataType("my_struct");
type.addField(new Field("my_byte", DataType.getArray(DataType.BYTE)));
type.addField(new Field("my_double", DataType.getArray(DataType.DOUBLE)));
type.addField(new Field("my_float", DataType.getArray(DataType.FLOAT)));
type.addField(new Field("my_int", DataType.getArray(DataType.INT)));
type.addField(new Field("my_long", DataType.getArray(DataType.LONG)));
type.addField(new Field("my_raw", DataType.getArray(DataType.RAW)));
type.addField(new Field("my_string", DataType.getArray(DataType.STRING)));
type.addField(new Field("my_uri", DataType.getArray(DataType.URI)));
assertFlat(new Field("foo", type), new Field("foo.my_byte", DataType.getArray(DataType.BYTE)), new Field("foo.my_double", DataType.getArray(DataType.DOUBLE)), new Field("foo.my_float", DataType.getArray(DataType.FLOAT)), new Field("foo.my_int", DataType.getArray(DataType.INT)), new Field("foo.my_long", DataType.getArray(DataType.LONG)), new Field("foo.my_raw", DataType.getArray(DataType.RAW)), new Field("foo.my_string", DataType.getArray(DataType.STRING)), new Field("foo.my_uri", DataType.getArray(DataType.URI)));
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class IndexSchemaTestCase method assertFlat.
private static void assertFlat(Field fieldToFlatten, Field... expectedFields) {
List<Field> actual = new LinkedList<>(IndexSchema.flattenField(fieldToFlatten));
List<Field> expected = new LinkedList<>(Arrays.asList(expectedFields));
Collections.sort(actual);
Collections.sort(expected);
for (Field field : actual) {
if (!expected.remove(field)) {
fail("Unexpected field: " + field);
}
}
assertTrue("Missing fields: " + expected, expected.isEmpty());
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class ReferenceFieldTestCase method assertSearchContainsReferenceField.
private static void assertSearchContainsReferenceField(String expectedFieldname, String referencedDocType, SDDocumentType documentType) {
Field field = documentType.getDocumentType().getField(expectedFieldname);
assertNotNull("Field does not exist in document type: " + expectedFieldname, field);
DataType dataType = field.getDataType();
assertThat(dataType, instanceOf(ReferenceDataType.class));
ReferenceDataType refField = (ReferenceDataType) dataType;
assertEquals(referencedDocType, refField.getTargetType().getName());
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class AddAttributeTransformToSummaryOfImportedFieldsTest method createSingleImportedField.
private static ImportedFields createSingleImportedField(String fieldName) {
Search targetSearch = new Search("target_doc", MockApplicationPackage.createEmpty());
SDField targetField = new SDField("target_field", DataType.INT);
DocumentReference documentReference = new DocumentReference(new Field("reference_field"), targetSearch);
ImportedField importedField = new ImportedField(fieldName, documentReference, targetField);
return new ImportedFields(Collections.singletonMap(fieldName, importedField));
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class GetSearcher method handleFieldFiltering.
private void handleFieldFiltering(GetResponse response, Result result, String fieldName, String contentType, boolean headersOnly) {
if (response.getDocumentHits().isEmpty()) {
result.hits().addError(ErrorMessage.createNotFound("Document not found, could not return field '" + fieldName + "'"));
return;
}
if (result.hits().getErrorHit() == null) {
Document doc = response.getDocumentHits().get(0).getDocument();
Field field = doc.getDataType().getField(fieldName);
boolean wrapXml = false;
if (field == null) {
result.hits().addError(ErrorMessage.createIllegalQuery("Field '" + fieldName + "' not found in document type"));
return;
}
FieldValue value = doc.getFieldValue(field);
// content will be null. We treat this as an error.
if (value == null) {
if (!field.isHeader() && headersOnly) {
// TODO(vekterli): make this work with field sets as well.
result.hits().addError(ErrorMessage.createInvalidQueryParameter("Field '" + fieldName + "' is located in document body, but headersonly " + "prevents it from being retrieved in " + doc.getId().toString()));
} else {
result.hits().addError(ErrorMessage.createNotFound("Field '" + fieldName + "' found in document type, but had " + "no content in " + doc.getId().toString()));
}
return;
}
String encoding = null;
if (field.getDataType() == DataType.RAW) {
if (contentType == null) {
contentType = "application/octet-stream";
}
encoding = "ISO-8859-1";
} else {
// By default, return field wrapped in a blanket of vespa XML
contentType = "text/xml";
wrapXml = true;
}
if (encoding == null) {
// Encoding doesn't matter for binary content, since we're always
// writing directly to the byte buffer and not through a charset
// encoder. Presumably, the client is intelligent enough to not
// attempt to UTF-8 decode binary data.
encoding = "UTF-8";
}
// Add hit now that we know there aren't any field errors. Otherwise,
// there would be both an error hit and a document hit in the result
response.addHitsToResult(result, false);
// Override Vespa XML template
result.getTemplating().setTemplates(new DocumentFieldTemplate(field, contentType, encoding, wrapXml));
}
// else: return with error hit, invoking regular Vespa XML error template
}
Aggregations