Search in sources :

Example 11 with SDDocumentType

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
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) Iterator(java.util.Iterator) DataTypeName(com.yahoo.document.DataTypeName) Test(org.junit.Test)

Example 12 with SDDocumentType

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);
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) Test(org.junit.Test)

Example 13 with SDDocumentType

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
    }
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) Test(org.junit.Test)

Example 14 with SDDocumentType

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");
}
Also used : SummarymapConfig(com.yahoo.vespa.config.search.SummarymapConfig) BaseDeployLogger(com.yahoo.config.model.application.provider.BaseDeployLogger) SDField(com.yahoo.searchdefinition.document.SDField) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) QueryProfiles(com.yahoo.vespa.model.container.search.QueryProfiles) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 15 with SDDocumentType

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;
}
Also used : SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) Search(com.yahoo.searchdefinition.Search)

Aggregations

SDDocumentType (com.yahoo.searchdefinition.document.SDDocumentType)48 Test (org.junit.Test)28 SDField (com.yahoo.searchdefinition.document.SDField)23 Search (com.yahoo.searchdefinition.Search)21 RankProfileRegistry (com.yahoo.searchdefinition.RankProfileRegistry)7 BaseDeployLogger (com.yahoo.config.model.application.provider.BaseDeployLogger)6 QueryProfiles (com.yahoo.vespa.model.container.search.QueryProfiles)6 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)5 TemporarySDField (com.yahoo.searchdefinition.document.TemporarySDField)4 ArrayList (java.util.ArrayList)4 DataTypeName (com.yahoo.document.DataTypeName)3 TemporarySDDocumentType (com.yahoo.searchdefinition.document.TemporarySDDocumentType)3 HashMap (java.util.HashMap)3 NewDocumentType (com.yahoo.documentmodel.NewDocumentType)2 DocumentReferences (com.yahoo.searchdefinition.DocumentReferences)2 RankProfile (com.yahoo.searchdefinition.RankProfile)2 SearchBuilder (com.yahoo.searchdefinition.SearchBuilder)2 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2 DataType (com.yahoo.document.DataType)1