Search in sources :

Example 26 with SDField

use of com.yahoo.searchdefinition.document.SDField in project vespa by vespa-engine.

the class AttributeSettingsTestCase method testAttributeSettings.

@Test
public void testAttributeSettings() throws IOException, ParseException {
    Search search = SearchBuilder.buildFromFile("src/test/examples/attributesettings.sd");
    SDField f1 = (SDField) search.getDocument().getField("f1");
    assertTrue(f1.getAttributes().size() == 1);
    Attribute a1 = f1.getAttributes().get(f1.getName());
    assertThat(a1.getType(), is(Attribute.Type.LONG));
    assertThat(a1.getCollectionType(), is(Attribute.CollectionType.SINGLE));
    assertTrue(a1.isHuge());
    assertFalse(a1.isFastSearch());
    assertFalse(a1.isFastAccess());
    assertFalse(a1.isRemoveIfZero());
    assertFalse(a1.isCreateIfNonExistent());
    SDField f2 = (SDField) search.getDocument().getField("f2");
    assertTrue(f2.getAttributes().size() == 1);
    Attribute a2 = f2.getAttributes().get(f2.getName());
    assertThat(a2.getType(), is(Attribute.Type.LONG));
    assertThat(a2.getCollectionType(), is(Attribute.CollectionType.SINGLE));
    assertFalse(a2.isHuge());
    assertTrue(a2.isFastSearch());
    assertFalse(a2.isFastAccess());
    assertFalse(a2.isRemoveIfZero());
    assertFalse(a2.isCreateIfNonExistent());
    assertThat(f2.getAliasToName().get("f2alias"), is("f2"));
    SDField f3 = (SDField) search.getDocument().getField("f3");
    assertTrue(f3.getAttributes().size() == 1);
    assertThat(f3.getAliasToName().get("f3alias"), is("f3"));
    Attribute a3 = f3.getAttributes().get(f3.getName());
    assertThat(a3.getType(), is(Attribute.Type.LONG));
    assertThat(a3.getCollectionType(), is(Attribute.CollectionType.SINGLE));
    assertFalse(a3.isHuge());
    assertFalse(a3.isFastSearch());
    assertFalse(a3.isFastAccess());
    assertFalse(a3.isRemoveIfZero());
    assertFalse(a3.isCreateIfNonExistent());
    assertWeightedSet(search, "f4", true, true);
    assertWeightedSet(search, "f5", true, true);
    assertWeightedSet(search, "f6", true, true);
    assertWeightedSet(search, "f7", true, false);
    assertWeightedSet(search, "f8", true, false);
    assertWeightedSet(search, "f9", false, true);
    assertWeightedSet(search, "f10", false, true);
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) Attribute(com.yahoo.searchdefinition.document.Attribute) Test(org.junit.Test)

Example 27 with SDField

use of com.yahoo.searchdefinition.document.SDField in project vespa by vespa-engine.

the class AttributeSettingsTestCase method assertWeightedSet.

private void assertWeightedSet(Search search, String name, boolean createIfNonExistent, boolean removeIfZero) {
    SDField f4 = (SDField) search.getDocument().getField(name);
    assertTrue(f4.getAttributes().size() == 1);
    Attribute a4 = f4.getAttributes().get(f4.getName());
    assertThat(a4.getType(), is(Attribute.Type.STRING));
    assertThat(a4.getCollectionType(), is(Attribute.CollectionType.WEIGHTEDSET));
    assertFalse(a4.isHuge());
    assertFalse(a4.isFastSearch());
    assertFalse(a4.isFastAccess());
    assertThat(removeIfZero, is(a4.isRemoveIfZero()));
    assertThat(createIfNonExistent, is(a4.isCreateIfNonExistent()));
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) Attribute(com.yahoo.searchdefinition.document.Attribute)

Example 28 with SDField

use of com.yahoo.searchdefinition.document.SDField in project vespa by vespa-engine.

the class DocumentReferenceResolverTest method throws_user_friendly_exception_if_referenced_document_does_not_exist.

@Test
public void throws_user_friendly_exception_if_referenced_document_does_not_exist() {
    // Create foo document with document reference to non-existing document bar
    SDField fooRefToBarField = new SDField("bar_ref", ReferenceDataType.createWithInferredId(TemporaryStructuredDataType.create("bar")));
    addAttributeAspect(fooRefToBarField);
    Search fooSearch = new Search();
    SDDocumentType fooDocument = new SDDocumentType("foo", fooSearch);
    fooDocument.addField(fooRefToBarField);
    fooSearch.addDocument(fooDocument);
    DocumentReferenceResolver resolver = new DocumentReferenceResolver(singletonList(fooSearch));
    exceptionRule.expect(IllegalArgumentException.class);
    exceptionRule.expectMessage("The field 'bar_ref' is an invalid document reference. " + "Could not find document with 'bar' in any search definitions");
    resolver.resolveReferences(fooDocument);
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) Test(org.junit.Test)

Example 29 with SDField

use of com.yahoo.searchdefinition.document.SDField 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 30 with SDField

use of com.yahoo.searchdefinition.document.SDField 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)

Aggregations

SDField (com.yahoo.searchdefinition.document.SDField)85 Test (org.junit.Test)33 SDDocumentType (com.yahoo.searchdefinition.document.SDDocumentType)22 Search (com.yahoo.searchdefinition.Search)15 Attribute (com.yahoo.searchdefinition.document.Attribute)11 Index (com.yahoo.searchdefinition.Index)7 RankProfileRegistry (com.yahoo.searchdefinition.RankProfileRegistry)7 ArrayList (java.util.ArrayList)7 BaseDeployLogger (com.yahoo.config.model.application.provider.BaseDeployLogger)6 Field (com.yahoo.document.Field)6 SummaryField (com.yahoo.vespa.documentmodel.SummaryField)6 ScriptExpression (com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression)6 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)5 ImmutableSDField (com.yahoo.searchdefinition.document.ImmutableSDField)5 QueryProfiles (com.yahoo.vespa.model.container.search.QueryProfiles)5 ArrayDataType (com.yahoo.document.ArrayDataType)4 DataType (com.yahoo.document.DataType)4 DocumentReference (com.yahoo.searchdefinition.DocumentReference)4 RankProfile (com.yahoo.searchdefinition.RankProfile)4 TemporarySDField (com.yahoo.searchdefinition.document.TemporarySDField)4