use of com.yahoo.searchdefinition.document.SDDocumentType in project vespa by vespa-engine.
the class SDDocumentTypeTestCase method testInheritance.
@Test
public void testInheritance() {
SDDocumentType child = new SDDocumentType("child");
Iterator<SDDocumentType> inherited = child.getInheritedTypes().iterator();
assertTrue(inherited.hasNext());
assertEquals(inherited.next().getDocumentName(), VespaDocumentType.NAME);
assertFalse(inherited.hasNext());
child.addField("childfield", DataType.INT);
SDField overridden = child.addField("overridden", DataType.STRING);
SDDocumentType parent1 = new SDDocumentType("parent1");
SDField overridden2 = parent1.addField("overridden", DataType.STRING);
parent1.addField("parent1field", DataType.STRING);
child.inherit(parent1);
SDDocumentType parent2 = new SDDocumentType("parent2");
parent2.addField("parent2field", DataType.STRING);
child.inherit(parent2);
SDDocumentType root = new SDDocumentType("root");
root.addField("rootfield", DataType.STRING);
parent1.inherit(root);
parent2.inherit(root);
inherited = child.getInheritedTypes().iterator();
assertEquals(VespaDocumentType.NAME, inherited.next().getDocumentName());
assertEquals(new DataTypeName("parent1"), inherited.next().getDocumentName());
assertEquals(new DataTypeName("parent2"), inherited.next().getDocumentName());
assertTrue(!inherited.hasNext());
inherited = parent1.getInheritedTypes().iterator();
assertEquals(VespaDocumentType.NAME, inherited.next().getDocumentName());
assertEquals(new DataTypeName("root"), inherited.next().getDocumentName());
assertTrue(!inherited.hasNext());
inherited = parent2.getInheritedTypes().iterator();
assertEquals(VespaDocumentType.NAME, inherited.next().getDocumentName());
assertEquals(new DataTypeName("root"), inherited.next().getDocumentName());
assertTrue(!inherited.hasNext());
inherited = root.getInheritedTypes().iterator();
assertTrue(inherited.hasNext());
assertEquals(inherited.next().getDocumentName(), VespaDocumentType.NAME);
assertFalse(inherited.hasNext());
Iterator fields = child.fieldSet().iterator();
SDField field;
field = (SDField) fields.next();
assertEquals("rootfield", field.getName());
field = (SDField) fields.next();
assertEquals("overridden", field.getName());
field = (SDField) fields.next();
assertEquals("parent1field", field.getName());
field = (SDField) fields.next();
assertEquals("parent2field", field.getName());
field = (SDField) fields.next();
assertEquals("childfield", field.getName());
// TODO: Test uninheriting
}
use of com.yahoo.searchdefinition.document.SDDocumentType in project vespa by vespa-engine.
the class SDFieldTestCase method testSettingReservedId.
@Test
public void testSettingReservedId() {
SDDocumentType doc = new SDDocumentType("testdoc");
try {
SDField one = (SDField) doc.addField("one", DataType.STRING, false, 127);
fail("Allowed to set reserved id");
} catch (IllegalArgumentException e) {
// Success
}
try {
SDField one = (SDField) doc.addField("one", DataType.STRING, false, 100);
fail("Allowed to set reserved id");
} catch (IllegalArgumentException e) {
// Success
}
try {
SDField one = (SDField) doc.addField("one", DataType.STRING, false, -1);
fail("Allowed to set reserved id");
} catch (IllegalArgumentException e) {
// Success
}
SDField one = doc.addField("one", DataType.STRING);
}
use of com.yahoo.searchdefinition.document.SDDocumentType in project vespa by vespa-engine.
the class SDFieldTestCase method testIdSettingConflict.
@Test
public void testIdSettingConflict() {
SDDocumentType doc = new SDDocumentType("testdoc");
SDField one = (SDField) doc.addField("one", DataType.STRING, false, 60);
SDField two = (SDField) doc.addField("two", DataType.STRING, false, 61);
try {
SDField three = (SDField) doc.addField("three", DataType.STRING, false, 60);
fail("Allowed to set duplicate id");
} catch (IllegalArgumentException e) {
// Success
}
}
use of com.yahoo.searchdefinition.document.SDDocumentType in project vespa by vespa-engine.
the class SummaryMapTestCase method testPositionDeriving.
@Test
public void testPositionDeriving() throws IOException, ParseException {
Search search = new Search("store", null);
SDDocumentType document = new SDDocumentType("store");
search.addDocument(document);
String fieldName = "location";
SDField field = document.addField(fieldName, PositionDataType.INSTANCE);
field.parseIndexingScript("{ attribute | summary }");
Processing.process(search, new BaseDeployLogger(), new RankProfileRegistry(), new QueryProfiles(), true);
SummaryMap summaryMap = new SummaryMap(search, new Summaries(search, new BaseDeployLogger()));
Iterator transforms = summaryMap.resultTransformIterator();
FieldResultTransform transform = (FieldResultTransform) transforms.next();
assertEquals(fieldName, transform.getFieldName());
assertEquals(SummaryTransform.GEOPOS, transform.getTransform());
transform = (FieldResultTransform) transforms.next();
assertEquals(PositionDataType.getPositionSummaryFieldName(fieldName), transform.getFieldName());
assertEquals(SummaryTransform.POSITIONS, transform.getTransform());
transform = (FieldResultTransform) transforms.next();
assertEquals(PositionDataType.getDistanceSummaryFieldName(fieldName), transform.getFieldName());
assertEquals(SummaryTransform.DISTANCE, transform.getTransform());
transform = (FieldResultTransform) transforms.next();
assertEquals("rankfeatures", transform.getFieldName());
assertEquals(SummaryTransform.RANKFEATURES, transform.getTransform());
transform = (FieldResultTransform) transforms.next();
assertEquals("summaryfeatures", transform.getFieldName());
assertEquals(SummaryTransform.SUMMARYFEATURES, transform.getTransform());
transform = (FieldResultTransform) transforms.next();
assertEquals("location_zcurve", transform.getFieldName());
assertEquals(SummaryTransform.ATTRIBUTE, transform.getTransform());
assertTrue(!transforms.hasNext());
SummarymapConfig.Builder scb = new SummarymapConfig.Builder();
summaryMap.getConfig(scb);
SummarymapConfig c = new SummarymapConfig(scb);
assertEquals(-1, c.defaultoutputclass());
assertEquals(c.override().size(), 6);
assertEquals(c.override(0).field(), fieldName);
assertEquals(c.override(0).command(), "geopos");
assertEquals(c.override(0).arguments(), PositionDataType.getZCurveFieldName(fieldName));
assertEquals(c.override(1).field(), PositionDataType.getPositionSummaryFieldName(fieldName));
assertEquals(c.override(1).command(), "positions");
assertEquals(c.override(1).arguments(), PositionDataType.getZCurveFieldName(fieldName));
assertEquals(c.override(2).field(), PositionDataType.getDistanceSummaryFieldName(fieldName));
assertEquals(c.override(2).command(), "absdist");
assertEquals(c.override(2).arguments(), PositionDataType.getZCurveFieldName(fieldName));
assertEquals(c.override(3).field(), "rankfeatures");
assertEquals(c.override(3).command(), "rankfeatures");
assertEquals(c.override(3).arguments(), "");
assertEquals(c.override(4).field(), "summaryfeatures");
assertEquals(c.override(4).command(), "summaryfeatures");
assertEquals(c.override(4).arguments(), "");
assertEquals(c.override(5).field(), "location_zcurve");
assertEquals(c.override(5).command(), "attribute");
assertEquals(c.override(5).arguments(), "location_zcurve");
}
use of com.yahoo.searchdefinition.document.SDDocumentType in project vespa by vespa-engine.
the class AddAttributeTransformToSummaryOfImportedFieldsTest method createSearchWithDocument.
private static Search createSearchWithDocument(String documentName) {
Search search = new Search(documentName, MockApplicationPackage.createEmpty());
SDDocumentType document = new SDDocumentType(documentName, search);
search.addDocument(document);
return search;
}
Aggregations